236 end; |
236 end; |
237 set = function(self, user, data) |
237 set = function(self, user, data) |
238 local xml = self:_get_user_xml(user, self.host); |
238 local xml = self:_get_user_xml(user, self.host); |
239 local usere = xml and getUserElement(xml); |
239 local usere = xml and getUserElement(xml); |
240 if usere then |
240 if usere then |
|
241 local user_jid = jid.join(usere.name, self.host); |
241 usere:remove_children("query", "jabber:iq:roster"); |
242 usere:remove_children("query", "jabber:iq:roster"); |
242 usere:maptags(function (tag) |
243 usere:maptags(function (tag) |
243 if tag.attr.xmlns == "jabber:client" and tag.name == "presence" and tag.attr.type == "subscribe" then |
244 if tag.attr.xmlns == "jabber:client" and tag.name == "presence" and tag.attr.type == "subscribe" then |
244 return nil; |
245 return nil; |
245 end |
246 end |
246 return tag; |
247 return tag; |
247 end); |
248 end); |
248 if data and next(data) ~= nil then |
249 if data and next(data) ~= nil then |
249 local roster = st.stanza("query", {xmlns='jabber:iq:roster'}); |
250 local roster = st.stanza("query", {xmlns='jabber:iq:roster'}); |
250 usere:add_child(roster); |
251 usere:add_child(roster); |
251 for jid, item in pairs(data) do |
252 for contact_jid, item in pairs(data) do |
252 if jid then |
253 contact_jid = jid.bare(jid.prep(contact_jid)); |
253 roster:tag("item", { |
254 if contact_jid ~= false then |
254 jid = jid, |
255 if contact_jid ~= user_jid then -- Skip self-contacts |
255 subscription = item.subscription, |
256 roster:tag("item", { |
256 ask = item.ask, |
257 jid = contact_jid, |
257 name = item.name, |
258 subscription = item.subscription, |
258 }); |
259 ask = item.ask, |
259 for group in pairs(item.groups) do |
260 name = item.name, |
260 roster:tag("group"):text(group):up(); |
261 }); |
|
262 for group in pairs(item.groups) do |
|
263 roster:tag("group"):text(group):up(); |
|
264 end |
|
265 roster:up(); -- move out from item |
261 end |
266 end |
262 roster:up(); -- move out from item |
|
263 else |
267 else |
264 roster.attr.version = item.version; |
268 roster.attr.version = item.version; |
265 for pending_jid in pairs(item.pending) do |
269 for pending_jid in pairs(item.pending) do |
266 usere:add_child(st.presence({ from = pending_jid, type = "subscribe" })); |
270 usere:add_child(st.presence({ from = pending_jid, type = "subscribe" })); |
267 end |
271 end |