Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 1744:265863a5612b
MUC: Added support for requesting various lists (owner, admin, voice, etc).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Mon, 07 Sep 2009 20:33:24 +0500 |
parent | 1743:d00b144f4bcf |
child | 1745:15039fac3693 |
comparison
equal
deleted
inserted
replaced
1743:d00b144f4bcf | 1744:265863a5612b |
---|---|
316 elseif xmlns == "http://jabber.org/protocol/disco#items" then | 316 elseif xmlns == "http://jabber.org/protocol/disco#items" then |
317 origin.send(room_get_disco_items(self, stanza)); | 317 origin.send(room_get_disco_items(self, stanza)); |
318 else | 318 else |
319 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); | 319 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
320 end | 320 end |
321 elseif stanza.name == "iq" and type == "set" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#admin" then | 321 elseif stanza.name == "iq" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#admin" then |
322 local actor = stanza.attr.from; | 322 local actor = stanza.attr.from; |
323 local affiliation = self:get_affiliation(actor); | 323 local affiliation = self:get_affiliation(actor); |
324 local current_nick = self._jid_nick[actor]; | 324 local current_nick = self._jid_nick[actor]; |
325 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation); | 325 local role = current_nick and self._occupants[current_nick].role or self:get_default_role(affiliation); |
326 local item = stanza.tags[1].tags[1]; | 326 local item = stanza.tags[1] and stanza.tags[1].tags[1]; |
327 if item and item.name == "item" then | 327 if item and item.name == "item" then |
328 local callback = function() origin.send(st.reply(stanza)); end | 328 if type == "set" then |
329 if item.attr.affiliation and item.attr.jid and not item.attr.role and not item.attr.nick then | 329 local callback = function() origin.send(st.reply(stanza)); end |
330 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback); | 330 if item.attr.affiliation and item.attr.jid and not item.attr.role and not item.attr.nick then |
331 if not success then origin.send(st.error_reply(stanza, errtype, err)); end | 331 local success, errtype, err = self:set_affiliation(actor, item.attr.jid, item.attr.affiliation, callback); |
332 elseif item.attr.role and item.attr.nick and not item.attr.affiliation and not item.attr.jid then | 332 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
333 local success, errtype, err = self:set_role(actor, item.attr.nick, item.attr.role, callback); | 333 elseif item.attr.role and item.attr.nick and not item.attr.affiliation and not item.attr.jid then |
334 if not success then origin.send(st.error_reply(stanza, errtype, err)); end | 334 local success, errtype, err = self:set_role(actor, item.attr.nick, item.attr.role, callback); |
335 else | 335 if not success then origin.send(st.error_reply(stanza, errtype, err)); end |
336 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | 336 else |
337 end | 337 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
338 else | 338 end |
339 elseif type == "get" then | |
340 local _aff = item.attr.affiliation; | |
341 local _rol = item.attr.role; | |
342 if _aff and not _rol then | |
343 if affiliation == "owner" or (affiliation == "admin" and _aff ~= "owner" and _aff ~= "admin") then | |
344 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); | |
345 for jid, affiliation in pairs(self._affiliations) do | |
346 if affiliation == _aff then | |
347 reply:tag("item", {affiliation = _aff, jid = jid}):up(); | |
348 end | |
349 end | |
350 origin.send(reply); | |
351 else | |
352 origin.send(st.error_reply(stanza, "auth", "forbidden")); | |
353 end | |
354 elseif _rol and not _aff then | |
355 if role == "moderator" then -- TODO allow admins and owners not in room? Provide read-only access to everyone who can see the participants anyway? | |
356 if _rol == "none" then _rol = nil; end | |
357 local reply = st.reply(stanza):query("http://jabber.org/protocol/muc#admin"); | |
358 for nick, occupant in pairs(self._occupants) do | |
359 if occupant.role == _rol then | |
360 reply:tag("item", {nick = nick, role = _rol or "none", affiliation = occupant.affiliation or "none", jid = occupant.jid}):up(); | |
361 end | |
362 end | |
363 origin.send(reply); | |
364 else | |
365 origin.send(st.error_reply(stanza, "auth", "forbidden")); | |
366 end | |
367 else | |
368 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | |
369 end | |
370 end | |
371 elseif type == "set" or type == "get" then | |
339 origin.send(st.error_reply(stanza, "cancel", "bad-request")); | 372 origin.send(st.error_reply(stanza, "cancel", "bad-request")); |
340 end | 373 end |
341 elseif stanza.name == "message" and type == "groupchat" then | 374 elseif stanza.name == "message" and type == "groupchat" then |
342 local from, to = stanza.attr.from, stanza.attr.to; | 375 local from, to = stanza.attr.from, stanza.attr.to; |
343 local room = jid_bare(to); | 376 local room = jid_bare(to); |
408 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end | 441 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end |
409 self._affiliations[jid] = affiliation; | 442 self._affiliations[jid] = affiliation; |
410 local role = self:get_default_role(affiliation); | 443 local role = self:get_default_role(affiliation); |
411 local p = st.presence({type = "unavailable"}) | 444 local p = st.presence({type = "unavailable"}) |
412 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | 445 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
413 :tag("item", {affiliation=affiliation, role=role or "none"}):up(); | 446 :tag("item", {affiliation=affiliation or "none", role=role or "none"}):up(); |
414 local x = p.tags[1]; | 447 local x = p.tags[1]; |
415 local item = x.tags[1]; | 448 local item = x.tags[1]; |
416 if not role then -- getting kicked | 449 if not role then -- getting kicked |
417 if affiliation == "outcast" then | 450 if affiliation == "outcast" then |
418 x:tag("status", {code="301"}):up(); -- banned | 451 x:tag("status", {code="301"}):up(); -- banned |
455 local occupant = self._occupants[nick]; | 488 local occupant = self._occupants[nick]; |
456 if not occupant then return nil, "modify", "not-acceptable"; end | 489 if not occupant then return nil, "modify", "not-acceptable"; end |
457 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end | 490 if occupant.affiliation == "owner" or occupant.affiliation == "admin" then return nil, "cancel", "not-allowed"; end |
458 local p = st.presence({from = nick, type = "unavailable"}) | 491 local p = st.presence({from = nick, type = "unavailable"}) |
459 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) | 492 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
460 :tag("item", {affiliation=occupant.affiliation, nick=nick, role=role or "none"}):up(); | 493 :tag("item", {affiliation=occupant.affiliation or "none", nick=nick, role=role or "none"}):up(); |
461 if not role then -- kick | 494 if not role then -- kick |
462 self._occupants[nick] = nil; | 495 self._occupants[nick] = nil; |
463 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick | 496 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick |
464 self._jid_nick[jid] = nil; | 497 self._jid_nick[jid] = nil; |
465 end | 498 end |