comparison sat/plugins/plugin_xep_0085.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 dcebc585c29f
children 524856bd7b19
comparison
equal deleted inserted replaced
3253:1af840e84af7 3254:6cf4bd6972c2
143 143
144 @param entity_jid: contact's JID, or C.ENTITY_ALL to update all contacts. 144 @param entity_jid: contact's JID, or C.ENTITY_ALL to update all contacts.
145 @param value: True, False or DELETE_VALUE to delete the entity data 145 @param value: True, False or DELETE_VALUE to delete the entity data
146 @param profile: current profile 146 @param profile: current profile
147 """ 147 """
148 client = self.host.getClient(profile)
148 if value == DELETE_VALUE: 149 if value == DELETE_VALUE:
149 self.host.memory.delEntityDatum(entity_jid, ENTITY_KEY, profile) 150 self.host.memory.delEntityDatum(client, entity_jid, ENTITY_KEY)
150 else: 151 else:
151 self.host.memory.updateEntityData( 152 self.host.memory.updateEntityData(
152 entity_jid, ENTITY_KEY, value, profile_key=profile 153 client, entity_jid, ENTITY_KEY, value
153 ) 154 )
154 if not value or value == DELETE_VALUE: 155 if not value or value == DELETE_VALUE:
155 # reinit chat state UI for this or these contact(s) 156 # reinit chat state UI for this or these contact(s)
156 self.host.bridge.chatStateReceived(entity_jid.full(), "", profile) 157 self.host.bridge.chatStateReceived(entity_jid.full(), "", profile)
157 158
254 255
255 @param to_jid (JID): full or bare JID to check 256 @param to_jid (JID): full or bare JID to check
256 @param profile (str): %(doc_profile)s 257 @param profile (str): %(doc_profile)s
257 @return: bool 258 @return: bool
258 """ 259 """
260 client = self.host.getClient(profile)
259 try: 261 try:
260 type_ = self.host.memory.getEntityDatum( 262 type_ = self.host.memory.getEntityDatum(
261 to_jid.userhostJID(), C.ENTITY_TYPE, profile) 263 client, to_jid.userhostJID(), C.ENTITY_TYPE)
262 if type_ == C.ENTITY_TYPE_MUC: 264 if type_ == C.ENTITY_TYPE_MUC:
263 return True 265 return True
264 except (exceptions.UnknownEntityError, KeyError): 266 except (exceptions.UnknownEntityError, KeyError):
265 pass 267 pass
266 return False 268 return False
271 @param forceEntityData: if set to True, a non-existing 273 @param forceEntityData: if set to True, a non-existing
272 entity data will be considered to be True (and initialized) 274 entity data will be considered to be True (and initialized)
273 @param: current profile 275 @param: current profile
274 @return: True if the notifications should be sent to this JID. 276 @return: True if the notifications should be sent to this JID.
275 """ 277 """
278 client = self.host.getClient(profile)
276 # check if the parameter is active 279 # check if the parameter is active
277 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile): 280 if not self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile):
278 return False 281 return False
279 # check if notifications should be sent to this contact 282 # check if notifications should be sent to this contact
280 if self._isMUC(to_jid, profile): 283 if self._isMUC(to_jid, profile):
281 return True 284 return True
282 # FIXME: this assertion crash when we want to send a message to an online bare jid 285 # FIXME: this assertion crash when we want to send a message to an online bare jid
283 # assert to_jid.resource or not self.host.memory.isEntityAvailable(to_jid, profile) # must either have a resource, or talk to an offline contact 286 # assert to_jid.resource or not self.host.memory.isEntityAvailable(to_jid, profile) # must either have a resource, or talk to an offline contact
284 try: 287 try:
285 return self.host.memory.getEntityDatum(to_jid, ENTITY_KEY, profile) 288 return self.host.memory.getEntityDatum(client, to_jid, ENTITY_KEY)
286 except (exceptions.UnknownEntityError, KeyError): 289 except (exceptions.UnknownEntityError, KeyError):
287 if forceEntityData: 290 if forceEntityData:
288 # enable it for the first time 291 # enable it for the first time
289 self.updateCache(to_jid, True, profile=profile) 292 self.updateCache(to_jid, True, profile=profile)
290 return True 293 return True