aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pep.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_pep.lua')
-rw-r--r--plugins/mod_pep.lua31
1 files changed, 16 insertions, 15 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 9ff6cac2..752cd28c 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -1,7 +1,7 @@
-- Prosody IM
-- Copyright (C) 2008-2010 Matthew Wild
-- Copyright (C) 2008-2010 Waqas Hussain
---
+--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--
@@ -10,13 +10,12 @@
local jid_bare = require "util.jid".bare;
local jid_split = require "util.jid".split;
local st = require "util.stanza";
-local hosts = hosts;
-local user_exists = require "core.usermanager".user_exists;
local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
-local pairs, ipairs = pairs, ipairs;
+local pairs = pairs;
local next = next;
local type = type;
local calculate_hash = require "util.caps".calculate_hash;
+local core_post_stanza = prosody.core_post_stanza;
local NULL = {};
local data = {};
@@ -32,7 +31,7 @@ module.restore = function(state)
hash_map = state.hash_map or {};
end
-module:add_identity("pubsub", "pep", "Prosody");
+module:add_identity("pubsub", "pep", module:get_option_string("name", "Prosody"));
module:add_feature("http://jabber.org/protocol/pubsub#publish");
local function subscription_presence(user_bare, recipient)
@@ -63,7 +62,7 @@ local function publish(session, node, id, item)
end
else
if not user_data then user_data = {}; data[bare] = user_data; end
- user_data[node] = {id or "1", item};
+ user_data[node] = {id, item};
end
-- broadcast
@@ -124,7 +123,7 @@ module:hook("presence/bare", function(event)
local recipient = stanza.attr.from;
local current = recipients[user] and recipients[user][recipient];
local hash = get_caps_hash_from_presence(stanza, current);
- if current == hash then return; end
+ if current == hash or (current and current == hash_map[hash]) then return; end
if not hash then
if recipients[user] then recipients[user][recipient] = nil; end
else
@@ -136,8 +135,9 @@ module:hook("presence/bare", function(event)
recipients[user][recipient] = hash;
local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host;
if self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then
+ -- COMPAT from ~= stanza.attr.to because OneTeam and Asterisk 1.8 can't deal with missing from attribute
origin.send(
- st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"})
+ st.stanza("iq", {from=user, to=stanza.attr.from, id="disco", type="get"})
:query("http://jabber.org/protocol/disco#info")
);
end
@@ -169,7 +169,8 @@ module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event)
local node = payload.attr.node;
payload = payload.tags[1];
if payload and payload.name == "item" then -- <item>
- local id = payload.attr.id;
+ local id = payload.attr.id or "1";
+ payload.attr.id = id;
session.send(st.reply(stanza));
publish(session, node, id, st.clone(payload));
return true;
@@ -262,19 +263,19 @@ module:hook("iq-result/bare/disco", function(event)
end);
module:hook("account-disco-info", function(event)
- local stanza = event.stanza;
- stanza:tag('identity', {category='pubsub', type='pep'}):up();
- stanza:tag('feature', {var='http://jabber.org/protocol/pubsub#publish'}):up();
+ local reply = event.reply;
+ reply:tag('identity', {category='pubsub', type='pep'}):up();
+ reply:tag('feature', {var='http://jabber.org/protocol/pubsub#publish'}):up();
end);
module:hook("account-disco-items", function(event)
- local stanza = event.stanza;
- local bare = stanza.attr.to;
+ local reply = event.reply;
+ local bare = reply.attr.to;
local user_data = data[bare];
if user_data then
for node, _ in pairs(user_data) do
- stanza:tag('item', {jid=bare, node=node}):up(); -- TODO we need to handle queries to these nodes
+ reply:tag('item', {jid=bare, node=node}):up(); -- TODO we need to handle queries to these nodes
end
end
end);