Merge pull request #273 from davidmhewitt/load-post-visibility-preference
Load post privacy preference
This commit is contained in:
@@ -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.MastodonAPIController;
|
||||||
import org.joinmastodon.android.api.MastodonErrorResponse;
|
import org.joinmastodon.android.api.MastodonErrorResponse;
|
||||||
import org.joinmastodon.android.api.ProgressListener;
|
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.CreateStatus;
|
||||||
import org.joinmastodon.android.api.requests.statuses.EditStatus;
|
import org.joinmastodon.android.api.requests.statuses.EditStatus;
|
||||||
import org.joinmastodon.android.api.requests.statuses.GetAttachmentByID;
|
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.Instance;
|
||||||
import org.joinmastodon.android.model.Mention;
|
import org.joinmastodon.android.model.Mention;
|
||||||
import org.joinmastodon.android.model.Poll;
|
import org.joinmastodon.android.model.Poll;
|
||||||
|
import org.joinmastodon.android.model.Preferences;
|
||||||
import org.joinmastodon.android.model.Status;
|
import org.joinmastodon.android.model.Status;
|
||||||
import org.joinmastodon.android.model.StatusPrivacy;
|
import org.joinmastodon.android.model.StatusPrivacy;
|
||||||
import org.joinmastodon.android.ui.ComposeAutocompleteViewController;
|
import org.joinmastodon.android.ui.ComposeAutocompleteViewController;
|
||||||
@@ -224,13 +226,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||||||
else
|
else
|
||||||
charLimit=500;
|
charLimit=500;
|
||||||
|
|
||||||
if(getArguments().containsKey("replyTo")){
|
loadDefaultStatusVisibility(savedInstanceState);
|
||||||
replyTo=Parcels.unwrap(getArguments().getParcelable("replyTo"));
|
|
||||||
statusVisibility=replyTo.visibility;
|
|
||||||
}
|
|
||||||
if(savedInstanceState!=null){
|
|
||||||
statusVisibility=(StatusPrivacy) savedInstanceState.getSerializable("visibility");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1276,6 +1272,47 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||||||
menu.show();
|
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(){
|
private void updateVisibilityIcon(){
|
||||||
if(statusVisibility==null){ // TODO find out why this happens
|
if(statusVisibility==null){ // TODO find out why this happens
|
||||||
statusVisibility=StatusPrivacy.PUBLIC;
|
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{
|
public enum StatusPrivacy{
|
||||||
@SerializedName("public")
|
@SerializedName("public")
|
||||||
PUBLIC,
|
PUBLIC(0),
|
||||||
@SerializedName("unlisted")
|
@SerializedName("unlisted")
|
||||||
UNLISTED,
|
UNLISTED(1),
|
||||||
@SerializedName("private")
|
@SerializedName("private")
|
||||||
PRIVATE,
|
PRIVATE(2),
|
||||||
@SerializedName("direct")
|
@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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user