Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0045.py @ 3101:ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
room statuses are now sent with other metadata on bridge signals, and saved in Room
instance. They give useful data on the room, for instance they can be used to know if a
full jid is used in this room.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 30 Dec 2019 20:44:02 +0100 |
parents | 13be04a70e2f |
children | 9d0df638c8b4 |
comparison
equal
deleted
inserted
replaced
3100:cea52c9ddfd9 | 3101:ab7e8ade848a |
---|---|
90 self.host = host | 90 self.host = host |
91 self._sessions = memory.Sessions() | 91 self._sessions = memory.Sessions() |
92 # return same arguments as mucRoomJoined + a boolean set to True is the room was | 92 # return same arguments as mucRoomJoined + a boolean set to True is the room was |
93 # already joined (first argument) | 93 # already joined (first argument) |
94 host.bridge.addMethod( | 94 host.bridge.addMethod( |
95 "mucJoin", ".plugin", in_sign='ssa{ss}s', out_sign='(bsa{sa{ss}}sss)', | 95 "mucJoin", ".plugin", in_sign='ssa{ss}s', out_sign='(bsa{sa{ss}}ssass)', |
96 method=self._join, async_=True) | 96 method=self._join, async_=True) |
97 host.bridge.addMethod( | 97 host.bridge.addMethod( |
98 "mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick) | 98 "mucNick", ".plugin", in_sign='sss', out_sign='', method=self._nick) |
99 host.bridge.addMethod( | 99 host.bridge.addMethod( |
100 "mucNickGet", ".plugin", in_sign='ss', out_sign='s', method=self._getRoomNick) | 100 "mucNickGet", ".plugin", in_sign='ss', out_sign='s', method=self._getRoomNick) |
105 "mucOccupantsGet", ".plugin", in_sign='ss', out_sign='a{sa{ss}}', | 105 "mucOccupantsGet", ".plugin", in_sign='ss', out_sign='a{sa{ss}}', |
106 method=self._getRoomOccupants) | 106 method=self._getRoomOccupants) |
107 host.bridge.addMethod( | 107 host.bridge.addMethod( |
108 "mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) | 108 "mucSubject", ".plugin", in_sign='sss', out_sign='', method=self._subject) |
109 host.bridge.addMethod( | 109 host.bridge.addMethod( |
110 "mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ss)', | 110 "mucGetRoomsJoined", ".plugin", in_sign='s', out_sign='a(sa{sa{ss}}ssas)', |
111 method=self._getRoomsJoined) | 111 method=self._getRoomsJoined) |
112 host.bridge.addMethod( | 112 host.bridge.addMethod( |
113 "mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', | 113 "mucGetUniqueRoomName", ".plugin", in_sign='ss', out_sign='s', |
114 method=self._getUniqueName) | 114 method=self._getUniqueName) |
115 host.bridge.addMethod( | 115 host.bridge.addMethod( |
126 # args: room_jid, profile | 126 # args: room_jid, profile |
127 host.bridge.addSignal( | 127 host.bridge.addSignal( |
128 "mucRoomPrepareJoin", ".plugin", signature='ss') | 128 "mucRoomPrepareJoin", ".plugin", signature='ss') |
129 # args: room_jid, occupants, user_nick, subject, profile | 129 # args: room_jid, occupants, user_nick, subject, profile |
130 host.bridge.addSignal( | 130 host.bridge.addSignal( |
131 "mucRoomJoined", ".plugin", signature='sa{sa{ss}}sss') | 131 "mucRoomJoined", ".plugin", signature='sa{sa{ss}}ssass') |
132 # args: room_jid, profile | 132 # args: room_jid, profile |
133 host.bridge.addSignal( | 133 host.bridge.addSignal( |
134 "mucRoomLeft", ".plugin", signature='ss') | 134 "mucRoomLeft", ".plugin", signature='ss') |
135 # args: room_jid, old_nick, new_nick, profile | 135 # args: room_jid, old_nick, new_nick, profile |
136 host.bridge.addSignal( | 136 host.bridge.addSignal( |
239 return [ | 239 return [ |
240 room.roomJID.userhost(), | 240 room.roomJID.userhost(), |
241 XEP_0045._getOccupants(room), | 241 XEP_0045._getOccupants(room), |
242 room.nick, | 242 room.nick, |
243 room.subject, | 243 room.subject, |
244 [s.name for s in room.statuses], | |
244 profile | 245 profile |
245 ] | 246 ] |
246 | 247 |
247 def _UIRoomJoinCb(self, data, profile): | 248 def _UIRoomJoinCb(self, data, profile): |
248 room_jid = jid.JID(data['index']) | 249 room_jid = jid.JID(data['index']) |
329 def getRoomsJoined(self, client): | 330 def getRoomsJoined(self, client): |
330 """Return rooms where user is""" | 331 """Return rooms where user is""" |
331 result = [] | 332 result = [] |
332 for room in list(client._muc_client.joined_rooms.values()): | 333 for room in list(client._muc_client.joined_rooms.values()): |
333 if room.state == ROOM_STATE_LIVE: | 334 if room.state == ROOM_STATE_LIVE: |
334 result.append((room.roomJID.userhost(), self._getOccupants(room), room.nick, room.subject)) | 335 result.append( |
336 (room.roomJID.userhost(), | |
337 self._getOccupants(room), | |
338 room.nick, | |
339 room.subject, | |
340 [s.name for s in room.statuses], | |
341 ) | |
342 ) | |
335 return result | 343 return result |
336 | 344 |
337 def _getRoomNick(self, room_jid_s, profile_key=C.PROF_KEY_NONE): | 345 def _getRoomNick(self, room_jid_s, profile_key=C.PROF_KEY_NONE): |
338 client = self.host.getClient(profile_key) | 346 client = self.host.getClient(profile_key) |
339 return self.getRoomNick(client, jid.JID(room_jid_s)) | 347 return self.getRoomNick(client, jid.JID(room_jid_s)) |
1084 if not nick: | 1092 if not nick: |
1085 log.warning(_("missing nick in presence: {xml}").format( | 1093 log.warning(_("missing nick in presence: {xml}").format( |
1086 xml = presence.toElement().toXml())) | 1094 xml = presence.toElement().toXml())) |
1087 return | 1095 return |
1088 user = muc.User(nick, presence.entity) | 1096 user = muc.User(nick, presence.entity) |
1097 | |
1098 # we want to keep statuses with room | |
1099 # XXX: presence if broadcasted, and we won't have status code | |
1100 # like 110 (REALJID_PUBLIC) after first <presence/> received | |
1101 # so we keep only the initial <presence> (with SELF_PRESENCE), | |
1102 # thus we check if attribute already exists | |
1103 if (not hasattr(room, 'statuses') | |
1104 and muc.STATUS_CODE.SELF_PRESENCE in presence.mucStatuses): | |
1105 room.statuses = presence.mucStatuses | |
1089 | 1106 |
1090 # Update user data | 1107 # Update user data |
1091 user.role = presence.role | 1108 user.role = presence.role |
1092 user.affiliation = presence.affiliation | 1109 user.affiliation = presence.affiliation |
1093 user.status = presence.status | 1110 user.status = presence.status |