From c04f0e97837dfc0c73defa3aaeada5c3848e2c59 Mon Sep 17 00:00:00 2001 From: mathieui Date: Wed, 16 May 2012 02:01:50 +0200 Subject: [PATCH] =?UTF-8?q?Prevent=20the=20rooms=20from=20going=20?= =?UTF-8?q?=E2=80=9Coffline=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a blacklist inside the roster that contains the bare JIDs of all the rooms ever joined in this session, so that no JID using this server will ever be shown as getting “offline”. If there is a cleaner way to do that (discriminating JIDs), I welcome it. --- src/core.py | 5 +++++ src/roster.py | 6 +++++- src/tabs.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/core.py b/src/core.py index c2624584..a89e7b25 100644 --- a/src/core.py +++ b/src/core.py @@ -658,12 +658,17 @@ class Core(object): self.add_tab(form_tab, True) def on_got_offline(self, presence): + """ + A JID got offline + """ jid = presence['from'] logger.log_roster_change(jid.bare, 'got offline') # If a resource got offline, display the message in the conversation with this # precise resource. if jid.resource: self.add_information_message_to_conversation_tab(jid.full, '\x195}%s is \x191}offline' % (jid.full)) + if jid.server in roster.blacklist: + return self.add_information_message_to_conversation_tab(jid.bare, '\x195}%s is \x191}offline' % (jid.bare)) self.information('\x193}%s \x195}is \x191}offline' % (jid.bare), 'Roster') if isinstance(self.current_tab(), tabs.RosterInfoTab): diff --git a/src/roster.py b/src/roster.py index 7f93c4b2..e1251024 100644 --- a/src/roster.py +++ b/src/roster.py @@ -19,6 +19,10 @@ from sleekxmpp.xmlstream.stanzabase import JID from sleekxmpp.exceptions import IqError class Roster(object): + + # MUC domains to blacklist from the contacts roster + blacklist = set() + def __init__(self): """ node: the RosterSingle from SleekXMPP @@ -103,7 +107,7 @@ class Roster(object): def jids(self): """List of the contact JIDS""" - return [key for key in self.__node.keys() if key not in self.__mucs and key != self.jid] + return [key for key in self.__node.keys() if JID(key).server not in self.blacklist and key != self.jid] def get_contacts(self): """ diff --git a/src/tabs.py b/src/tabs.py index f798df69..be8085e8 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -1171,6 +1171,7 @@ class MucTab(ChatTab): self.core.events.trigger('muc_join', presence, self) if from_nick == self.own_nick: self.joined = True + roster.blacklist.add(JID(from_room).server) if self.get_name() in self.core.initial_joins: self.core.initial_joins.remove(self.get_name()) self._state = 'normal'