diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2016-02-22 20:19:58 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2016-02-22 20:19:58 +0100 |
commit | a0d0ed34ae38f2377fdb3ad2c661b74b85f2df28 (patch) | |
tree | 14e3755a0491c00f4ff125d02969ba5389659a8b /src/main/java/eu/siacs/conversations | |
parent | c20d8ac69eeade4d5337d958ada7910db0c6d3a0 (diff) |
turned muc errors into enum. added error codes for service shutdown
Diffstat (limited to 'src/main/java/eu/siacs/conversations')
5 files changed, 51 insertions, 37 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index be9d790d1..3567c14f4 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -91,22 +91,26 @@ public class MucOptions { } } - public static final int ERROR_NO_ERROR = 0; - public static final int ERROR_NICK_IN_USE = 1; - public static final int ERROR_UNKNOWN = 2; - public static final int ERROR_PASSWORD_REQUIRED = 3; - public static final int ERROR_BANNED = 4; - public static final int ERROR_MEMBERS_ONLY = 5; - public static final int ERROR_NO_RESPONSE = 6; - - public static final int KICKED_FROM_ROOM = 9; + public enum Error { + NO_RESPONSE, + NONE, + NICK_IN_USE, + PASSWORD_REQUIRED, + BANNED, + MEMBERS_ONLY, + KICKED, + SHUTDOWN, + UNKNOWN + } public static final String STATUS_CODE_ROOM_CONFIG_CHANGED = "104"; public static final String STATUS_CODE_SELF_PRESENCE = "110"; public static final String STATUS_CODE_BANNED = "301"; public static final String STATUS_CODE_CHANGED_NICK = "303"; public static final String STATUS_CODE_KICKED = "307"; - public static final String STATUS_CODE_LOST_MEMBERSHIP = "321"; + public static final String STATUS_CODE_AFFILIATION_CHANGE = "321"; + public static final String STATUS_CODE_LOST_MEMBERSHIP = "322"; + public static final String STATUS_CODE_SHUTDOWN = "332"; private interface OnEventListener { void onSuccess(); @@ -245,7 +249,7 @@ public class MucOptions { private Data form = new Data(); private Conversation conversation; private boolean isOnline = false; - private int error = ERROR_NO_RESPONSE; + private Error error = Error.NONE; public OnRenameListener onRenameListener = null; private User self; private String subject = null; @@ -324,8 +328,8 @@ public class MucOptions { return findUser(name) != null; } - public void setError(int error) { - this.isOnline = isOnline && error == ERROR_NO_ERROR; + public void setError(Error error) { + this.isOnline = isOnline && error == Error.NONE; this.error = error; } @@ -379,7 +383,7 @@ public class MucOptions { return this.isOnline; } - public int getError() { + public Error getError() { return this.error; } @@ -389,7 +393,7 @@ public class MucOptions { public void setOffline() { this.users.clear(); - this.error = ERROR_NO_RESPONSE; + this.error = Error.NO_RESPONSE; this.isOnline = false; } diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index dc02eda8f..63d28c97b 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -63,7 +63,7 @@ public class PresenceParser extends AbstractParser implements if (x != null) { Element item = x.findChild("item"); if (item != null && !from.isBareJid()) { - mucOptions.setError(MucOptions.ERROR_NO_ERROR); + mucOptions.setError(MucOptions.Error.NONE); MucOptions.User user = new MucOptions.User(mucOptions,from); user.setAffiliation(item.getAttribute("affiliation")); user.setRole(item.getAttribute("role")); @@ -109,13 +109,17 @@ public class PresenceParser extends AbstractParser implements if (codes.contains(MucOptions.STATUS_CODE_CHANGED_NICK)) { mucOptions.mNickChangingInProgress = true; } else if (codes.contains(MucOptions.STATUS_CODE_KICKED)) { - mucOptions.setError(MucOptions.KICKED_FROM_ROOM); + mucOptions.setError(MucOptions.Error.KICKED); } else if (codes.contains(MucOptions.STATUS_CODE_BANNED)) { - mucOptions.setError(MucOptions.ERROR_BANNED); + mucOptions.setError(MucOptions.Error.BANNED); } else if (codes.contains(MucOptions.STATUS_CODE_LOST_MEMBERSHIP)) { - mucOptions.setError(MucOptions.ERROR_MEMBERS_ONLY); + mucOptions.setError(MucOptions.Error.MEMBERS_ONLY); + } else if (codes.contains(MucOptions.STATUS_CODE_AFFILIATION_CHANGE)) { + mucOptions.setError(MucOptions.Error.MEMBERS_ONLY); + } else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN)) { + mucOptions.setError(MucOptions.Error.SHUTDOWN); } else { - mucOptions.setError(MucOptions.ERROR_UNKNOWN); + mucOptions.setError(MucOptions.Error.UNKNOWN); Log.d(Config.LOGTAG, "unknown error in conference: " + packet); } } else if (!from.isBareJid()){ @@ -132,14 +136,14 @@ public class PresenceParser extends AbstractParser implements mucOptions.onRenameListener.onFailure(); } } else { - mucOptions.setError(MucOptions.ERROR_NICK_IN_USE); + mucOptions.setError(MucOptions.Error.NICK_IN_USE); } } else if (error != null && error.hasChild("not-authorized")) { - mucOptions.setError(MucOptions.ERROR_PASSWORD_REQUIRED); + mucOptions.setError(MucOptions.Error.PASSWORD_REQUIRED); } else if (error != null && error.hasChild("forbidden")) { - mucOptions.setError(MucOptions.ERROR_BANNED); + mucOptions.setError(MucOptions.Error.BANNED); } else if (error != null && error.hasChild("registration-required")) { - mucOptions.setError(MucOptions.ERROR_MEMBERS_ONLY); + mucOptions.setError(MucOptions.Error.BANNED); } } } diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 59a37fe51..e8616bd8f 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -227,7 +227,6 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { this.execute(nextQuery); this.finalizeQuery(query, false); synchronized (this.queries) { - this.queries.remove(query); this.queries.add(nextQuery); } } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index b836e780a..24a728f7d 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1824,9 +1824,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa fetchConferenceConfiguration(conversation); } }); - + updateConversationUi(); } else { account.pendingConferenceJoins.add(conversation); + conversation.resetMucOptions(); + updateConversationUi(); } } diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index ac06452a5..c652c3c0a 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -809,26 +809,29 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa && !conversation.getMucOptions().online() && account.getStatus() == Account.State.ONLINE) { switch (conversation.getMucOptions().getError()) { - case MucOptions.ERROR_NICK_IN_USE: + case NICK_IN_USE: showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc); break; - case MucOptions.ERROR_NO_RESPONSE: - showSnackbar(R.string.conference_not_found, R.string.leave, leaveMuc); + case NO_RESPONSE: + showSnackbar(R.string.joining_conference, 0, null); break; - case MucOptions.ERROR_PASSWORD_REQUIRED: + case PASSWORD_REQUIRED: showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword); break; - case MucOptions.ERROR_BANNED: + case BANNED: showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc); break; - case MucOptions.ERROR_MEMBERS_ONLY: + case MEMBERS_ONLY: showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc); break; - case MucOptions.KICKED_FROM_ROOM: + case KICKED: showSnackbar(R.string.conference_kicked, R.string.join, joinMuc); break; - case MucOptions.ERROR_UNKNOWN: - showSnackbar(R.string.conference_unknown_error, R.string.try_again, joinMuc); + case UNKNOWN: + showSnackbar(R.string.conference_unknown_error, R.string.join, joinMuc); + break; + case SHUTDOWN: + showSnackbar(R.string.conference_shutdown, R.string.join, joinMuc); break; default: break; @@ -1091,8 +1094,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa snackbar.setOnClickListener(null); snackbarMessage.setText(message); snackbarMessage.setOnClickListener(null); - snackbarAction.setVisibility(View.VISIBLE); - snackbarAction.setText(action); + snackbarAction.setVisibility(clickListener == null ? View.GONE : View.VISIBLE); + if (action != 0) { + snackbarAction.setText(action); + } snackbarAction.setOnClickListener(clickListener); } |