Comparison

plugins/mod_pep.lua @ 1439:f989608964ec

mod_pep: Use cached caps
author Waqas Hussain <waqas20@gmail.com>
date Sun, 28 Jun 2009 21:49:31 +0500
parent 1437:cf2eba9b1716
child 1440:d3117a6ad1bf
comparison
equal deleted inserted replaced
1438:f02a5a982fac 1439:f989608964ec
43 -- broadcast 43 -- broadcast
44 for recipient, notify in pairs(recipients[bare] or NULL) do 44 for recipient, notify in pairs(recipients[bare] or NULL) do
45 if notify[node] then 45 if notify[node] then
46 stanza.attr.to = recipient; 46 stanza.attr.to = recipient;
47 core_post_stanza(session, stanza); 47 core_post_stanza(session, stanza);
48 end
49 end
50 end
51 local function publish_all(user, recipient, session)
52 local d = data[user];
53 local notify = recipients[user] and recipients[user][recipient];
54 if d and notify then
55 for node, message in pairs(notify) do
56 if d[node] then
57 message.attr.to = recipient;
58 session.send(message);
59 end
48 end 60 end
49 end 61 end
50 end 62 end
51 63
52 local function get_caps_hash_from_presence(stanza, current) 64 local function get_caps_hash_from_presence(stanza, current)
83 if current == hash then return; end 95 if current == hash then return; end
84 if not hash then 96 if not hash then
85 if recipients[user] then recipients[user][recipient] = nil; end 97 if recipients[user] then recipients[user][recipient] = nil; end
86 else 98 else
87 recipients[user] = recipients[user] or {}; 99 recipients[user] = recipients[user] or {};
88 recipients[user][recipient] = hash; 100 if hash_map[hash] then
89 origin.send( 101 recipients[user][recipient] = hash_map[hash];
90 st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"}) 102 publish_all(user, recipient);
91 :query("http://jabber.org/protocol/disco#info") 103 else
92 ); 104 recipients[user][recipient] = hash;
105 origin.send(
106 st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"})
107 :query("http://jabber.org/protocol/disco#info")
108 );
109 end
93 end 110 end
94 end 111 end
95 end, 10); 112 end, 10);
96 113
97 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event) 114 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event)
178 end 195 end
179 end 196 end
180 hash_map[ver] = notify; -- update hash map 197 hash_map[ver] = notify; -- update hash map
181 recipients[user][contact] = notify; -- set recipient's data to calculated data 198 recipients[user][contact] = notify; -- set recipient's data to calculated data
182 -- send messages to recipient 199 -- send messages to recipient
183 local d = data[user]; 200 publish_all(user, contact, session);
184 if d then
185 for node, message in pairs(notify) do
186 if d[node] then
187 message.attr.to = stanza.attr.from;
188 session.send(message);
189 end
190 end
191 end
192 end 201 end
193 end 202 end
194 end); 203 end);