From 8c85ae00295132ff02012ba5c3c8a0706e6ed158 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Tue, 10 Aug 2021 12:18:31 -0400
Subject: [PATCH] conversationfacade: use removeContact for one to one
 conversations

Change-Id: I7cc80ce64a818cb8801ed56da6e348ba5c7f5bf3
GitLab: https://git.jami.net/savoirfairelinux/ring-project/-/issues/1282
---
 .../java/net/jami/facades/ConversationFacade.java    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/ring-android/libringclient/src/main/java/net/jami/facades/ConversationFacade.java b/ring-android/libringclient/src/main/java/net/jami/facades/ConversationFacade.java
index fdcd012ab..168d9e1a9 100644
--- a/ring-android/libringclient/src/main/java/net/jami/facades/ConversationFacade.java
+++ b/ring-android/libringclient/src/main/java/net/jami/facades/ConversationFacade.java
@@ -693,7 +693,17 @@ public class ConversationFacade {
 
     public Completable removeConversation(String accountId, Uri conversationUri) {
         if (conversationUri.isSwarm()) {
-            return mAccountService.removeConversation(accountId, conversationUri);
+            // For a one to one conversation, contact is strongly related, so remove the contact.
+            // This will remove related conversations
+            Account account = mAccountService.getAccount(accountId);
+            Conversation conversation = account.getSwarm(conversationUri.getRawRingId());
+            if (conversation != null && conversation.getMode().blockingFirst() == Conversation.Mode.OneToOne) {
+                Contact contact = conversation.getContact();
+                mAccountService.removeContact(accountId, contact.getUri().getRawRingId(), false);
+                return Completable.complete();
+            } else {
+                return mAccountService.removeConversation(accountId, conversationUri);
+            }
         } else {
             return mHistoryService
                     .clearHistory(conversationUri.getUri(), accountId, true)
-- 
GitLab