Comparison

util/pubsub.lua @ 5971:637731f0b9a3

util.pubsub: Fire events on more actions
author Kim Alvefur <zash@zash.se>
date Thu, 26 Dec 2013 18:14:34 +0100
parent 5776:bd0ff8ae98a8
child 5972:f365d3c8fd2c
comparison
equal deleted inserted replaced
5970:6a2c3293d4d7 5971:637731f0b9a3
217 subscribers = {}; 217 subscribers = {};
218 config = {}; 218 config = {};
219 data = {}; 219 data = {};
220 affiliations = {}; 220 affiliations = {};
221 }; 221 };
222 self.events.fire_event("node-created", { node = node, actor = actor });
222 local ok, err = self:set_affiliation(node, true, actor, "owner"); 223 local ok, err = self:set_affiliation(node, true, actor, "owner");
223 if not ok then 224 if not ok then
224 self.nodes[node] = nil; 225 self.nodes[node] = nil;
225 end 226 end
226 return ok, err; 227 return ok, err;
235 local node_obj = self.nodes[node]; 236 local node_obj = self.nodes[node];
236 if not node_obj then 237 if not node_obj then
237 return false, "item-not-found"; 238 return false, "item-not-found";
238 end 239 end
239 self.nodes[node] = nil; 240 self.nodes[node] = nil;
241 self.events.fire_event("node-deleted", { node = node, actor = actor });
240 self.config.broadcaster("delete", node, node_obj.subscribers); 242 self.config.broadcaster("delete", node, node_obj.subscribers);
241 return true; 243 return true;
242 end 244 end
243 245
244 function service:publish(node, actor, id, item) 246 function service:publish(node, actor, id, item)
272 -- 274 --
273 local node_obj = self.nodes[node]; 275 local node_obj = self.nodes[node];
274 if (not node_obj) or (not node_obj.data[id]) then 276 if (not node_obj) or (not node_obj.data[id]) then
275 return false, "item-not-found"; 277 return false, "item-not-found";
276 end 278 end
279 self.events.fire_event("item-retracted", { node = node, actor = actor, id = id });
277 node_obj.data[id] = nil; 280 node_obj.data[id] = nil;
278 if retract then 281 if retract then
279 self.config.broadcaster("items", node, node_obj.subscribers, retract); 282 self.config.broadcaster("items", node, node_obj.subscribers, retract);
280 end 283 end
281 return true 284 return true
290 local node_obj = self.nodes[node]; 293 local node_obj = self.nodes[node];
291 if not node_obj then 294 if not node_obj then
292 return false, "item-not-found"; 295 return false, "item-not-found";
293 end 296 end
294 node_obj.data = {}; -- Purge 297 node_obj.data = {}; -- Purge
298 self.events.fire_event("node-purged", { node = node, actor = actor });
295 if notify then 299 if notify then
296 self.config.broadcaster("purge", node, node_obj.subscribers); 300 self.config.broadcaster("purge", node, node_obj.subscribers);
297 end 301 end
298 return true 302 return true
299 end 303 end