self ping (xep-0410) after receiving invite to muc

This commit is contained in:
Daniel Gultsch 2019-06-18 13:20:24 +02:00
parent e432710a3f
commit 6862b60c3f
4 changed files with 28 additions and 4 deletions

View file

@ -869,7 +869,10 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
public boolean execute(Account account) { public boolean execute(Account account) {
if (jid != null) { if (jid != null) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true, false); 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); conversation.getMucOptions().setPassword(password);
mXmppConnectionService.databaseBackend.updateConversation(conversation); mXmppConnectionService.databaseBackend.updateConversation(conversation);
mXmppConnectionService.joinMuc(conversation, inviter != null && inviter.mutualPresenceSubscription()); mXmppConnectionService.joinMuc(conversation, inviter != null && inviter.mutualPresenceSubscription());

View file

@ -1974,7 +1974,7 @@ public class XmppConnectionService extends Service {
archiveConversation(conversation, true); archiveConversation(conversation, true);
} }
private void archiveConversation(Conversation conversation, final boolean maySyncronizeWithBookmarks) { private void archiveConversation(Conversation conversation, final boolean maySynchronizeWithBookmarks) {
getNotificationService().clear(conversation); getNotificationService().clear(conversation);
conversation.setStatus(Conversation.STATUS_ARCHIVED); conversation.setStatus(Conversation.STATUS_ARCHIVED);
conversation.setNextMessage(null); conversation.setNextMessage(null);
@ -1983,7 +1983,7 @@ public class XmppConnectionService extends Service {
if (conversation.getMode() == Conversation.MODE_MULTI) { if (conversation.getMode() == Conversation.MODE_MULTI) {
if (conversation.getAccount().getStatus() == Account.State.ONLINE) { if (conversation.getAccount().getStatus() == Account.State.ONLINE) {
Bookmark bookmark = conversation.getBookmark(); Bookmark bookmark = conversation.getBookmark();
if (maySyncronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) { if (maySynchronizeWithBookmarks && bookmark != null && synchronizeWithBookmarks()) {
if (conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) { if (conversation.getMucOptions().getError() == MucOptions.Error.DESTROYED) {
Account account = bookmark.getAccount(); Account account = bookmark.getAccount();
bookmark.setConversation(null); 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) { public void joinMuc(Conversation conversation) {
joinMuc(conversation, null, false); joinMuc(conversation, null, false);
} }

View file

@ -27,4 +27,5 @@ public final class Namespace {
public static final String AVATAR_CONVERSION = "urn:xmpp:pep-vcard-conversion:0"; 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_S5B = "urn:xmpp:jingle:transports:s5b:1";
public static final String JINGLE_TRANSPORTS_IBB = "urn:xmpp:jingle:transports:ibb:1"; public static final String JINGLE_TRANSPORTS_IBB = "urn:xmpp:jingle:transports:ibb:1";
public static final String PING = "urn:xmpp:ping";
} }

View file

@ -1417,7 +1417,7 @@ public class XmppConnection implements Runnable {
if (!r()) { if (!r()) {
final IqPacket iq = new IqPacket(IqPacket.TYPE.GET); final IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
iq.setFrom(account.getJid()); iq.setFrom(account.getJid());
iq.addChild("ping", "urn:xmpp:ping"); iq.addChild("ping", Namespace.PING);
this.sendIqPacket(iq, null); this.sendIqPacket(iq, null);
} }
this.lastPingSent = SystemClock.elapsedRealtime(); this.lastPingSent = SystemClock.elapsedRealtime();