From b6e26061febc8f770ec666ffcf9dcfd46716839e Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Tue, 9 Aug 2011 17:14:13 +0200
Subject: [PATCH] ability to connect to a server that doesn't support roster,
 and hide the correcponding features. Fixes #6745

---
 src/chat_control.py               | 3 ++-
 src/common/connection.py          | 5 +++--
 src/common/connection_handlers.py | 9 +++++++++
 src/conversation_textview.py      | 7 ++++---
 src/groupchat_control.py          | 3 ++-
 src/gui_menu_builder.py           | 6 +++++-
 src/roster_window.py              | 7 +++++--
 7 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/chat_control.py b/src/chat_control.py
index 201b71389d..f17ebe255f 100644
--- a/src/chat_control.py
+++ b/src/chat_control.py
@@ -1669,7 +1669,8 @@ class ChatControl(ChatControlBase):
 
         # Add to roster
         if not isinstance(self.contact, GC_Contact) \
-        and _('Not in Roster') in self.contact.groups:
+        and _('Not in Roster') in self.contact.groups and \
+        gajim.connections[self.account].roster_supported:
             self._add_to_roster_button.show()
         else:
             self._add_to_roster_button.hide()
diff --git a/src/common/connection.py b/src/common/connection.py
index 8d5c510b47..ba7d70ae1c 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -155,6 +155,7 @@ class CommonConnection:
         self.private_storage_supported = False
         self.archiving_supported = False
         self.archive_pref_supported = False
+        self.roster_supported = True
 
         self.muc_jid = {} # jid of muc server for each transport type
         self._stun_servers = [] # STUN servers of our jabber server
@@ -511,14 +512,14 @@ class CommonConnection:
         raise NotImplementedError
 
     def update_contact(self, jid, name, groups):
-        if self.connection:
+        if self.connection and self.roster_supported:
             self.connection.getRoster().setItem(jid=jid, name=name, groups=groups)
 
     def update_contacts(self, contacts):
         """
         Update multiple roster items
         """
-        if self.connection:
+        if self.connection and self.roster_supported:
             self.connection.getRoster().setItemMulti(contacts)
 
     def new_account(self, name, config, sync=False):
diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index 37185b055e..0cca49b10f 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -550,6 +550,15 @@ class ConnectionVcard:
                     roster = self.connection.getRoster(force=True)
                     roster.setRaw(roster_data)
                 self._getRoster()
+            elif iq_obj.getType() == 'error':
+                self.roster_supported = False
+                self.discoverItems(gajim.config.get_per('accounts', self.name,
+                    'hostname'), id_prefix='Gajim_')
+                if gajim.config.get_per('accounts', self.name,
+                'use_ft_proxies'):
+                    self.discover_ft_proxies()
+                gajim.nec.push_incoming_event(RosterReceivedEvent(None,
+                    conn=self))
         elif self.awaiting_answers[id_][0] == PRIVACY_ARRIVED:
             if iq_obj.getType() != 'error':
                 self.privacy_rules_supported = True
diff --git a/src/conversation_textview.py b/src/conversation_textview.py
index d3befe8a85..12912f2144 100644
--- a/src/conversation_textview.py
+++ b/src/conversation_textview.py
@@ -915,9 +915,10 @@ class ConversationTextview(gobject.GObject):
                     self.on_join_group_chat_menuitem_activate, text)
             self.handlers[id_] = childs[6]
 
-            if self.account:
-                id_ = childs[7].connect('activate', self.on_add_to_roster_activate,
-                        text)
+            if self.account and gajim.connections[self.account].\
+            roster_supported:
+                id_ = childs[7].connect('activate',
+                    self.on_add_to_roster_activate, text)
                 self.handlers[id_] = childs[7]
                 childs[7].show() # show add to roster menuitem
             else:
diff --git a/src/groupchat_control.py b/src/groupchat_control.py
index 5a8fbabc29..b7d6c6e807 100644
--- a/src/groupchat_control.py
+++ b/src/groupchat_control.py
@@ -2398,7 +2398,8 @@ class GroupchatControl(ChatControlBase):
 
         item = xml.get_object('add_to_roster_menuitem')
         our_jid = gajim.get_jid_from_account(self.account)
-        if not jid or jid == our_jid:
+        if not jid or jid == our_jid or not gajim.connections[self.account].\
+        roster_supported:
             item.set_sensitive(False)
         else:
             id_ = item.connect('activate', self.on_add_to_roster, jid)
diff --git a/src/gui_menu_builder.py b/src/gui_menu_builder.py
index 1eed94dd58..ddbb1103fb 100644
--- a/src/gui_menu_builder.py
+++ b/src/gui_menu_builder.py
@@ -425,13 +425,17 @@ control=None, gc_contact=None):
             revoke_auth_menuitem.connect('activate', roster.revoke_auth, jid,
                     account)
 
-    else:
+    elif gajim.connections[account].roster_supported:
         # contact is in group 'Not in Roster'
         add_to_roster_menuitem.set_no_show_all(False)
         subscription_menuitem.set_sensitive(False)
 
         add_to_roster_menuitem.connect('activate', roster.on_add_to_roster,
                 contact, account)
+    else:
+        add_to_roster_menuitem.hide()
+        add_to_roster_menuitem.set_no_show_all(True)
+        subscription_menuitem.set_sensitive(False)
 
     set_custom_avatar_menuitem.connect('activate',
             roster.on_set_custom_avatar_activate, contact, account)
diff --git a/src/roster_window.py b/src/roster_window.py
index 77d41987bd..df49fd06c3 100644
--- a/src/roster_window.py
+++ b/src/roster_window.py
@@ -5396,8 +5396,11 @@ class RosterWindow:
 
             edit_account_menuitem.connect('activate', self.on_edit_account,
                 account)
-            add_contact_menuitem.connect('activate', self.on_add_new_contact,
-                account)
+            if gajim.connections[account].roster_supported:
+                add_contact_menuitem.connect('activate',
+                    self.on_add_new_contact, account)
+            else:
+                add_contact_menuitem.set_sensitive(False)
             service_discovery_menuitem.connect('activate',
                 self.on_service_disco_menuitem_activate, account)
             hostname = gajim.config.get_per('accounts', account, 'hostname')
-- 
GitLab