Software / code / prosody
Comparison
util/pubsub.lua @ 5851:cdcfd93e2f43
mod_pubsub, util.pubsub: Keep track of the order of items
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 04 Oct 2013 16:40:27 +0200 |
| parent | 5776:bd0ff8ae98a8 |
| child | 5973:905b4fd863b4 |
comparison
equal
deleted
inserted
replaced
| 5850:e8c743f4213f | 5851:cdcfd93e2f43 |
|---|---|
| 256 if not ok then | 256 if not ok then |
| 257 return ok, err; | 257 return ok, err; |
| 258 end | 258 end |
| 259 node_obj = self.nodes[node]; | 259 node_obj = self.nodes[node]; |
| 260 end | 260 end |
| 261 node_obj.data[#node_obj.data + 1] = id; | |
| 261 node_obj.data[id] = item; | 262 node_obj.data[id] = item; |
| 262 self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); | 263 self.events.fire_event("item-published", { node = node, actor = actor, id = id, item = item }); |
| 263 self.config.broadcaster("items", node, node_obj.subscribers, item); | 264 self.config.broadcaster("items", node, node_obj.subscribers, item); |
| 264 return true; | 265 return true; |
| 265 end | 266 end |
| 273 local node_obj = self.nodes[node]; | 274 local node_obj = self.nodes[node]; |
| 274 if (not node_obj) or (not node_obj.data[id]) then | 275 if (not node_obj) or (not node_obj.data[id]) then |
| 275 return false, "item-not-found"; | 276 return false, "item-not-found"; |
| 276 end | 277 end |
| 277 node_obj.data[id] = nil; | 278 node_obj.data[id] = nil; |
| 279 for i, _id in ipairs(node_obj.data) do | |
| 280 if id == _id then | |
| 281 table.remove(node_obj, i); | |
| 282 break; | |
| 283 end | |
| 284 end | |
| 278 if retract then | 285 if retract then |
| 279 self.config.broadcaster("items", node, node_obj.subscribers, retract); | 286 self.config.broadcaster("items", node, node_obj.subscribers, retract); |
| 280 end | 287 end |
| 281 return true | 288 return true |
| 282 end | 289 end |
| 307 local node_obj = self.nodes[node]; | 314 local node_obj = self.nodes[node]; |
| 308 if not node_obj then | 315 if not node_obj then |
| 309 return false, "item-not-found"; | 316 return false, "item-not-found"; |
| 310 end | 317 end |
| 311 if id then -- Restrict results to a single specific item | 318 if id then -- Restrict results to a single specific item |
| 312 return true, { [id] = node_obj.data[id] }; | 319 return true, { id, [id] = node_obj.data[id] }; |
| 313 else | 320 else |
| 314 return true, node_obj.data; | 321 return true, node_obj.data; |
| 315 end | 322 end |
| 316 end | 323 end |
| 317 | 324 |