diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 10c9e9764..72aaf1fa0 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -869,7 +869,10 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece public boolean execute(Account account) { if (jid != null) { Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true, false); - if (!conversation.getMucOptions().online()) { + if (conversation.getMucOptions().online()) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": received invite to "+jid+" but muc is considered to be online"); + mXmppConnectionService.mucSelfPingAndRejoin(conversation); + } else { conversation.getMucOptions().setPassword(password); mXmppConnectionService.databaseBackend.updateConversation(conversation); mXmppConnectionService.joinMuc(conversation, inviter != null && inviter.mutualPresenceSubscription()); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 5eeaab99c..a596f3b87 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -1974,7 +1974,7 @@ public class XmppConnectionService extends Service { archiveConversation(conversation, true); } - private void archiveConversation(Conversation conversation, final boolean maySyncronizeWithBookmarks) { + private void archiveConversation(Conversation conversation, final boolean maySynchronizeWithBookmarks) { getNotificationService().clear(conversation); conversation.setStatus(Conversation.STATUS_ARCHIVED); conversation.setNextMessage(null); @@ -1983,7 +1983,7 @@ public class XmppConnectionService extends Service { if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getAccount().getStatus() == Account.State.ONLINE) { Bookmark bookmark = conversation.getBookmark(); - if (maySyncronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) { + if (maySynchronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) { if (conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) { Account account = bookmark.getAccount(); bookmark.setConversation(null); @@ -2431,6 +2431,26 @@ public class XmppConnectionService extends Service { } } + public void mucSelfPingAndRejoin(final Conversation conversation) { + final Jid self = conversation.getMucOptions().getSelf().getFullJid(); + final IqPacket ping = new IqPacket(IqPacket.TYPE.GET); + ping.setTo(self); + ping.addChild("ping", Namespace.PING); + sendIqPacket(conversation.getAccount(), ping, (account, response) -> { + if (response.getType() == IqPacket.TYPE.ERROR) { + Element error = response.findChild("error"); + if (error == null || error.hasChild("service-unavailable") || error.hasChild("feature-not-implemented") || error.hasChild("item-not-found")) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ping to "+self+" came back as ignorable error"); + } else { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ping to "+self+" failed. attempting rejoin"); + joinMuc(conversation); + } + } else if (response.getType() == IqPacket.TYPE.RESULT) { + Log.d(Config.LOGTAG,account.getJid().asBareJid()+": ping to "+self+" came back fine"); + } + }); + } + public void joinMuc(Conversation conversation) { joinMuc(conversation, null, false); } diff --git a/src/main/java/eu/siacs/conversations/xml/Namespace.java b/src/main/java/eu/siacs/conversations/xml/Namespace.java index 0d478c586..73d3d452d 100644 --- a/src/main/java/eu/siacs/conversations/xml/Namespace.java +++ b/src/main/java/eu/siacs/conversations/xml/Namespace.java @@ -27,4 +27,5 @@ public final class Namespace { public static final String AVATAR_CONVERSION = "urn:xmpp:pep-vcard-conversion:0"; public static final String JINGLE_TRANSPORTS_S5B = "urn:xmpp:jingle:transports:s5b:1"; public static final String JINGLE_TRANSPORTS_IBB = "urn:xmpp:jingle:transports:ibb:1"; + public static final String PING = "urn:xmpp:ping"; } diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index 90a7fe02c..d157926b6 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -1417,7 +1417,7 @@ public class XmppConnection implements Runnable { if (!r()) { final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); iq.setFrom(account.getJid()); - iq.addChild("ping", "urn:xmpp:ping"); + iq.addChild("ping", Namespace.PING); this.sendIqPacket(iq, null); } this.lastPingSent = SystemClock.elapsedRealtime();