Software /
code /
prosody
Comparison
util/pubsub.lua @ 9230:711fea229e48
util.pubsub: Add 'service' field to all events
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 27 Aug 2018 14:07:28 +0100 |
parent | 9220:c4f9469b203f |
child | 9232:65c83bfcf2ee |
comparison
equal
deleted
inserted
replaced
9229:1338b84c0566 | 9230:711fea229e48 |
---|---|
319 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; | 319 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; |
320 return ok, "internal-server-error"; | 320 return ok, "internal-server-error"; |
321 end | 321 end |
322 end | 322 end |
323 | 323 |
324 self.events.fire_event("subscription-added", { node = node, jid = jid, normalized_jid = normal_jid, options = options }); | 324 self.events.fire_event("subscription-added", { service = self, node = node, jid = jid, normalized_jid = normal_jid, options = options }); |
325 return true; | 325 return true; |
326 end | 326 end |
327 | 327 |
328 function service:remove_subscription(node, actor, jid) | 328 function service:remove_subscription(node, actor, jid) |
329 -- Access checking | 329 -- Access checking |
371 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; | 371 self.subscriptions[normal_jid][jid][node] = old_subscription and true or nil; |
372 return ok, "internal-server-error"; | 372 return ok, "internal-server-error"; |
373 end | 373 end |
374 end | 374 end |
375 | 375 |
376 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); | 376 self.events.fire_event("subscription-removed", { service = self, node = node, jid = jid, normalized_jid = normal_jid }); |
377 return true; | 377 return true; |
378 end | 378 end |
379 | 379 |
380 function service:get_subscription(node, actor, jid) | 380 function service:get_subscription(node, actor, jid) |
381 -- Access checking | 381 -- Access checking |
420 return ok, "internal-server-error"; | 420 return ok, "internal-server-error"; |
421 end | 421 end |
422 end | 422 end |
423 | 423 |
424 self.data[node] = self.config.itemstore(self.nodes[node].config, node); | 424 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
425 self.events.fire_event("node-created", { node = node, actor = actor }); | 425 self.events.fire_event("node-created", { service = self, node = node, actor = actor }); |
426 if actor ~= true then | 426 if actor ~= true then |
427 local ok, err = self:set_affiliation(node, true, actor, "owner"); | 427 local ok, err = self:set_affiliation(node, true, actor, "owner"); |
428 if not ok then | 428 if not ok then |
429 self.nodes[node] = nil; | 429 self.nodes[node] = nil; |
430 self.data[node] = nil; | 430 self.data[node] = nil; |
457 self.nodes[node] = nil; | 457 self.nodes[node] = nil; |
458 return ok, err; | 458 return ok, err; |
459 end | 459 end |
460 end | 460 end |
461 | 461 |
462 self.events.fire_event("node-deleted", { node = node, actor = actor }); | 462 self.events.fire_event("node-deleted", { service = self, node = node, actor = actor }); |
463 self.config.broadcaster("delete", node, node_obj.subscribers, nil, actor, node_obj, self); | 463 self.config.broadcaster("delete", node, node_obj.subscribers, nil, actor, node_obj, self); |
464 return true; | 464 return true; |
465 end | 465 end |
466 | 466 |
467 -- Used to check that the config of a node is as expected (i.e. 'publish-options') | 467 -- Used to check that the config of a node is as expected (i.e. 'publish-options') |
515 local ok = node_data:set(id, item); | 515 local ok = node_data:set(id, item); |
516 if not ok then | 516 if not ok then |
517 return nil, "internal-server-error"; | 517 return nil, "internal-server-error"; |
518 end | 518 end |
519 if type(ok) == "string" then id = ok; end | 519 if type(ok) == "string" then id = ok; end |
520 local event_data = { node = node, actor = actor, id = id, item = item }; | 520 local event_data = { service = self, node = node, actor = actor, id = id, item = item }; |
521 self.events.fire_event("item-published/"..node, event_data); | 521 self.events.fire_event("item-published/"..node, event_data); |
522 self.events.fire_event("item-published", event_data); | 522 self.events.fire_event("item-published", event_data); |
523 self.config.broadcaster("items", node, node_obj.subscribers, item, actor, node_obj, self); | 523 self.config.broadcaster("items", node, node_obj.subscribers, item, actor, node_obj, self); |
524 return true; | 524 return true; |
525 end | 525 end |
536 end | 536 end |
537 local ok = self.data[node]:set(id, nil); | 537 local ok = self.data[node]:set(id, nil); |
538 if not ok then | 538 if not ok then |
539 return nil, "internal-server-error"; | 539 return nil, "internal-server-error"; |
540 end | 540 end |
541 self.events.fire_event("item-retracted", { node = node, actor = actor, id = id }); | 541 self.events.fire_event("item-retracted", { service = self, node = node, actor = actor, id = id }); |
542 if retract then | 542 if retract then |
543 self.config.broadcaster("retract", node, node_obj.subscribers, retract, actor, node_obj, self); | 543 self.config.broadcaster("retract", node, node_obj.subscribers, retract, actor, node_obj, self); |
544 end | 544 end |
545 return true | 545 return true |
546 end | 546 end |
558 if self.data[node] and self.data[node].clear then | 558 if self.data[node] and self.data[node].clear then |
559 self.data[node]:clear() | 559 self.data[node]:clear() |
560 else | 560 else |
561 self.data[node] = self.config.itemstore(self.nodes[node].config, node); | 561 self.data[node] = self.config.itemstore(self.nodes[node].config, node); |
562 end | 562 end |
563 self.events.fire_event("node-purged", { node = node, actor = actor }); | 563 self.events.fire_event("node-purged", { service = self, node = node, actor = actor }); |
564 if notify then | 564 if notify then |
565 self.config.broadcaster("purge", node, node_obj.subscribers, nil, actor, node_obj, self); | 565 self.config.broadcaster("purge", node, node_obj.subscribers, nil, actor, node_obj, self); |
566 end | 566 end |
567 return true | 567 return true |
568 end | 568 end |