Mercurial > libervia-backend
comparison src/memory/memory.py @ 1315:be3a301540c0 frontends_multi_profiles
core (memory): updateEntityData now accept a "silent" argument to avoid sending signal to frontends when updating an attribute with "signalOnUpdate" flag.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 09 Feb 2015 21:39:51 +0100 |
parents | bb9c32249778 |
children | 3a20312d4012 |
comparison
equal
deleted
inserted
replaced
1314:bb9c32249778 | 1315:be3a301540c0 |
---|---|
442 @param priority: priority | 442 @param priority: priority |
443 @param statuses: dictionary of statuses | 443 @param statuses: dictionary of statuses |
444 @param profile_key: %(doc_profile_key)s | 444 @param profile_key: %(doc_profile_key)s |
445 """ | 445 """ |
446 presence_data = PresenceTuple(show, priority, statuses) | 446 presence_data = PresenceTuple(show, priority, statuses) |
447 self.updateEntityData(entity_jid, "presence", presence_data, profile_key) | 447 self.updateEntityData(entity_jid, "presence", presence_data, profile_key=profile_key) |
448 if entity_jid.resource and show != C.PRESENCE_UNAVAILABLE: | 448 if entity_jid.resource and show != C.PRESENCE_UNAVAILABLE: |
449 # If a resource is available, bare jid should not have presence information | 449 # If a resource is available, bare jid should not have presence information |
450 try: | 450 try: |
451 self.delEntityDatum(entity_jid.userhostJID(), "presence", profile_key) | 451 self.delEntityDatum(entity_jid.userhostJID(), "presence", profile_key) |
452 except (KeyError, exceptions.UnknownEntityError): | 452 except (KeyError, exceptions.UnknownEntityError): |
578 continue | 578 continue |
579 full_jid = copy.copy(bare_jid) | 579 full_jid = copy.copy(bare_jid) |
580 full_jid.resource = resource | 580 full_jid.resource = resource |
581 yield full_jid | 581 yield full_jid |
582 | 582 |
583 def updateEntityData(self, entity_jid, key, value, profile_key): | 583 def updateEntityData(self, entity_jid, key, value, silent=False, profile_key=C.PROF_KEY_NONE): |
584 """Set a misc data for an entity | 584 """Set a misc data for an entity |
585 | 585 |
586 If key was registered with setSignalOnUpdate, a signal will be sent to frontends | 586 If key was registered with setSignalOnUpdate, a signal will be sent to frontends |
587 @param entity_jid: JID of the entity, C.ENTITY_ALL_RESOURCES for all resources of all entities, | 587 @param entity_jid: JID of the entity, C.ENTITY_ALL_RESOURCES for all resources of all entities, |
588 C.ENTITY_ALL for all entities (all resources + bare jids) | 588 C.ENTITY_ALL for all entities (all resources + bare jids) |
589 @param key: key to set (eg: "type") | 589 @param key: key to set (eg: "type") |
590 @param value: value for this key (eg: "chatroom") | 590 @param value: value for this key (eg: "chatroom") |
591 @param silent(bool): if True, doesn't send signal to frontend, even there is a signal flag (see setSignalOnUpdate) | |
591 @param profile_key: %(doc_profile_key)s | 592 @param profile_key: %(doc_profile_key)s |
592 """ | 593 """ |
593 profile_cache = self._getProfileCache(profile_key) | 594 profile_cache = self._getProfileCache(profile_key) |
594 if entity_jid in (C.ENTITY_ALL_RESOURCES, C.ENTITY_ALL): | 595 if entity_jid in (C.ENTITY_ALL_RESOURCES, C.ENTITY_ALL): |
595 entities = self.getAllEntitiesIter(entity_jid==C.ENTITY_ALL, profile_key) | 596 entities = self.getAllEntitiesIter(entity_jid==C.ENTITY_ALL, profile_key) |
598 | 599 |
599 for jid_ in entities: | 600 for jid_ in entities: |
600 entity_data = profile_cache.setdefault(jid_.userhostJID(),{}).setdefault(jid_.resource, {}) | 601 entity_data = profile_cache.setdefault(jid_.userhostJID(),{}).setdefault(jid_.resource, {}) |
601 | 602 |
602 entity_data[key] = value | 603 entity_data[key] = value |
603 if key in self._key_signals: | 604 if key in self._key_signals and not silent: |
604 if not isinstance(value, basestring): | 605 if not isinstance(value, basestring): |
605 log.error(u"Setting a non string value ({}) for a key ({}) which has a signal flag".format(value, key)) | 606 log.error(u"Setting a non string value ({}) for a key ({}) which has a signal flag".format(value, key)) |
606 else: | 607 else: |
607 self.host.bridge.entityDataUpdated(jid_.full(), key, value, self.getProfileName(profile_key)) | 608 self.host.bridge.entityDataUpdated(jid_.full(), key, value, self.getProfileName(profile_key)) |
608 | 609 |