display propper toast after room has been destroyed

This commit is contained in:
Daniel Gultsch 2018-07-11 21:33:27 +02:00
parent f9c5cdee6e
commit 4871263d9c
4 changed files with 32 additions and 1 deletions

View File

@ -167,6 +167,7 @@ public class MucOptions {
RESOURCE_CONSTRAINT, RESOURCE_CONSTRAINT,
KICKED, KICKED,
SHUTDOWN, SHUTDOWN,
DESTROYED,
INVALID_NICK, INVALID_NICK,
UNKNOWN UNKNOWN
} }

View File

@ -20,6 +20,7 @@ import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.generator.IqGenerator; import eu.siacs.conversations.generator.IqGenerator;
import eu.siacs.conversations.generator.PresenceGenerator; import eu.siacs.conversations.generator.PresenceGenerator;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xml.Namespace; import eu.siacs.conversations.xml.Namespace;
import eu.siacs.conversations.xmpp.InvalidJid; import eu.siacs.conversations.xmpp.InvalidJid;
@ -125,7 +126,15 @@ public class PresenceParser extends AbstractParser implements
} }
} }
} else if (type.equals("unavailable")) { } else if (type.equals("unavailable")) {
if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN) && from.equals(mucOptions.getSelf().getFullJid())) { final boolean fullJidMatches = from.equals(mucOptions.getSelf().getFullJid());
if (x.hasChild("destroy") && fullJidMatches) {
Element destroy = x.findChild("destroy");
final Jid alternate = destroy == null ? null : InvalidJid.getNullForInvalid(destroy.getAttributeAsJid("jid"));
mucOptions.setError(MucOptions.Error.DESTROYED);
if (alternate != null) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
}
} else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN) && fullJidMatches) {
mucOptions.setError(MucOptions.Error.SHUTDOWN); mucOptions.setError(MucOptions.Error.SHUTDOWN);
} else if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE)) { } else if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE)) {
if (codes.contains(MucOptions.STATUS_CODE_KICKED)) { if (codes.contains(MucOptions.STATUS_CODE_KICKED)) {
@ -171,6 +180,23 @@ public class PresenceParser extends AbstractParser implements
mucOptions.setError(MucOptions.Error.MEMBERS_ONLY); mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
} else if (error.hasChild("resource-constraint")) { } else if (error.hasChild("resource-constraint")) {
mucOptions.setError(MucOptions.Error.RESOURCE_CONSTRAINT); mucOptions.setError(MucOptions.Error.RESOURCE_CONSTRAINT);
} else if (error.hasChild("gone")) {
final String gone = error.findChildContent("gone");
final Jid alternate;
if (gone != null) {
final XmppUri xmppUri = new XmppUri(gone);
if (xmppUri.isJidValid()) {
alternate = xmppUri.getJid();
} else {
alternate = null;
}
} else {
alternate = null;
}
mucOptions.setError(MucOptions.Error.DESTROYED);
if (alternate != null) {
Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
}
} else { } else {
final String text = error.findChildContent("text"); final String text = error.findChildContent("text");
if (text != null && text.contains("attribute 'to'")) { if (text != null && text.contains("attribute 'to'")) {

View File

@ -2034,6 +2034,9 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
case SHUTDOWN: case SHUTDOWN:
showSnackbar(R.string.conference_shutdown, R.string.try_again, joinMuc); showSnackbar(R.string.conference_shutdown, R.string.try_again, joinMuc);
break; break;
case DESTROYED:
showSnackbar(R.string.conference_destroyed, R.string.leave, leaveMuc);
break;
default: default:
hideSnackbar(); hideSnackbar();
break; break;

View File

@ -721,4 +721,5 @@
<string name="group_chat_name">Name</string> <string name="group_chat_name">Name</string>
<string name="providing_a_name_is_optional">Providing a name is optional</string> <string name="providing_a_name_is_optional">Providing a name is optional</string>
<string name="create_dialog_group_chat_name">Group chat name</string> <string name="create_dialog_group_chat_name">Group chat name</string>
<string name="conference_destroyed">This group chat has been destroyed</string>
</resources> </resources>