Mercurial > libervia-backend
changeset 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 | 908be289eb49 |
children | adcc35625e17 |
files | src/plugins/plugin_xep_0045.py |
diffstat | 1 files changed, 18 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0045.py Fri Jan 05 12:58:54 2018 +0100 +++ b/src/plugins/plugin_xep_0045.py Fri Jan 05 12:59:52 2018 +0100 @@ -88,6 +88,7 @@ host.bridge.addMethod("mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', method=self._getUniqueName) host.bridge.addMethod("mucConfigureRoom", ".plugin", in_sign='ss', out_sign='s', method=self._configureRoom, async=True) host.bridge.addMethod("mucGetDefaultService", ".plugin", in_sign='', out_sign='s', method=self.getDefaultMUC) + host.bridge.addMethod("mucGetService", ".plugin", in_sign='ss', out_sign='s', method=self._getMUCService, async=True) host.bridge.addSignal("mucRoomJoined", ".plugin", signature='sa{sa{ss}}sss') # args: room_jid, occupants, user_nick, subject, profile host.bridge.addSignal("mucRoomLeft", ".plugin", signature='ss') # args: room_jid, profile host.bridge.addSignal("mucRoomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile @@ -109,7 +110,7 @@ def profileConnected(self, client): def assign_service(service): client.muc_service = service - return self.getMUCService(profile=client.profile).addCallback(assign_service) + return self.getMUCService(client).addCallback(assign_service) def MessageReceivedTrigger(self, client, message_elt, post_treat): if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: @@ -359,15 +360,27 @@ self.checkRoomJoined(client, room_jid) return client._muc_client.joined_rooms[room_jid].inRoster(muc.User(nick)) + def _getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE): + client = self.host.getClient(profile) + d = self.getMUCService(client, jid_ or None) + d.addCallback(lambda service_jid: service_jid.full() if service_jid is not None else u'') + return d + @defer.inlineCallbacks - def getMUCService(self, jid_=None, profile=C.PROF_KEY_NONE): + def getMUCService(self, client, jid_=None): """Return first found MUC service of an entity @param jid_: entity which may have a MUC service, or None for our own server - @param profile: %(doc_profile)s + @return (jid.JID, None): found service jid or None """ - client = self.host.getClient(profile) - muc_service = None + if jid_ is None: + try: + muc_service = client.muc_service + except AttributeError: + pass + else: + # we have a cached value, we return it + defer.returnValue(muc_service) services = yield self.host.findServiceEntities(client, "conference", "text", jid_) for service in services: if ".irc." not in service.userhost():