comparison sat_pubsub/pgsql_storage.py @ 463:f520ac3164b0

privilege: improvment on last message sending on presence with `+notify`: - local entities subscribed to the presence of an other local entity which is connecting are now added to presence map. This helps getting their notification even if they didn't connect recently - nodes with `presence` access model are now also used for `+notify` - notifications are not sent anymore in case of status change if the resource was already present.
author Goffi <goffi@goffi.org>
date Fri, 15 Oct 2021 13:40:56 +0200
parents 7c9792f934a2
children 0d38c3529972
comparison
equal deleted inserted replaced
462:a017af61a32b 463:f520ac3164b0
453 last_items.append((pep_jid, node, item, item_access_model)) 453 last_items.append((pep_jid, node, item, item_access_model))
454 return last_items 454 return last_items
455 455
456 def getLastItems(self, entities, nodes, node_accesses, item_accesses, pep): 456 def getLastItems(self, entities, nodes, node_accesses, item_accesses, pep):
457 """get last item for several nodes and entities in a single request""" 457 """get last item for several nodes and entities in a single request"""
458 # TODO: manage other access model (whitelist, …)
458 if not entities or not nodes or not node_accesses or not item_accesses: 459 if not entities or not nodes or not node_accesses or not item_accesses:
459 raise BadRequest(text="entities, nodes and accesses must not be empty") 460 raise BadRequest(text="entities, nodes and accesses must not be empty")
460 if node_accesses != ('open',) or item_accesses != ('open',): 461 if any(not {"open", "presence"}.issuperset(a)
461 raise NotImplementedError('only "open" access model is handled for now') 462 for a in (node_accesses, item_accesses)):
463 raise NotImplementedError('only "open" and "presence" access model are handled for now')
462 if not pep: 464 if not pep:
463 raise NotImplementedError("getLastItems is only implemented for PEP at the moment") 465 raise NotImplementedError("getLastItems is only implemented for PEP at the moment")
464 d = self.dbpool.runQuery("""SELECT DISTINCT ON (node_id) pep, node, data::text, items.access_model 466 d = self.dbpool.runQuery("""SELECT DISTINCT ON (node_id) pep, node, data::text, items.access_model
465 FROM items 467 FROM items
466 NATURAL JOIN nodes 468 NATURAL JOIN nodes