comparison src/plugins/plugin_xep_0045.py @ 1239:b6dbac8ee485

plugin XEP-0045: handle MUC presence
author souliane <souliane@mailoo.org>
date Fri, 17 Oct 2014 15:49:46 +0200
parents 96fb74a4714d
children 1f0ae61536aa
comparison
equal deleted inserted replaced
1238:ff58a49a7022 1239:b6dbac8ee485
26 26
27 from sat.core import exceptions 27 from sat.core import exceptions
28 from sat.memory import memory 28 from sat.memory import memory
29 29
30 import uuid 30 import uuid
31 import copy
31 32
32 from wokkel import muc 33 from wokkel import muc
33 from sat.tools import xml_tools 34 from sat.tools import xml_tools
34 35
35 36
83 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) 84 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
84 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100) 85 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100)
85 except KeyError: 86 except KeyError:
86 log.info(_("Text commands not available")) 87 log.info(_("Text commands not available"))
87 88
89 host.trigger.add("presence_available", self.presenceTrigger)
90
88 def profileConnected(self, profile): 91 def profileConnected(self, profile):
89 def assign_service(service): 92 def assign_service(service):
90 client = self.host.getClient(profile) 93 client = self.host.getClient(profile)
91 client.muc_service = service 94 client.muc_service = service
92 return self.getMUCService(profile_key=profile).addCallback(assign_service) 95 return self.getMUCService(profile_key=profile).addCallback(assign_service)
637 if user.status: 640 if user.status:
638 whois_msg.append(_("Status: %s") % user.status) 641 whois_msg.append(_("Status: %s") % user.status)
639 if user.show: 642 if user.show:
640 whois_msg.append(_("Show: %s") % user.show) 643 whois_msg.append(_("Show: %s") % user.show)
641 644
645 def presenceTrigger(self, presence_elt, client):
646 # XXX: shouldn't it be done by the server ?!!
647 muc_client = self.clients[client.profile]
648 for room_jid_s, room in muc_client.joined_rooms.items():
649 elt = copy.deepcopy(presence_elt)
650 elt['to'] = room_jid_s + '/' + room.nick
651 client.presence.send(elt)
652 return True
653
642 654
643 class SatMUCClient (muc.MUCClient): 655 class SatMUCClient (muc.MUCClient):
644 #implements(iwokkel.IDisco) 656 #implements(iwokkel.IDisco)
645 657
646 def __init__(self, plugin_parent): 658 def __init__(self, plugin_parent):
710 722
711 def userChangedNick(self, room, user, new_nick): 723 def userChangedNick(self, room, user, new_nick):
712 self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile) 724 self.host.bridge.roomUserChangedNick(room.roomJID.userhost(), user.nick, new_nick, self.parent.profile)
713 725
714 def userUpdatedStatus(self, room, user, show, status): 726 def userUpdatedStatus(self, room, user, show, status):
715 print("FIXME: MUC status not managed yet") 727 self.host.bridge.presenceUpdate(room.roomJID.userhost() + '/' + user.nick, show or '', 0, {'default': status or ''}, self.parent.profile)
716 #FIXME:
717 728
718 def receivedSubject(self, room, user, subject): 729 def receivedSubject(self, room, user, subject):
719 log.debug(_("New subject for room (%(room_id)s): %(subject)s") % {'room_id': room.roomJID.full(), 'subject': subject}) 730 log.debug(_("New subject for room (%(room_id)s): %(subject)s") % {'room_id': room.roomJID.full(), 'subject': subject})
720 self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject) 731 self.rec_subjects[room.roomJID.userhost()] = (room.roomJID.userhost(), subject)
721 self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile) 732 self.host.bridge.roomNewSubject(room.roomJID.userhost(), subject, self.parent.profile)