comparison sat/memory/disco.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 e4d3ba75b1b2
children be6d91572633
comparison
equal deleted inserted replaced
3253:1af840e84af7 3254:6cf4bd6972c2
175 try: 175 try:
176 if not use_cache: 176 if not use_cache:
177 # we ignore cache, so we pretend we haven't found it 177 # we ignore cache, so we pretend we haven't found it
178 raise KeyError 178 raise KeyError
179 cap_hash = self.host.memory.getEntityData( 179 cap_hash = self.host.memory.getEntityData(
180 jid_, [C.ENTITY_CAP_HASH], client.profile 180 client, jid_, [C.ENTITY_CAP_HASH]
181 )[C.ENTITY_CAP_HASH] 181 )[C.ENTITY_CAP_HASH]
182 except (KeyError, exceptions.UnknownEntityError): 182 except (KeyError, exceptions.UnknownEntityError):
183 # capability hash is not available, we'll compute one 183 # capability hash is not available, we'll compute one
184 def infosCb(disco_infos): 184 def infosCb(disco_infos):
185 cap_hash = self.generateHash(disco_infos) 185 cap_hash = self.generateHash(disco_infos)
189 # the hash has been generated (str value is needed to compute the 189 # the hash has been generated (str value is needed to compute the
190 # hash) 190 # hash)
191 ext_form.typeCheck() 191 ext_form.typeCheck()
192 self.hashes[cap_hash] = disco_infos 192 self.hashes[cap_hash] = disco_infos
193 self.host.memory.updateEntityData( 193 self.host.memory.updateEntityData(
194 jid_, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile 194 client, jid_, C.ENTITY_CAP_HASH, cap_hash
195 ) 195 )
196 return disco_infos 196 return disco_infos
197 197
198 def infosEb(fail): 198 def infosEb(fail):
199 if fail.check(defer.CancelledError): 199 if fail.check(defer.CancelledError):
212 ) 212 )
213 213
214 # XXX we set empty disco in cache, to avoid getting an error or waiting 214 # XXX we set empty disco in cache, to avoid getting an error or waiting
215 # for a timeout again the next time 215 # for a timeout again the next time
216 self.host.memory.updateEntityData( 216 self.host.memory.updateEntityData(
217 jid_, C.ENTITY_CAP_HASH, CAP_HASH_ERROR, profile_key=client.profile 217 client, jid_, C.ENTITY_CAP_HASH, CAP_HASH_ERROR
218 ) 218 )
219 raise fail 219 raise fail
220 220
221 d = client.disco.requestInfo(jid_, nodeIdentifier=node) 221 d = client.disco.requestInfo(jid_, nodeIdentifier=node)
222 d.addCallback(infosCb) 222 d.addCallback(infosCb)
241 241
242 if jid_ == server_jid and not node: 242 if jid_ == server_jid and not node:
243 # we cache items only for our own server and if node is not set 243 # we cache items only for our own server and if node is not set
244 try: 244 try:
245 items = self.host.memory.getEntityData( 245 items = self.host.memory.getEntityData(
246 jid_, ["DISCO_ITEMS"], client.profile 246 client, jid_, ["DISCO_ITEMS"]
247 )["DISCO_ITEMS"] 247 )["DISCO_ITEMS"]
248 log.debug("[%s] disco items are in cache" % jid_.full()) 248 log.debug("[%s] disco items are in cache" % jid_.full())
249 if not use_cache: 249 if not use_cache:
250 # we ignore cache, so we pretend we haven't found it 250 # we ignore cache, so we pretend we haven't found it
251 raise KeyError 251 raise KeyError
252 except (KeyError, exceptions.UnknownEntityError): 252 except (KeyError, exceptions.UnknownEntityError):
253 log.debug("Caching [%s] disco items" % jid_.full()) 253 log.debug("Caching [%s] disco items" % jid_.full())
254 items = yield client.disco.requestItems(jid_, nodeIdentifier=node) 254 items = yield client.disco.requestItems(jid_, nodeIdentifier=node)
255 self.host.memory.updateEntityData( 255 self.host.memory.updateEntityData(
256 jid_, "DISCO_ITEMS", items, profile_key=client.profile 256 client, jid_, "DISCO_ITEMS", items
257 ) 257 )
258 else: 258 else:
259 try: 259 try:
260 items = yield client.disco.requestItems(jid_, nodeIdentifier=node) 260 items = yield client.disco.requestItems(jid_, nodeIdentifier=node)
261 except StanzaError as e: 261 except StanzaError as e: