Mercurial > prosody-hg
comparison plugins/mod_pep.lua @ 1325:b58645973d7d
mod_pep: Send items to contacts coming online
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sun, 07 Jun 2009 18:04:08 +0500 |
| parents | dc64a841f0c2 |
| children | 20285e9d71ee |
comparison
equal
deleted
inserted
replaced
| 1324:dc64a841f0c2 | 1325:b58645973d7d |
|---|---|
| 4 local st = require "util.stanza"; | 4 local st = require "util.stanza"; |
| 5 local hosts = hosts; | 5 local hosts = hosts; |
| 6 local user_exists = require "core.usermanager".user_exists; | 6 local user_exists = require "core.usermanager".user_exists; |
| 7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; | 7 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed; |
| 8 local pairs, ipairs = pairs, ipairs; | 8 local pairs, ipairs = pairs, ipairs; |
| 9 local load_roster = require "core.rostermanager".load_roster; | |
| 9 | 10 |
| 10 local data = {}; | 11 local data = {}; |
| 12 local recipients = {}; | |
| 11 | 13 |
| 12 local function publish(session, node, item) | 14 local function publish(session, node, item) |
| 13 local stanza = st.message({from=session.full_jid, type='headline'}) | 15 local stanza = st.message({from=session.full_jid, type='headline'}) |
| 14 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'}) | 16 :tag('event', {xmlns='http://jabber.org/protocol/pubsub#event'}) |
| 15 :tag('items', {node=node}) | 17 :tag('items', {node=node}) |
| 34 core_route_stanza(session, stanza); | 36 core_route_stanza(session, stanza); |
| 35 end | 37 end |
| 36 end | 38 end |
| 37 end | 39 end |
| 38 | 40 |
| 41 module:hook("presence/bare", function(data) | |
| 42 -- inbound presence to bare JID recieved | |
| 43 local origin, stanza = data.origin, data.stanza; | |
| 44 | |
| 45 local user = stanza.attr.to or (origin.username..'@'..origin.host); | |
| 46 local bare = jid_bare(stanza.attr.from); | |
| 47 local item = load_roster(jid_split(user))[bare]; | |
| 48 if not stanza.attr.to or (item and (item.subscription == 'from' or item.subscription == 'both')) then | |
| 49 local t = stanza.attr.type; | |
| 50 local recipient = stanza.attr.from; | |
| 51 if t == "unavailable" or t == "error" then | |
| 52 if recipients[user] then recipients[user][recipient] = nil; end | |
| 53 elseif not t then | |
| 54 recipients[user] = recipients[user][recipient] or {}; | |
| 55 if not recipients[user][recipient] then | |
| 56 recipients[user][recipient] = true; | |
| 57 for node, message in pairs(data[user] or {}) do | |
| 58 message.attr.to = stanza.attr.from; | |
| 59 origin.send(message); | |
| 60 end | |
| 61 end | |
| 62 end | |
| 63 end | |
| 64 end); | |
| 65 | |
| 39 module:add_iq_handler("c2s", "http://jabber.org/protocol/pubsub", function (session, stanza) | 66 module:add_iq_handler("c2s", "http://jabber.org/protocol/pubsub", function (session, stanza) |
| 40 if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then | 67 if stanza.attr.type == 'set' and (not stanza.attr.to or jid_bare(stanza.attr.from) == stanza.attr.to) then |
| 41 local payload = stanza.tags[1]; | 68 local payload = stanza.tags[1]; |
| 42 if payload.name == 'pubsub' then | 69 if payload.name == 'pubsub' then |
| 43 payload = payload.tags[1]; | 70 payload = payload.tags[1]; |
