plugins/mod_pep.lua

changeset 3664
345cd1e04e80
parent 3652
c0148fddd81f
child 3666
44c4789d6e17
equal deleted inserted replaced
3663:300ae72fd692 3664:345cd1e04e80
115 module:hook("presence/bare", function(event) 115 module:hook("presence/bare", function(event)
116 -- inbound presence to bare JID recieved 116 -- inbound presence to bare JID recieved
117 local origin, stanza = event.origin, event.stanza; 117 local origin, stanza = event.origin, event.stanza;
118 local user = stanza.attr.to or (origin.username..'@'..origin.host); 118 local user = stanza.attr.to or (origin.username..'@'..origin.host);
119 local t = stanza.attr.type; 119 local t = stanza.attr.type;
120 local self = not stanza.attr.to;
120 121
121 if not t then -- available presence 122 if not t then -- available presence
122 if not stanza.attr.to or subscription_presence(user, stanza.attr.from) then 123 if self or subscription_presence(user, stanza.attr.from) then
123 local recipient = stanza.attr.from; 124 local recipient = stanza.attr.from;
124 local current = recipients[user] and recipients[user][recipient]; 125 local current = recipients[user] and recipients[user][recipient];
125 local hash = get_caps_hash_from_presence(stanza, current); 126 local hash = get_caps_hash_from_presence(stanza, current);
126 if current == hash then return; end 127 if current == hash then return; end
127 if not hash then 128 if not hash then
131 if hash_map[hash] then 132 if hash_map[hash] then
132 recipients[user][recipient] = hash_map[hash]; 133 recipients[user][recipient] = hash_map[hash];
133 publish_all(user, recipient, origin); 134 publish_all(user, recipient, origin);
134 else 135 else
135 recipients[user][recipient] = hash; 136 recipients[user][recipient] = hash;
136 origin.send( 137 if self or origin.type ~= "c2s" then
137 st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"}) 138 origin.send(
138 :query("http://jabber.org/protocol/disco#info") 139 st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"})
139 ); 140 :query("http://jabber.org/protocol/disco#info")
141 );
142 end
140 end 143 end
141 end 144 end
142 end 145 end
143 elseif t == "unavailable" then 146 elseif t == "unavailable" then
144 if recipients[user] then recipients[user][stanza.attr.from] = nil; end 147 if recipients[user] then recipients[user][stanza.attr.from] = nil; end
212 local session, stanza = event.origin, event.stanza; 215 local session, stanza = event.origin, event.stanza;
213 if stanza.attr.type == "result" then 216 if stanza.attr.type == "result" then
214 local disco = stanza.tags[1]; 217 local disco = stanza.tags[1];
215 if disco and disco.name == "query" and disco.attr.xmlns == "http://jabber.org/protocol/disco#info" then 218 if disco and disco.name == "query" and disco.attr.xmlns == "http://jabber.org/protocol/disco#info" then
216 -- Process disco response 219 -- Process disco response
220 local self = not stanza.attr.to;
217 local user = stanza.attr.to or (session.username..'@'..session.host); 221 local user = stanza.attr.to or (session.username..'@'..session.host);
218 local contact = stanza.attr.from; 222 local contact = stanza.attr.from;
219 local current = recipients[user] and recipients[user][contact]; 223 local current = recipients[user] and recipients[user][contact];
220 if type(current) ~= "string" then return; end -- check if waiting for recipient's response 224 if type(current) ~= "string" then return; end -- check if waiting for recipient's response
221 local ver = current; 225 local ver = current;
228 local nfeature = feature.attr.var:match("^(.*)%+notify$"); 232 local nfeature = feature.attr.var:match("^(.*)%+notify$");
229 if nfeature then notify[nfeature] = true; end 233 if nfeature then notify[nfeature] = true; end
230 end 234 end
231 end 235 end
232 hash_map[ver] = notify; -- update hash map 236 hash_map[ver] = notify; -- update hash map
233 recipients[user][contact] = notify; -- set recipient's data to calculated data 237 if self then
238 for jid, item in pairs(origin.roster) do -- for all interested contacts
239 if item.subscription == "both" or item.subscription == "from" then
240 if not recipients[jid] then recipients[jid] = {}; end
241 recipients[jid][contact] = notify;
242 end
243 end
244 else
245 recipients[user][contact] = notify; -- set recipient's data to calculated data
246 end
234 -- send messages to recipient 247 -- send messages to recipient
235 publish_all(user, contact, session); 248 publish_all(user, contact, session);
236 end 249 end
237 end 250 end
238 end); 251 end);

mercurial