Load post privacy preference
This queries the user's post visibility preference when opening the composer, and sets it on the composer. In the case of composing a reply, the user's preference is only respected if it is "more private" than the privacy of the post being replied to, as this appears to be the behaviour in the web interface (and is what I'd expect)
This commit is contained in:
parent
e8fa82d0de
commit
eea00b0d53
|
@ -0,0 +1,10 @@
|
|||
package org.joinmastodon.android.api.requests.accounts;
|
||||
|
||||
import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||
import org.joinmastodon.android.model.Preferences;
|
||||
|
||||
public class GetPreferences extends MastodonAPIRequest<Preferences> {
|
||||
public GetPreferences(){
|
||||
super(HttpMethod.GET, "/preferences", Preferences.class);
|
||||
}
|
||||
}
|
|
@ -59,6 +59,7 @@ import org.joinmastodon.android.R;
|
|||
import org.joinmastodon.android.api.MastodonAPIController;
|
||||
import org.joinmastodon.android.api.MastodonErrorResponse;
|
||||
import org.joinmastodon.android.api.ProgressListener;
|
||||
import org.joinmastodon.android.api.requests.accounts.GetPreferences;
|
||||
import org.joinmastodon.android.api.requests.statuses.CreateStatus;
|
||||
import org.joinmastodon.android.api.requests.statuses.EditStatus;
|
||||
import org.joinmastodon.android.api.requests.statuses.GetAttachmentByID;
|
||||
|
@ -75,6 +76,7 @@ import org.joinmastodon.android.model.EmojiCategory;
|
|||
import org.joinmastodon.android.model.Instance;
|
||||
import org.joinmastodon.android.model.Mention;
|
||||
import org.joinmastodon.android.model.Poll;
|
||||
import org.joinmastodon.android.model.Preferences;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
import org.joinmastodon.android.model.StatusPrivacy;
|
||||
import org.joinmastodon.android.ui.ComposeAutocompleteViewController;
|
||||
|
@ -224,13 +226,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||
else
|
||||
charLimit=500;
|
||||
|
||||
if(getArguments().containsKey("replyTo")){
|
||||
replyTo=Parcels.unwrap(getArguments().getParcelable("replyTo"));
|
||||
statusVisibility=replyTo.visibility;
|
||||
}
|
||||
if(savedInstanceState!=null){
|
||||
statusVisibility=(StatusPrivacy) savedInstanceState.getSerializable("visibility");
|
||||
}
|
||||
loadDefaultStatusVisibility(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1276,6 +1272,47 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||
menu.show();
|
||||
}
|
||||
|
||||
private void loadDefaultStatusVisibility(Bundle savedInstanceState) {
|
||||
if(getArguments().containsKey("replyTo")){
|
||||
replyTo=Parcels.unwrap(getArguments().getParcelable("replyTo"));
|
||||
statusVisibility = replyTo.visibility;
|
||||
}
|
||||
|
||||
// A saved privacy setting from a previous compose session wins over the reply visibility
|
||||
if(savedInstanceState !=null){
|
||||
statusVisibility = (StatusPrivacy) savedInstanceState.getSerializable("visibility");
|
||||
}
|
||||
|
||||
new GetPreferences()
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(Preferences result){
|
||||
// Only override the reply visibility if our preference is more private
|
||||
if (result.postingDefaultVisibility.isLessVisibleThan(statusVisibility)) {
|
||||
// Map unlisted from the API onto public, because we don't have unlisted in the UI
|
||||
statusVisibility = switch (result.postingDefaultVisibility) {
|
||||
case PUBLIC, UNLISTED -> StatusPrivacy.PUBLIC;
|
||||
case PRIVATE -> StatusPrivacy.PRIVATE;
|
||||
case DIRECT -> StatusPrivacy.DIRECT;
|
||||
};
|
||||
}
|
||||
|
||||
// A saved privacy setting from a previous compose session wins over all
|
||||
if(savedInstanceState !=null){
|
||||
statusVisibility = (StatusPrivacy) savedInstanceState.getSerializable("visibility");
|
||||
}
|
||||
|
||||
updateVisibilityIcon ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
Log.w(TAG, "Unable to get user preferences to set default post privacy");
|
||||
}
|
||||
})
|
||||
.exec(accountID);
|
||||
}
|
||||
|
||||
private void updateVisibilityIcon(){
|
||||
if(statusVisibility==null){ // TODO find out why this happens
|
||||
statusVisibility=StatusPrivacy.PUBLIC;
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package org.joinmastodon.android.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public enum ExpandMedia {
|
||||
@SerializedName("default")
|
||||
DEFAULT,
|
||||
@SerializedName("show_all")
|
||||
SHOW_ALL,
|
||||
@SerializedName("hide_all")
|
||||
HIDE_ALL;
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package org.joinmastodon.android.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
* Preferred common behaviors to be shared across clients.
|
||||
*/
|
||||
public class Preferences extends BaseModel {
|
||||
/**
|
||||
* Default visibility for new posts
|
||||
*/
|
||||
@SerializedName("posting:default:visibility")
|
||||
public StatusPrivacy postingDefaultVisibility;
|
||||
|
||||
/**
|
||||
* Default sensitivity flag for new posts
|
||||
*/
|
||||
@SerializedName("posting:default:sensitive")
|
||||
public boolean postingDefaultSensitive;
|
||||
|
||||
/**
|
||||
* Default language for new posts
|
||||
*/
|
||||
@SerializedName("posting:default:language")
|
||||
public String postingDefaultLanguage;
|
||||
|
||||
/**
|
||||
* Whether media attachments should be automatically displayed or blurred/hidden.
|
||||
*/
|
||||
@SerializedName("reading:expand:media")
|
||||
public ExpandMedia readingExpandMedia;
|
||||
|
||||
/**
|
||||
* Whether CWs should be expanded by default.
|
||||
*/
|
||||
@SerializedName("reading:expand:spoilers")
|
||||
public boolean readingExpandSpoilers;
|
||||
}
|
|
@ -4,11 +4,25 @@ import com.google.gson.annotations.SerializedName;
|
|||
|
||||
public enum StatusPrivacy{
|
||||
@SerializedName("public")
|
||||
PUBLIC,
|
||||
PUBLIC(0),
|
||||
@SerializedName("unlisted")
|
||||
UNLISTED,
|
||||
UNLISTED(1),
|
||||
@SerializedName("private")
|
||||
PRIVATE,
|
||||
PRIVATE(2),
|
||||
@SerializedName("direct")
|
||||
DIRECT;
|
||||
DIRECT(3);
|
||||
|
||||
private int privacy;
|
||||
|
||||
StatusPrivacy(int privacy) {
|
||||
this.privacy = privacy;
|
||||
}
|
||||
|
||||
public boolean isLessVisibleThan(StatusPrivacy other) {
|
||||
return privacy > other.getPrivacy();
|
||||
}
|
||||
|
||||
public int getPrivacy() {
|
||||
return privacy;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue