turned muc errors into enum. added error codes for service shutdown

This commit is contained in:
Daniel Gultsch 2016-02-22 20:19:58 +01:00
parent c20d8ac69e
commit a0d0ed34ae
6 changed files with 54 additions and 39 deletions

View File

@ -91,22 +91,26 @@ public class MucOptions {
} }
} }
public static final int ERROR_NO_ERROR = 0; public enum Error {
public static final int ERROR_NICK_IN_USE = 1; NO_RESPONSE,
public static final int ERROR_UNKNOWN = 2; NONE,
public static final int ERROR_PASSWORD_REQUIRED = 3; NICK_IN_USE,
public static final int ERROR_BANNED = 4; PASSWORD_REQUIRED,
public static final int ERROR_MEMBERS_ONLY = 5; BANNED,
public static final int ERROR_NO_RESPONSE = 6; MEMBERS_ONLY,
KICKED,
public static final int KICKED_FROM_ROOM = 9; SHUTDOWN,
UNKNOWN
}
public static final String STATUS_CODE_ROOM_CONFIG_CHANGED = "104"; 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_SELF_PRESENCE = "110";
public static final String STATUS_CODE_BANNED = "301"; public static final String STATUS_CODE_BANNED = "301";
public static final String STATUS_CODE_CHANGED_NICK = "303"; public static final String STATUS_CODE_CHANGED_NICK = "303";
public static final String STATUS_CODE_KICKED = "307"; 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 { private interface OnEventListener {
void onSuccess(); void onSuccess();
@ -245,7 +249,7 @@ public class MucOptions {
private Data form = new Data(); private Data form = new Data();
private Conversation conversation; private Conversation conversation;
private boolean isOnline = false; private boolean isOnline = false;
private int error = ERROR_NO_RESPONSE; private Error error = Error.NONE;
public OnRenameListener onRenameListener = null; public OnRenameListener onRenameListener = null;
private User self; private User self;
private String subject = null; private String subject = null;
@ -324,8 +328,8 @@ public class MucOptions {
return findUser(name) != null; return findUser(name) != null;
} }
public void setError(int error) { public void setError(Error error) {
this.isOnline = isOnline && error == ERROR_NO_ERROR; this.isOnline = isOnline && error == Error.NONE;
this.error = error; this.error = error;
} }
@ -379,7 +383,7 @@ public class MucOptions {
return this.isOnline; return this.isOnline;
} }
public int getError() { public Error getError() {
return this.error; return this.error;
} }
@ -389,7 +393,7 @@ public class MucOptions {
public void setOffline() { public void setOffline() {
this.users.clear(); this.users.clear();
this.error = ERROR_NO_RESPONSE; this.error = Error.NO_RESPONSE;
this.isOnline = false; this.isOnline = false;
} }

View File

@ -63,7 +63,7 @@ public class PresenceParser extends AbstractParser implements
if (x != null) { if (x != null) {
Element item = x.findChild("item"); Element item = x.findChild("item");
if (item != null && !from.isBareJid()) { if (item != null && !from.isBareJid()) {
mucOptions.setError(MucOptions.ERROR_NO_ERROR); mucOptions.setError(MucOptions.Error.NONE);
MucOptions.User user = new MucOptions.User(mucOptions,from); MucOptions.User user = new MucOptions.User(mucOptions,from);
user.setAffiliation(item.getAttribute("affiliation")); user.setAffiliation(item.getAttribute("affiliation"));
user.setRole(item.getAttribute("role")); user.setRole(item.getAttribute("role"));
@ -109,13 +109,17 @@ public class PresenceParser extends AbstractParser implements
if (codes.contains(MucOptions.STATUS_CODE_CHANGED_NICK)) { if (codes.contains(MucOptions.STATUS_CODE_CHANGED_NICK)) {
mucOptions.mNickChangingInProgress = true; mucOptions.mNickChangingInProgress = true;
} else if (codes.contains(MucOptions.STATUS_CODE_KICKED)) { } 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)) { } 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)) { } 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 { } else {
mucOptions.setError(MucOptions.ERROR_UNKNOWN); mucOptions.setError(MucOptions.Error.UNKNOWN);
Log.d(Config.LOGTAG, "unknown error in conference: " + packet); Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
} }
} else if (!from.isBareJid()){ } else if (!from.isBareJid()){
@ -132,14 +136,14 @@ public class PresenceParser extends AbstractParser implements
mucOptions.onRenameListener.onFailure(); mucOptions.onRenameListener.onFailure();
} }
} else { } else {
mucOptions.setError(MucOptions.ERROR_NICK_IN_USE); mucOptions.setError(MucOptions.Error.NICK_IN_USE);
} }
} else if (error != null && error.hasChild("not-authorized")) { } 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")) { } 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")) { } else if (error != null && error.hasChild("registration-required")) {
mucOptions.setError(MucOptions.ERROR_MEMBERS_ONLY); mucOptions.setError(MucOptions.Error.BANNED);
} }
} }
} }

View File

@ -227,7 +227,6 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded {
this.execute(nextQuery); this.execute(nextQuery);
this.finalizeQuery(query, false); this.finalizeQuery(query, false);
synchronized (this.queries) { synchronized (this.queries) {
this.queries.remove(query);
this.queries.add(nextQuery); this.queries.add(nextQuery);
} }
} }

View File

@ -1824,9 +1824,11 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
fetchConferenceConfiguration(conversation); fetchConferenceConfiguration(conversation);
} }
}); });
updateConversationUi();
} else { } else {
account.pendingConferenceJoins.add(conversation); account.pendingConferenceJoins.add(conversation);
conversation.resetMucOptions();
updateConversationUi();
} }
} }

View File

@ -809,26 +809,29 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
&& !conversation.getMucOptions().online() && !conversation.getMucOptions().online()
&& account.getStatus() == Account.State.ONLINE) { && account.getStatus() == Account.State.ONLINE) {
switch (conversation.getMucOptions().getError()) { switch (conversation.getMucOptions().getError()) {
case MucOptions.ERROR_NICK_IN_USE: case NICK_IN_USE:
showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc); showSnackbar(R.string.nick_in_use, R.string.edit, clickToMuc);
break; break;
case MucOptions.ERROR_NO_RESPONSE: case NO_RESPONSE:
showSnackbar(R.string.conference_not_found, R.string.leave, leaveMuc); showSnackbar(R.string.joining_conference, 0, null);
break; break;
case MucOptions.ERROR_PASSWORD_REQUIRED: case PASSWORD_REQUIRED:
showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword); showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword);
break; break;
case MucOptions.ERROR_BANNED: case BANNED:
showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc); showSnackbar(R.string.conference_banned, R.string.leave, leaveMuc);
break; break;
case MucOptions.ERROR_MEMBERS_ONLY: case MEMBERS_ONLY:
showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc); showSnackbar(R.string.conference_members_only, R.string.leave, leaveMuc);
break; break;
case MucOptions.KICKED_FROM_ROOM: case KICKED:
showSnackbar(R.string.conference_kicked, R.string.join, joinMuc); showSnackbar(R.string.conference_kicked, R.string.join, joinMuc);
break; break;
case MucOptions.ERROR_UNKNOWN: case UNKNOWN:
showSnackbar(R.string.conference_unknown_error, R.string.try_again, joinMuc); showSnackbar(R.string.conference_unknown_error, R.string.join, joinMuc);
break;
case SHUTDOWN:
showSnackbar(R.string.conference_shutdown, R.string.join, joinMuc);
break; break;
default: default:
break; break;
@ -1091,8 +1094,10 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
snackbar.setOnClickListener(null); snackbar.setOnClickListener(null);
snackbarMessage.setText(message); snackbarMessage.setText(message);
snackbarMessage.setOnClickListener(null); snackbarMessage.setOnClickListener(null);
snackbarAction.setVisibility(View.VISIBLE); snackbarAction.setVisibility(clickListener == null ? View.GONE : View.VISIBLE);
if (action != 0) {
snackbarAction.setText(action); snackbarAction.setText(action);
}
snackbarAction.setOnClickListener(clickListener); snackbarAction.setOnClickListener(clickListener);
} }

View File

@ -241,8 +241,7 @@
<string name="bookmark_already_exists">This bookmark already exists</string> <string name="bookmark_already_exists">This bookmark already exists</string>
<string name="you">You</string> <string name="you">You</string>
<string name="action_edit_subject">Edit conference subject</string> <string name="action_edit_subject">Edit conference subject</string>
<string name="conference_not_found">Conference not found</string> <string name="joining_conference">Joining conference…</string>
<string name="conference_unknown_error">Unknown error received</string>2
<string name="leave">Leave</string> <string name="leave">Leave</string>
<string name="contact_added_you">Contact added you to contact list</string> <string name="contact_added_you">Contact added you to contact list</string>
<string name="add_back">Add back</string> <string name="add_back">Add back</string>
@ -340,6 +339,8 @@
<string name="conference_banned">You are banned from this conference</string> <string name="conference_banned">You are banned from this conference</string>
<string name="conference_members_only">This conference is members only</string> <string name="conference_members_only">This conference is members only</string>
<string name="conference_kicked">You have been kicked from this conference</string> <string name="conference_kicked">You have been kicked from this conference</string>
<string name="conference_shutdown">The conference was shut down</string>
<string name="conference_unknown_error">You are no longer in this conference</string>
<string name="using_account">using account %s</string> <string name="using_account">using account %s</string>
<string name="checking_x">Checking %s on HTTP host</string> <string name="checking_x">Checking %s on HTTP host</string>
<string name="not_connected_try_again">You are not connected. Try again later</string> <string name="not_connected_try_again">You are not connected. Try again later</string>