diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-06-25 12:12:06 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-06-25 12:12:06 +0200 |
commit | 73c8feea13a526259ee5bb58e639e31ad781fd79 (patch) | |
tree | 63d9c368081ff47d6160bd78669fbcc28ff71a8b /src/main/java/de/pixart/messenger/services | |
parent | e09feea27ceb9729264cf8c19296b6a2a68238a7 (diff) |
implement client support for muc push
Staying connected to a MUC room hosted on a remote server can be challenging.
If a server reboots it will usually send a shut down notification to all
participants. However even if a client knows that a server was shut down it
doesn’t know when it comes up again. In some corner cases that shut down
notification might not even be delivered successfully leaving the client in a
state where it thinks it is connected but it really isn’t.
The possible work around implemented in this commit is to register the clients
full JID (user@domain.tld/Conversations.r4nd) as an App Server according to
XEP-0357 with the room. (Conversations checks for the push:0 namespace on the
room.)
After cycling through a reboot the first message send to a room will trigger
pubsub notifications to each registered full JID. This event will be used to
trigger a XEP-0410 ping and if necessary a subsequent rejoin of the MUC.
If the resource has become unavailable during down time of the MUC server the
user’s server will respond with an IQ error which in turn leads to the MUC
server disabling that push target.
Leaving a MUC will send a `disable` command. If sending that disable command
failed for some reason (network outage) and the client receives a pubsub
notification for a room it is no longer joined in it will respond with an
item-not-found IQ error which also disables subsequent pushes from the server.
Note: We 0410-ping before a join to avoid unnecessary full joins which can be
quite costly. Further client side optimizations will also suppress pings when
a ping is already in flight to further save traffic.
Diffstat (limited to 'src/main/java/de/pixart/messenger/services')
-rw-r--r-- | src/main/java/de/pixart/messenger/services/XmppConnectionService.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 8ce549e8c..b9945de0a 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -2803,6 +2803,9 @@ public class XmppConnectionService extends Service { saveConversationAsBookmark(conversation, null); } } + if (mucOptions.push()) { + enableMucPush(conversation); + } synchronized (account.inProgressConferenceJoins) { account.inProgressConferenceJoins.remove(conversation); sendUnsentMessages(conversation); @@ -2845,6 +2848,35 @@ public class XmppConnectionService extends Service { } } + private void enableMucPush(final Conversation conversation) { + final Account account = conversation.getAccount(); + final Jid room = conversation.getJid().asBareJid(); + final IqPacket enable = mIqGenerator.enablePush(conversation.getAccount().getJid(), conversation.getUuid(), null); + enable.setTo(room); + sendIqPacket(account, enable, (a, response) -> { + if (response.getType() == IqPacket.TYPE.RESULT) { + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": enabled push for muc " + room); + } else if (response.getType() == IqPacket.TYPE.ERROR) { + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to enable push for muc " + room + " " + response.getError()); + } + }); + + } + + private void disableMucPush(final Conversation conversation) { + final Account account = conversation.getAccount(); + final Jid room = conversation.getJid().asBareJid(); + final IqPacket disable = mIqGenerator.disablePush(conversation.getAccount().getJid(), conversation.getUuid()); + disable.setTo(room); + sendIqPacket(account, disable, (a, response) -> { + if (response.getType() == IqPacket.TYPE.RESULT) { + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": disabled push for muc " + room); + } else if (response.getType() == IqPacket.TYPE.ERROR) { + Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": unable to disable push for muc " + room + " " + response.getError()); + } + }); + } + private void fetchConferenceMembers(final Conversation conversation) { final Account account = conversation.getAccount(); final AxolotlService axolotlService = account.getAxolotlService(); @@ -3025,6 +3057,9 @@ public class XmppConnectionService extends Service { account.pendingConferenceJoins.remove(conversation); account.pendingConferenceLeaves.remove(conversation); if (account.getStatus() == Account.State.ONLINE || now) { + if (conversation.getMucOptions().push()) { + disableMucPush(conversation); + } sendPresencePacket(conversation.getAccount(), mPresenceGenerator.leave(conversation.getMucOptions())); conversation.getMucOptions().setOffline(); Bookmark bookmark = conversation.getBookmark(); |