From 72bca44272629ca11a14988e0f93b954145d1887 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Sat, 21 Jan 2012 16:32:52 +0100
Subject: [PATCH] fix behaviour when we remove a contact for which we have a
 chat tab opened (re-add it to not in roster group). Fixes #7078

---
 src/common/connection_handlers.py |  2 +-
 src/roster_window.py              | 57 ++++++++++++++++---------------
 2 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index 6398a3e42b..bad67bdc87 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -865,7 +865,7 @@ class ConnectionHandlersBase:
             elif obj.contact.show in statuss:
                 obj.old_show = statuss.index(obj.contact.show)
             if (resources != [''] and (len(obj.contact_list) != 1 or \
-            obj.contact_list[0].show != 'offline')) and \
+            obj.contact_list[0].show not in ('not in roster', 'offline'))) and \
             not gajim.jid_is_transport(jid):
                 # Another resource of an existing contact connected
                 obj.old_show = 0
diff --git a/src/roster_window.py b/src/roster_window.py
index 8b860a998b..df6d06d334 100644
--- a/src/roster_window.py
+++ b/src/roster_window.py
@@ -726,17 +726,9 @@ class RosterWindow:
         if not contact:
             return
 
-        if not force and (self.contact_has_pending_roster_events(contact,
-        account) or gajim.interface.msg_win_mgr.get_control(jid, account)):
-            # Contact has pending events or window
-            #TODO: or single message windows? Bur they are not listed for the
-            # moment
-            key = (jid, account)
-            if not key in self.contacts_to_be_removed:
-                self.contacts_to_be_removed[key] = {'backend': backend}
-            # if more pending event, don't remove from roster
-            if self.contact_has_pending_roster_events(contact, account):
-                return False
+        if not force and self.contact_has_pending_roster_events(contact,
+        account):
+            return False
 
         iters = self._get_contact_iter(jid, account, contact, self.model)
         if iters:
@@ -749,25 +741,36 @@ class RosterWindow:
             else:
                 self._remove_entity(contact, account)
 
-        if backend and (not gajim.interface.msg_win_mgr.get_control(jid,
-        account) or force):
-            # If a window is still opened: don't remove contact instance
-            # Remove contact before redrawing, otherwise the old
-            # numbers will still be show
-            gajim.contacts.remove_jid(account, jid, remove_meta=True)
-            if iters:
-                rest_of_family = [data for data in family
-                    if account != data['account'] or jid != data['jid']]
-                if rest_of_family:
-                    # reshow the rest of the family
-                    brothers = self._add_metacontact_family(rest_of_family,
-                        account)
-                    for c, acc in brothers:
-                        self.draw_completely(c.jid, acc)
+        old_grps = []
+        if backend:
+            if not gajim.interface.msg_win_mgr.get_control(jid, account) or \
+            force:
+                # If a window is still opened: don't remove contact instance
+                # Remove contact before redrawing, otherwise the old
+                # numbers will still be show
+                gajim.contacts.remove_jid(account, jid, remove_meta=True)
+                if iters:
+                    rest_of_family = [data for data in family
+                        if account != data['account'] or jid != data['jid']]
+                    if rest_of_family:
+                        # reshow the rest of the family
+                        brothers = self._add_metacontact_family(rest_of_family,
+                            account)
+                        for c, acc in brothers:
+                            self.draw_completely(c.jid, acc)
+            else:
+                for c in gajim.contacts.get_contacts(account, jid):
+                    c.sub = 'none'
+                    c.show = 'not in roster'
+                    c.status = ''
+                    old_grps = c.get_shown_groups()
+                    c.groups = [_('Not in Roster')]
+                    self._add_entity(c, account)
+                    self.draw_contact(jid, account)
 
         if iters:
             # Draw all groups of the contact
-            for group in contact.get_shown_groups():
+            for group in contact.get_shown_groups() + old_grps:
                 self.draw_group(group, account)
             self.draw_account(account)
 
-- 
GitLab