aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-07-01 04:42:41 +0200
committerKim Alvefur <zash@zash.se>2018-07-01 04:42:41 +0200
commit6d639a75d4c8db2ddd7e56367e737a063914f53f (patch)
treeba2d9fde79d7ad1ae38cf284c5b77753a0fa1953 /util
parent4d6226b9eb07e1a82b3d589cab7f7007bad8a655 (diff)
downloadprosody-6d639a75d4c8db2ddd7e56367e737a063914f53f.tar.gz
prosody-6d639a75d4c8db2ddd7e56367e737a063914f53f.zip
util.pubsub: Store subscription changes
Diffstat (limited to 'util')
-rw-r--r--util/pubsub.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua
index 267c9a3c..9a5470bf 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -174,6 +174,7 @@ function service:add_subscription(node, actor, jid, options)
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 @@ function service:add_subscription(node, actor, jid, options)
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 @@ function service:remove_subscription(node, actor, jid)
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 @@ function service:remove_subscription(node, actor, jid)
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