comparison src/plugins/plugin_xep_0045.py @ 2468:8f14c1865e9e

plugin XEP-0045: new mucGetService bridge method to retrieve MUC service of the server.
author Goffi <goffi@goffi.org>
date Fri, 05 Jan 2018 12:59:52 +0100
parents 34cb8b713370
children 0046283a285d
comparison
equal deleted inserted replaced
2467:908be289eb49 2468:8f14c1865e9e
86 host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) 86 host.bridge.addMethod("mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject)
87 host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined) 87 host.bridge.addMethod("mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', method=self._getRoomsJoined)
88 host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) 88 host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName)
89 host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True) 89 host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True)
90 host.bridge.addMethod("mucGetDefaultService", ".plugin", in_sign='', out_sign='s', method=self.getDefaultMUC) 90 host.bridge.addMethod("mucGetDefaultService", ".plugin", in_sign='', out_sign='s', method=self.getDefaultMUC)
91 host.bridge.addMethod("mucGetService", ".plugin", in_sign='ss', out_sign='s', method=self._getMUCService, async=True)
91 host.bridge.addSignal("mucRoomJoined", ".plugin", signature='sa{sa{ss}}sss') # args: room_jid, occupants, user_nick, subject, profile 92 host.bridge.addSignal("mucRoomJoined", ".plugin", signature='sa{sa{ss}}sss') # args: room_jid, occupants, user_nick, subject, profile
92 host.bridge.addSignal("mucRoomLeft", ".plugin", signature='ss') # args: room_jid, profile 93 host.bridge.addSignal("mucRoomLeft", ".plugin", signature='ss') # args: room_jid, profile
93 host.bridge.addSignal("mucRoomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile 94 host.bridge.addSignal("mucRoomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile
94 host.bridge.addSignal("mucRoomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile 95 host.bridge.addSignal("mucRoomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile
95 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True) 96 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True)
107 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=1000000) 108 host.trigger.add("MessageReceived", self.MessageReceivedTrigger, priority=1000000)
108 109
109 def profileConnected(self, client): 110 def profileConnected(self, client):
110 def assign_service(service): 111 def assign_service(service):
111 client.muc_service = service 112 client.muc_service = service
112 return self.getMUCService(profile=client.profile).addCallback(assign_service) 113 return self.getMUCService(client).addCallback(assign_service)
113 114
114 def MessageReceivedTrigger(self, client, message_elt, post_treat): 115 def MessageReceivedTrigger(self, client, message_elt, post_treat):
115 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: 116 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT:
116 if message_elt.subject or message_elt.delay: 117 if message_elt.subject or message_elt.delay:
117 return False 118 return False
357 def isNickInRoom(self, client, room_jid, nick): 358 def isNickInRoom(self, client, room_jid, nick):
358 """Tell if a nick is currently present in a room""" 359 """Tell if a nick is currently present in a room"""
359 self.checkRoomJoined(client, room_jid) 360 self.checkRoomJoined(client, room_jid)
360 return client._muc_client.joined_rooms[room_jid].inRoster(muc.User(nick)) 361 return client._muc_client.joined_rooms[room_jid].inRoster(muc.User(nick))
361 362
363 def _getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE):
364 client = self.host.getClient(profile)
365 d = self.getMUCService(client, jid_ or None)
366 d.addCallback(lambda service_jid: service_jid.full() if service_jid is not None else u'')
367 return d
368
362 @defer.inlineCallbacks 369 @defer.inlineCallbacks
363 def getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE): 370 def getMUCService(self, client, jid_=None):
364 """Return first found MUC service of an entity 371 """Return first found MUC service of an entity
365 372
366 @param jid_: entity which may have a MUC service, or None for our own server 373 @param jid_: entity which may have a MUC service, or None for our own server
367 @param profile: %(doc_profile)s 374 @return (jid.JID, None): found service jid or None
368 """ 375 """
369 client = self.host.getClient(profile) 376 if jid_ is None:
370 muc_service = None 377 try:
378 muc_service = client.muc_service
379 except AttributeError:
380 pass
381 else:
382 # we have a cached value, we return it
383 defer.returnValue(muc_service)
371 services = yield self.host.findServiceEntities(client, "conference", "text", jid_) 384 services = yield self.host.findServiceEntities(client, "conference", "text", jid_)
372 for service in services: 385 for service in services:
373 if ".irc." not in service.userhost(): 386 if ".irc." not in service.userhost():
374 # FIXME: 387 # FIXME:
375 # This ugly hack is here to avoid an issue with openfire: the IRC gateway 388 # This ugly hack is here to avoid an issue with openfire: the IRC gateway