From 5b41c0da43d7c2f18fd96aa81cd70ffe8f5970f6 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Thu, 9 Mar 2017 20:01:20 +0100 Subject: closing the corresponding conversations after blocking a contact --- .../messenger/services/XmppConnectionService.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/main/java/de/pixart/messenger/services') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index f2a6dc308..4c6dd9ccd 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -3747,7 +3747,7 @@ public class XmppConnectionService extends Service { mDatabaseExecutor.execute(runnable); } - public void sendBlockRequest(final Blockable blockable, boolean reportSpam) { + public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) { if (blockable != null && blockable.getBlockedJid() != null) { final Jid jid = blockable.getBlockedJid(); this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() { @@ -3760,7 +3760,37 @@ public class XmppConnectionService extends Service { } } }); + if (removeBlockedConversations(blockable.getAccount(), jid)) { + updateConversationUi(); + return true; + } else { + return false; + } + } else { + return false; + } + } + + public boolean removeBlockedConversations(final Account account, final Jid blockedJid) { + boolean removed = false; + synchronized (this.conversations) { + boolean domainJid = blockedJid.isDomainJid(); + for (Conversation conversation : this.conversations) { + boolean jidMatches = (domainJid && blockedJid.getDomainpart().equals(conversation.getJid().getDomainpart())) + || blockedJid.equals(conversation.getJid().toBareJid()); + if (conversation.getAccount() == account + && conversation.getMode() == Conversation.MODE_SINGLE + && jidMatches) { + this.conversations.remove(conversation); + markRead(conversation); + conversation.setStatus(Conversation.STATUS_ARCHIVED); + Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": archiving conversation " + conversation.getJid().toBareJid() + " because jid was blocked"); + updateConversation(conversation); + removed = true; + } + } } + return removed; } public void sendUnblockRequest(final Blockable blockable) { -- cgit v1.2.3