From 26765a8a0d4df43ea0e29101a86aa58c81dda0a4 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 10 Aug 2017 22:33:40 +0200 Subject: [PATCH] send unavailable presence before join --- .../conversations/generator/PresenceGenerator.java | 9 +++++++++ .../conversations/services/XmppConnectionService.java | 10 +++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java index f8639885b..38d99bb71 100644 --- a/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/PresenceGenerator.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.generator; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; +import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.xml.Element; @@ -62,6 +63,14 @@ public class PresenceGenerator extends AbstractGenerator { return packet; } + public PresencePacket leave(final MucOptions mucOptions) { + PresencePacket presencePacket = new PresencePacket(); + presencePacket.setTo(mucOptions.getSelf().getFullJid()); + presencePacket.setFrom(mucOptions.getAccount().getJid()); + presencePacket.setAttribute("type", "unavailable"); + return presencePacket; + } + public PresencePacket sendOfflinePresence(Account account) { PresencePacket packet = new PresencePacket(); packet.setFrom(account.getJid()); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 339266932..392939bd8 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2246,6 +2246,7 @@ public class XmppConnectionService extends Service { account.pendingConferenceJoins.remove(conversation); account.pendingConferenceLeaves.remove(conversation); if (account.getStatus() == Account.State.ONLINE) { + sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions())); conversation.resetMucOptions(); if (onConferenceJoined != null) { conversation.getMucOptions().flagNoAutoPushConfiguration(); @@ -2460,15 +2461,10 @@ public class XmppConnectionService extends Service { account.pendingConferenceJoins.remove(conversation); account.pendingConferenceLeaves.remove(conversation); if (account.getStatus() == Account.State.ONLINE || now) { - PresencePacket packet = new PresencePacket(); - packet.setTo(conversation.getMucOptions().getSelf().getFullJid()); - packet.setFrom(conversation.getAccount().getJid()); - packet.setAttribute("type", "unavailable"); - sendPresencePacket(conversation.getAccount(), packet); + sendPresencePacket(conversation.getAccount(), mPresenceGenerator.leave(conversation.getMucOptions())); conversation.getMucOptions().setOffline(); conversation.deregisterWithBookmark(); - Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() - + ": leaving muc " + conversation.getJid()); + Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": leaving muc " + conversation.getJid()); } else { account.pendingConferenceLeaves.add(conversation); }