diff src/core/xmpp.py @ 518:75216d94a89d

primitivus: fixed messages order in chat window
author Goffi <goffi@goffi.org>
date Sun, 21 Oct 2012 12:03:29 +0200
parents 8ee9113d307b
children b7577230a7c8
line wrap: on
line diff
--- a/src/core/xmpp.py	Sat Oct 20 19:22:51 2012 +0200
+++ b/src/core/xmpp.py	Sun Oct 21 12:03:29 2012 +0200
@@ -37,6 +37,7 @@
         self.host_app = host_app
         self.client_initialized = defer.Deferred()
         self.conn_deferred = defer.Deferred()
+        self.ignored = set()
 
     def getConnectionDeferred(self):
         """Return a deferred which fire when the client is connected"""
@@ -97,6 +98,20 @@
         self.host_app.bridge.disconnected(self.profile) #we send the signal to the clients
         self.host_app.purgeClient(self.profile) #and we remove references to this client
 
+    def ignore(self, entity_jid):
+        """Put entity in ignore list
+        @param entity_jid: jid of the entity to ignore"""
+        self.ignored.add(entity_jid)
+
+    def unignore(self, entity_jid):
+        """Remove an entity from ignore list
+        @param entity_jid: jid of the entity to ignore"""
+        self.ignored.discard(entity_jid)
+    
+    def isIgnored(self, entity_jid):
+        """Tell if an entity is in ignore
+        @param entity_jid: jid of the entity to ignore"""
+        return entity_jid in self.ignored
 
 class SatMessageProtocol(xmppim.MessageProtocol):
     
@@ -105,7 +120,12 @@
         self.host = host
 
     def onMessage(self, message):
-        debug (_(u"got message from: %s"), message["from"])
+        debug (_(u"got message from: %s") % message["from"])
+        
+        if self.parent.isIgnored(jid.JID(message["from"])):
+            info(_(u"%s is ignored, discarding the message") % message["from"])
+            return
+
         if not self.host.trigger.point("MessageReceived",message, profile=self.parent.profile):
             return
         for e in message.elements():