Software /
code /
prosody
Comparison
plugins/mod_pep.lua @ 3132:4d2251242ac1
mod_pep: Corrected and optimized handling of non-available presence stanzas.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Wed, 02 Jun 2010 01:54:17 +0500 |
parent | 3130:80e630e60f06 |
child | 3290:1eec2bd19bf7 |
comparison
equal
deleted
inserted
replaced
3131:5c116a10ff0b | 3132:4d2251242ac1 |
---|---|
115 | 115 |
116 module:hook("presence/bare", function(event) | 116 module:hook("presence/bare", function(event) |
117 -- inbound presence to bare JID recieved | 117 -- inbound presence to bare JID recieved |
118 local origin, stanza = event.origin, event.stanza; | 118 local origin, stanza = event.origin, event.stanza; |
119 local user = stanza.attr.to or (origin.username..'@'..origin.host); | 119 local user = stanza.attr.to or (origin.username..'@'..origin.host); |
120 | 120 local t = stanza.attr.type; |
121 if not stanza.attr.to or subscription_presence(user, stanza.attr.from) then | 121 |
122 local recipient = stanza.attr.from; | 122 if not t then -- available presence |
123 local current = recipients[user] and recipients[user][recipient]; | 123 if not stanza.attr.to or subscription_presence(user, stanza.attr.from) then |
124 local hash = get_caps_hash_from_presence(stanza, current); | 124 local recipient = stanza.attr.from; |
125 if current == hash then return; end | 125 local current = recipients[user] and recipients[user][recipient]; |
126 if not hash then | 126 local hash = get_caps_hash_from_presence(stanza, current); |
127 if recipients[user] then recipients[user][recipient] = nil; end | 127 if current == hash then return; end |
128 else | 128 if not hash then |
129 recipients[user] = recipients[user] or {}; | 129 if recipients[user] then recipients[user][recipient] = nil; end |
130 if hash_map[hash] then | |
131 recipients[user][recipient] = hash_map[hash]; | |
132 publish_all(user, recipient, origin); | |
133 else | 130 else |
134 recipients[user][recipient] = hash; | 131 recipients[user] = recipients[user] or {}; |
135 origin.send( | 132 if hash_map[hash] then |
136 st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"}) | 133 recipients[user][recipient] = hash_map[hash]; |
137 :query("http://jabber.org/protocol/disco#info") | 134 publish_all(user, recipient, origin); |
138 ); | 135 else |
139 end | 136 recipients[user][recipient] = hash; |
140 end | 137 origin.send( |
138 st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"}) | |
139 :query("http://jabber.org/protocol/disco#info") | |
140 ); | |
141 end | |
142 end | |
143 end | |
144 elseif t == "unavailable" then | |
145 if recipients[user] then recipients[user][stanza.attr.from] = nil; end | |
141 end | 146 end |
142 end, 10); | 147 end, 10); |
143 | 148 |
144 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event) | 149 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", function(event) |
145 local session, stanza = event.origin, event.stanza; | 150 local session, stanza = event.origin, event.stanza; |