Software / code / prosody
Comparison
util/pubsub.lua @ 8955:ca6a09cf2829
util.pubsub: Store subscription changes
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 01 Jul 2018 04:42:41 +0200 |
| parent | 8954:3b6095686498 |
| child | 8956:82f92af4b0f3 |
comparison
equal
deleted
inserted
replaced
| 8954:3b6095686498 | 8955:ca6a09cf2829 |
|---|---|
| 172 return ok, err; | 172 return ok, err; |
| 173 end | 173 end |
| 174 node_obj = self.nodes[node]; | 174 node_obj = self.nodes[node]; |
| 175 end | 175 end |
| 176 end | 176 end |
| 177 local old_subscription = node_obj.subscribers[jid]; | |
| 177 node_obj.subscribers[jid] = options or true; | 178 node_obj.subscribers[jid] = options or true; |
| 178 local normal_jid = self.config.normalize_jid(jid); | 179 local normal_jid = self.config.normalize_jid(jid); |
| 179 local subs = self.subscriptions[normal_jid]; | 180 local subs = self.subscriptions[normal_jid]; |
| 180 if subs then | 181 if subs then |
| 181 if not subs[jid] then | 182 if not subs[jid] then |
| 184 subs[jid][node] = true; | 185 subs[jid][node] = true; |
| 185 end | 186 end |
| 186 else | 187 else |
| 187 self.subscriptions[normal_jid] = { [jid] = { [node] = true } }; | 188 self.subscriptions[normal_jid] = { [jid] = { [node] = true } }; |
| 188 end | 189 end |
| 190 | |
| 191 if self.config.nodestore then | |
| 192 local ok, err = save_node_to_store(self, node_obj); | |
| 193 if not ok then | |
| 194 node_obj.subscribers[jid] = old_subscription; | |
| 195 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; | |
| 196 return ok, "internal-server-error"; | |
| 197 end | |
| 198 end | |
| 199 | |
| 189 self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options }); | 200 self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options }); |
| 190 return true; | 201 return true; |
| 191 end | 202 end |
| 192 | 203 |
| 193 function service:remove_subscription(node, actor, jid) | 204 function service:remove_subscription(node, actor, jid) |
| 210 return false, "item-not-found"; | 221 return false, "item-not-found"; |
| 211 end | 222 end |
| 212 if not node_obj.subscribers[jid] then | 223 if not node_obj.subscribers[jid] then |
| 213 return false, "not-subscribed"; | 224 return false, "not-subscribed"; |
| 214 end | 225 end |
| 226 local old_subscription = node_obj.subscribers[jid]; | |
| 215 node_obj.subscribers[jid] = nil; | 227 node_obj.subscribers[jid] = nil; |
| 216 local normal_jid = self.config.normalize_jid(jid); | 228 local normal_jid = self.config.normalize_jid(jid); |
| 217 local subs = self.subscriptions[normal_jid]; | 229 local subs = self.subscriptions[normal_jid]; |
| 218 if subs then | 230 if subs then |
| 219 local jid_subs = subs[jid]; | 231 local jid_subs = subs[jid]; |
| 225 end | 237 end |
| 226 if next(subs) == nil then | 238 if next(subs) == nil then |
| 227 self.subscriptions[normal_jid] = nil; | 239 self.subscriptions[normal_jid] = nil; |
| 228 end | 240 end |
| 229 end | 241 end |
| 242 | |
| 243 if self.config.nodestore then | |
| 244 local ok, err = save_node_to_store(self, node_obj); | |
| 245 if not ok then | |
| 246 node_obj.subscribers[jid] = old_subscription; | |
| 247 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; | |
| 248 return ok, "internal-server-error"; | |
| 249 end | |
| 250 end | |
| 251 | |
| 230 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); | 252 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); |
| 231 return true; | 253 return true; |
| 232 end | 254 end |
| 233 | 255 |
| 234 function service:get_subscription(node, actor, jid) | 256 function service:get_subscription(node, actor, jid) |