send unavailable presence before join

This commit is contained in:
Daniel Gultsch 2017-08-10 22:33:40 +02:00
parent 1b5979dc50
commit 26765a8a0d
2 changed files with 12 additions and 7 deletions

View file

@ -2,6 +2,7 @@ package eu.siacs.conversations.generator;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.Presence; import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
@ -62,6 +63,14 @@ public class PresenceGenerator extends AbstractGenerator {
return packet; 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) { public PresencePacket sendOfflinePresence(Account account) {
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
packet.setFrom(account.getJid()); packet.setFrom(account.getJid());

View file

@ -2246,6 +2246,7 @@ public class XmppConnectionService extends Service {
account.pendingConferenceJoins.remove(conversation); account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation); account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE) { if (account.getStatus() == Account.State.ONLINE) {
sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions()));
conversation.resetMucOptions(); conversation.resetMucOptions();
if (onConferenceJoined != null) { if (onConferenceJoined != null) {
conversation.getMucOptions().flagNoAutoPushConfiguration(); conversation.getMucOptions().flagNoAutoPushConfiguration();
@ -2460,15 +2461,10 @@ public class XmppConnectionService extends Service {
account.pendingConferenceJoins.remove(conversation); account.pendingConferenceJoins.remove(conversation);
account.pendingConferenceLeaves.remove(conversation); account.pendingConferenceLeaves.remove(conversation);
if (account.getStatus() == Account.State.ONLINE || now) { if (account.getStatus() == Account.State.ONLINE || now) {
PresencePacket packet = new PresencePacket(); sendPresencePacket(conversation.getAccount(), mPresenceGenerator.leave(conversation.getMucOptions()));
packet.setTo(conversation.getMucOptions().getSelf().getFullJid());
packet.setFrom(conversation.getAccount().getJid());
packet.setAttribute("type", "unavailable");
sendPresencePacket(conversation.getAccount(), packet);
conversation.getMucOptions().setOffline(); conversation.getMucOptions().setOffline();
conversation.deregisterWithBookmark(); conversation.deregisterWithBookmark();
Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": leaving muc " + conversation.getJid());
+ ": leaving muc " + conversation.getJid());
} else { } else {
account.pendingConferenceLeaves.add(conversation); account.pendingConferenceLeaves.add(conversation);
} }