Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0115.py @ 3254:6cf4bd6972c2
core, frontends: avatar refactoring:
/!\ huge commit
Avatar logic has been reworked around the IDENTITY plugin: plugins able to handle avatar
or other identity related metadata (like nicknames) register to IDENTITY plugin in the
same way as for other features like download/upload. Once registered, IDENTITY plugin will
call them when suitable in order of priority, and handle caching.
Methods to manage those metadata from frontend now use serialised data.
For now `avatar` and `nicknames` are handled:
- `avatar` is now a dict with `path` + metadata like `media_type`, instead of just a string
path
- `nicknames` is now a list of nicknames in order of priority. This list is never empty,
and `nicknames[0]` should be the preferred nickname to use by frontends in most cases.
In addition to contact specified nicknames, user set nickname (the one set in roster) is
used in priority when available.
Among the side changes done with this commit, there are:
- a new `contactGet` bridge method to get roster metadata for a single contact
- SatPresenceProtocol.send returns a Deferred to check when it has actually been sent
- memory's methods to handle entities data now use `client` as first argument
- metadata filter can be specified with `getIdentity`
- `getAvatar` and `setAvatar` are now part of the IDENTITY plugin instead of XEP-0054 (and
there signature has changed)
- `isRoom` and `getBareOrFull` are now part of XEP-0045 plugin
- jp avatar/get command uses `xdg-open` first when available for `--show` flag
- `--no-cache` has been added to jp avatar/get and identity/get
- jp identity/set has been simplified, explicit options (`--nickname` only for now) are
used instead of `--field`. `--field` may come back in the future if necessary for extra
data.
- QuickContactList `SetContact` now handle None as a value, and doesn't use it to delete the
metadata anymore
- improved cache handling for `metadata` and `nicknames` in quick frontend
- new `default` argument in QuickContactList `getCache`
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 14 Apr 2020 21:00:33 +0200 |
parents | 559a625a236b |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3253:1af840e84af7 | 3254:6cf4bd6972c2 |
---|---|
58 log.info(_("Plugin XEP_0115 initialization")) | 58 log.info(_("Plugin XEP_0115 initialization")) |
59 self.host = host | 59 self.host = host |
60 host.trigger.add("Presence send", self._presenceTrigger) | 60 host.trigger.add("Presence send", self._presenceTrigger) |
61 | 61 |
62 def getHandler(self, client): | 62 def getHandler(self, client): |
63 return XEP_0115_handler(self, client.profile) | 63 return XEP_0115_handler(self) |
64 | 64 |
65 @defer.inlineCallbacks | 65 @defer.inlineCallbacks |
66 def _prepareCaps(self, client): | 66 def _prepareCaps(self, client): |
67 # we have to calculate hash for client | 67 # we have to calculate hash for client |
68 # because disco infos/identities may change between clients | 68 # because disco infos/identities may change between clients |
95 if client._caps_optimize: | 95 if client._caps_optimize: |
96 client._caps_sent = False | 96 client._caps_sent = False |
97 if cap_hash not in self.host.memory.disco.hashes: | 97 if cap_hash not in self.host.memory.disco.hashes: |
98 self.host.memory.disco.hashes[cap_hash] = disco_infos | 98 self.host.memory.disco.hashes[cap_hash] = disco_infos |
99 self.host.memory.updateEntityData( | 99 self.host.memory.updateEntityData( |
100 client.jid, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile | 100 client, client.jid, C.ENTITY_CAP_HASH, cap_hash |
101 ) | 101 ) |
102 | 102 |
103 def _presenceAddElt(self, client, obj): | 103 def _presenceAddElt(self, client, obj): |
104 if client._caps_optimize: | 104 if client._caps_optimize: |
105 if client._caps_sent: | 105 if client._caps_sent: |
116 | 116 |
117 | 117 |
118 @implementer(iwokkel.IDisco) | 118 @implementer(iwokkel.IDisco) |
119 class XEP_0115_handler(XMPPHandler): | 119 class XEP_0115_handler(XMPPHandler): |
120 | 120 |
121 def __init__(self, plugin_parent, profile): | 121 def __init__(self, plugin_parent): |
122 self.plugin_parent = plugin_parent | 122 self.plugin_parent = plugin_parent |
123 self.host = plugin_parent.host | 123 self.host = plugin_parent.host |
124 self.profile = profile | 124 |
125 @property | |
126 def client(self): | |
127 return self.parent | |
125 | 128 |
126 def connectionInitialized(self): | 129 def connectionInitialized(self): |
127 self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update) | 130 self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update) |
128 | 131 |
129 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): | 132 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
156 log.debug( | 159 log.debug( |
157 "hash [%(hash)s] already in cache, updating entity [%(jid)s]" | 160 "hash [%(hash)s] already in cache, updating entity [%(jid)s]" |
158 % {"hash": c_ver, "jid": from_jid.full()} | 161 % {"hash": c_ver, "jid": from_jid.full()} |
159 ) | 162 ) |
160 self.host.memory.updateEntityData( | 163 self.host.memory.updateEntityData( |
161 from_jid, C.ENTITY_CAP_HASH, c_ver, profile_key=self.profile | 164 self.client, from_jid, C.ENTITY_CAP_HASH, c_ver |
162 ) | 165 ) |
163 return | 166 return |
164 | 167 |
165 if c_hash != "sha-1": # unknown hash method | 168 if c_hash != "sha-1": # unknown hash method |
166 log.warning( | 169 log.warning( |
171 .format(hash_method = c_hash, entity_jid = from_jid, node = c_node) | 174 .format(hash_method = c_hash, entity_jid = from_jid, node = c_node) |
172 ) | 175 ) |
173 | 176 |
174 def cb(__): | 177 def cb(__): |
175 computed_hash = self.host.memory.getEntityDatum( | 178 computed_hash = self.host.memory.getEntityDatum( |
176 from_jid, C.ENTITY_CAP_HASH, self.profile | 179 self.client, from_jid, C.ENTITY_CAP_HASH |
177 ) | 180 ) |
178 if computed_hash != c_ver: | 181 if computed_hash != c_ver: |
179 log.warning( | 182 log.warning( |
180 _( | 183 _( |
181 "Computed hash differ from given hash:\n" | 184 "Computed hash differ from given hash:\n" |