Software /
code /
prosody
Changeset
8955:ca6a09cf2829
util.pubsub: Store subscription changes
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 01 Jul 2018 04:42:41 +0200 |
parents | 8954:3b6095686498 |
children | 8956:82f92af4b0f3 |
files | util/pubsub.lua |
diffstat | 1 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/util/pubsub.lua Sun Jul 01 04:33:15 2018 +0200 +++ b/util/pubsub.lua Sun Jul 01 04:42:41 2018 +0200 @@ -174,6 +174,7 @@ node_obj = self.nodes[node]; end end + local old_subscription = node_obj.subscribers[jid]; node_obj.subscribers[jid] = options or true; local normal_jid = self.config.normalize_jid(jid); local subs = self.subscriptions[normal_jid]; @@ -186,6 +187,16 @@ else self.subscriptions[normal_jid] = { [jid] = { [node] = true } }; end + + if self.config.nodestore then + local ok, err = save_node_to_store(self, node_obj); + if not ok then + node_obj.subscribers[jid] = old_subscription; + self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; + return ok, "internal-server-error"; + end + end + self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options }); return true; end @@ -212,6 +223,7 @@ if not node_obj.subscribers[jid] then return false, "not-subscribed"; end + local old_subscription = node_obj.subscribers[jid]; node_obj.subscribers[jid] = nil; local normal_jid = self.config.normalize_jid(jid); local subs = self.subscriptions[normal_jid]; @@ -227,6 +239,16 @@ self.subscriptions[normal_jid] = nil; end end + + if self.config.nodestore then + local ok, err = save_node_to_store(self, node_obj); + if not ok then + node_obj.subscribers[jid] = old_subscription; + self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; + return ok, "internal-server-error"; + end + end + self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); return true; end