changeset 1239:b6dbac8ee485

plugin XEP-0045: handle MUC presence
author souliane <souliane@mailoo.org>
date Fri, 17 Oct 2014 15:49:46 +0200
parents ff58a49a7022
children 22adf1eb59f5
files src/plugins/plugin_xep_0045.py
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py	Thu Oct 16 17:02:44 2014 +0200
+++ b/src/plugins/plugin_xep_0045.py	Fri Oct 17 15:49:46 2014 +0200
@@ -28,6 +28,7 @@
 from sat.memory import memory
 
 import uuid
+import copy
 
 from wokkel import muc
 from sat.tools import xml_tools
@@ -85,6 +86,8 @@
         except KeyError:
             log.info(_("Text commands not available"))
 
+        host.trigger.add("presence_available", self.presenceTrigger)
+
     def profileConnected(self, profile):
         def assign_service(service):
             client = self.host.getClient(profile)
@@ -639,6 +642,15 @@
         if user.show:
             whois_msg.append(_("Show: %s") % user.show)
 
+    def presenceTrigger(self, presence_elt, client):
+        # XXX: shouldn't it be done by the server ?!!
+        muc_client = self.clients[client.profile]
+        for room_jid_s, room in muc_client.joined_rooms.items():
+            elt = copy.deepcopy(presence_elt)
+            elt['to'] = room_jid_s + '/' + room.nick
+            client.presence.send(elt)
+        return True
+
 
 class SatMUCClient (muc.MUCClient):
     #implements(iwokkel.IDisco)
@@ -712,8 +724,7 @@
         self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile)
 
     def userUpdatedStatus(self, room, user, show, status):
-        print("FIXME: MUC status not managed yet")
-        #FIXME:
+        self.host.bridge.presenceUpdate(room.roomJID.userhost() + '/' + user.nick, show or '', 0, {'default': status or ''}, self.parent.profile)
 
     def receivedSubject(self, room, user, subject):
         log.debug(_("New subject for room (%(room_id)s): %(subject)s") % {'room_id': room.roomJID.full(), 'subject': subject})