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`
This commit is contained in:
Goffi 2020-04-14 21:00:33 +02:00
commit 88072e0453

View file

@ -60,7 +60,7 @@ class XEP_0115(object):
host.trigger.add("Presence send", self._presenceTrigger)
def getHandler(self, client):
return XEP_0115_handler(self, client.profile)
return XEP_0115_handler(self)
@defer.inlineCallbacks
def _prepareCaps(self, client):
@ -97,7 +97,7 @@ class XEP_0115(object):
if cap_hash not in self.host.memory.disco.hashes:
self.host.memory.disco.hashes[cap_hash] = disco_infos
self.host.memory.updateEntityData(
client.jid, C.ENTITY_CAP_HASH, cap_hash, profile_key=client.profile
client, client.jid, C.ENTITY_CAP_HASH, cap_hash
)
def _presenceAddElt(self, client, obj):
@ -118,10 +118,13 @@ class XEP_0115(object):
@implementer(iwokkel.IDisco)
class XEP_0115_handler(XMPPHandler):
def __init__(self, plugin_parent, profile):
def __init__(self, plugin_parent):
self.plugin_parent = plugin_parent
self.host = plugin_parent.host
self.profile = profile
@property
def client(self):
return self.parent
def connectionInitialized(self):
self.xmlstream.addObserver(CAPABILITY_UPDATE, self.update)
@ -158,7 +161,7 @@ class XEP_0115_handler(XMPPHandler):
% {"hash": c_ver, "jid": from_jid.full()}
)
self.host.memory.updateEntityData(
from_jid, C.ENTITY_CAP_HASH, c_ver, profile_key=self.profile
self.client, from_jid, C.ENTITY_CAP_HASH, c_ver
)
return
@ -173,7 +176,7 @@ class XEP_0115_handler(XMPPHandler):
def cb(__):
computed_hash = self.host.memory.getEntityDatum(
from_jid, C.ENTITY_CAP_HASH, self.profile
self.client, from_jid, C.ENTITY_CAP_HASH
)
if computed_hash != c_ver:
log.warning(