ignore groupchats messages that are pending leave

This commit is contained in:
iNPUTmice 2014-07-20 02:26:23 +02:00
parent 1cfe557b2b
commit 22e504b8f9
3 changed files with 31 additions and 26 deletions

View File

@ -109,6 +109,9 @@ public class MessageParser extends AbstractParser implements
private Message parseGroupchat(MessagePacket packet, Account account) { private Message parseGroupchat(MessagePacket packet, Account account) {
int status; int status;
String[] fromParts = packet.getFrom().split("/"); String[] fromParts = packet.getFrom().split("/");
if (mXmppConnectionService.find(account.pendingConferenceLeaves,account,fromParts[0]) != null) {
return null;
}
Conversation conversation = mXmppConnectionService Conversation conversation = mXmppConnectionService
.findOrCreateConversation(account, fromParts[0], true); .findOrCreateConversation(account, fromParts[0], true);
if (packet.hasChild("subject")) { if (packet.hasChild("subject")) {

View File

@ -21,14 +21,14 @@ public class PresenceParser extends AbstractParser implements
public void parseConferencePresence(PresencePacket packet, Account account) { public void parseConferencePresence(PresencePacket packet, Account account) {
PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine(); PgpEngine mPgpEngine = mXmppConnectionService.getPgpEngine();
if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) { if (packet.hasChild("x", "http://jabber.org/protocol/muc#user")) {
Conversation muc = mXmppConnectionService.findMuc(packet Conversation muc = mXmppConnectionService.find(account,packet
.getAttribute("from").split("/")[0], account); .getAttribute("from").split("/")[0]);
if (muc != null) { if (muc != null) {
muc.getMucOptions().processPacket(packet, mPgpEngine); muc.getMucOptions().processPacket(packet, mPgpEngine);
} }
} else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) { } else if (packet.hasChild("x", "http://jabber.org/protocol/muc")) {
Conversation muc = mXmppConnectionService.findMuc(packet Conversation muc = mXmppConnectionService.find(account,packet
.getAttribute("from").split("/")[0], account); .getAttribute("from").split("/")[0]);
if (muc != null) { if (muc != null) {
int error = muc.getMucOptions().getError(); int error = muc.getMucOptions().getError();
muc.getMucOptions().processPacket(packet, mPgpEngine); muc.getMucOptions().processPacket(packet, mPgpEngine);

View File

@ -111,7 +111,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onContactStatusChanged(Contact contact, boolean online) { public void onContactStatusChanged(Contact contact, boolean online) {
Conversation conversation = findActiveConversation(contact); Conversation conversation = find(getConversations(),contact);
if (conversation != null) { if (conversation != null) {
conversation.endOtrIfNeeded(); conversation.endOtrIfNeeded();
if (online && (contact.getPresences().size() == 1)) { if (online && (contact.getPresences().size() == 1)) {
@ -268,18 +268,12 @@ public class XmppConnectionService extends Service {
return message; return message;
} }
public Conversation findMuc(Bookmark bookmark) { public Conversation find(Bookmark bookmark) {
return findMuc(bookmark.getJid(), bookmark.getAccount()); return find(bookmark.getAccount(),bookmark.getJid());
} }
public Conversation findMuc(String jid, Account account) { public Conversation find(Account account, String jid) {
for (Conversation conversation : this.conversations) { return find(getConversations(),account,jid);
if (conversation.getContactJid().split("/")[0].equals(jid)
&& (conversation.getAccount() == account)) {
return conversation;
}
}
return null;
} }
public class XmppConnectionBinder extends Binder { public class XmppConnectionBinder extends Binder {
@ -693,7 +687,7 @@ public class XmppConnectionService extends Service {
if (item.getName().equals("conference")) { if (item.getName().equals("conference")) {
Bookmark bookmark = Bookmark.parse(item,account); Bookmark bookmark = Bookmark.parse(item,account);
bookmarks.add(bookmark); bookmarks.add(bookmark);
Conversation conversation = findMuc(bookmark); Conversation conversation = find(bookmark);
if (conversation!=null) { if (conversation!=null) {
conversation.setBookmark(bookmark); conversation.setBookmark(bookmark);
} else { } else {
@ -802,8 +796,8 @@ public class XmppConnectionService extends Service {
return this.accounts; return this.accounts;
} }
public Conversation findActiveConversation(Contact contact) { public Conversation find(List<Conversation> haystack, Contact contact) {
for (Conversation conversation : this.getConversations()) { for (Conversation conversation : haystack) {
if (conversation.getContact() == contact) { if (conversation.getContact() == contact) {
return conversation; return conversation;
} }
@ -811,16 +805,24 @@ public class XmppConnectionService extends Service {
return null; return null;
} }
public Conversation find(List<Conversation> haystack, Account account, String jid) {
for (Conversation conversation : haystack) {
if ((conversation.getAccount().equals(account))
&& (conversation.getContactJid().split("/")[0].equals(jid))) {
return conversation;
}
}
return null;
}
public Conversation findOrCreateConversation(Account account, String jid, public Conversation findOrCreateConversation(Account account, String jid,
boolean muc) { boolean muc) {
for (Conversation conv : this.getConversations()) { Conversation conversation = find(account, jid);
if ((conv.getAccount().equals(account)) if (conversation != null) {
&& (conv.getContactJid().split("/")[0].equals(jid))) { return conversation;
return conv;
} }
} conversation = databaseBackend.findConversation(account,jid);
Conversation conversation = databaseBackend.findConversation(account,
jid);
if (conversation != null) { if (conversation != null) {
conversation.setStatus(Conversation.STATUS_AVAILABLE); conversation.setStatus(Conversation.STATUS_AVAILABLE);
conversation.setAccount(account); conversation.setAccount(account);