Software /
code /
prosody
Comparison
plugins/mod_pep.lua @ 6544:2f709bc35575
mod_pep: Fire an event when an item is published
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 20 Dec 2014 21:34:59 +0100 |
parent | 5805:11b6157ee274 |
child | 6866:abff7543b79c |
comparison
equal
deleted
inserted
replaced
6533:5da544e97bea | 6544:2f709bc35575 |
---|---|
39 if (recipient_bare == user_bare) then return true end | 39 if (recipient_bare == user_bare) then return true end |
40 local username, host = jid_split(user_bare); | 40 local username, host = jid_split(user_bare); |
41 return is_contact_subscribed(username, host, recipient_bare); | 41 return is_contact_subscribed(username, host, recipient_bare); |
42 end | 42 end |
43 | 43 |
44 local function publish(session, node, id, item) | 44 module:hook("pep-publish-item", function (event) |
45 local session, node, id, item = event.session, event.node, event.id, event.item; | |
45 item.attr.xmlns = nil; | 46 item.attr.xmlns = nil; |
46 local disable = #item.tags ~= 1 or #item.tags[1] == 0; | 47 local disable = #item.tags ~= 1 or #item.tags[1] == 0; |
47 if #item.tags == 0 then item.name = "retract"; end | 48 if #item.tags == 0 then item.name = "retract"; end |
48 local bare = session.username..'@'..session.host; | 49 local bare = session.username..'@'..session.host; |
49 local stanza = st.message({from=bare, type='headline'}) | 50 local stanza = st.message({from=bare, type='headline'}) |
70 if notify[node] then | 71 if notify[node] then |
71 stanza.attr.to = recipient; | 72 stanza.attr.to = recipient; |
72 core_post_stanza(session, stanza); | 73 core_post_stanza(session, stanza); |
73 end | 74 end |
74 end | 75 end |
75 end | 76 end); |
77 | |
76 local function publish_all(user, recipient, session) | 78 local function publish_all(user, recipient, session) |
77 local d = data[user]; | 79 local d = data[user]; |
78 local notify = recipients[user] and recipients[user][recipient]; | 80 local notify = recipients[user] and recipients[user][recipient]; |
79 if d and notify then | 81 if d and notify then |
80 for node in pairs(notify) do | 82 for node in pairs(notify) do |
170 payload = payload.tags[1]; | 172 payload = payload.tags[1]; |
171 if payload and payload.name == "item" then -- <item> | 173 if payload and payload.name == "item" then -- <item> |
172 local id = payload.attr.id or "1"; | 174 local id = payload.attr.id or "1"; |
173 payload.attr.id = id; | 175 payload.attr.id = id; |
174 session.send(st.reply(stanza)); | 176 session.send(st.reply(stanza)); |
175 publish(session, node, id, st.clone(payload)); | 177 module:fire_event("pep-publish-item", { |
178 node = node, actor = session.jid, id = id, session = session, item = st.clone(payload); | |
179 }); | |
176 return true; | 180 return true; |
177 end | 181 end |
178 end | 182 end |
179 elseif stanza.attr.type == 'get' then | 183 elseif stanza.attr.type == 'get' then |
180 local user = stanza.attr.to and jid_bare(stanza.attr.to) or session.username..'@'..session.host; | 184 local user = stanza.attr.to and jid_bare(stanza.attr.to) or session.username..'@'..session.host; |