909 end |
909 end |
910 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end |
910 if self:get_affiliation(actor) ~= "owner" then return nil, "cancel", "not-allowed"; end |
911 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end |
911 if jid_bare(actor) == jid then return nil, "cancel", "not-allowed"; end |
912 self._affiliations[jid] = affiliation; |
912 self._affiliations[jid] = affiliation; |
913 local role = self:get_default_role(affiliation); |
913 local role = self:get_default_role(affiliation); |
914 local p = st.presence() |
914 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
915 :tag("x", {xmlns = "http://jabber.org/protocol/muc#user"}) |
|
916 :tag("item", {affiliation=affiliation or "none", role=role or "none"}) |
915 :tag("item", {affiliation=affiliation or "none", role=role or "none"}) |
917 :tag("reason"):text(reason or ""):up() |
916 :tag("reason"):text(reason or ""):up() |
918 :up(); |
917 :up(); |
919 local x = p.tags[1]; |
918 local presence_type = nil; |
920 local item = x.tags[1]; |
|
921 if not role then -- getting kicked |
919 if not role then -- getting kicked |
922 p.attr.type = "unavailable"; |
920 presence_type = "unavailable"; |
923 if affiliation == "outcast" then |
921 if affiliation == "outcast" then |
924 x:tag("status", {code="301"}):up(); -- banned |
922 x:tag("status", {code="301"}):up(); -- banned |
925 else |
923 else |
926 x:tag("status", {code="321"}):up(); -- affiliation change |
924 x:tag("status", {code="321"}):up(); -- affiliation change |
927 end |
925 end |
928 end |
926 end |
929 local modified_nicks = {}; |
927 local modified_nicks = {}; |
930 for nick, occupant in pairs(self._occupants) do |
928 for nick, occupant in pairs(self._occupants) do |
931 if jid_bare(occupant.jid) == jid then |
929 if jid_bare(occupant.jid) == jid then |
932 t_insert(modified_nicks, nick); |
|
933 if not role then -- getting kicked |
930 if not role then -- getting kicked |
934 self._occupants[nick] = nil; |
931 self._occupants[nick] = nil; |
935 else |
932 else |
936 occupant.affiliation, occupant.role = affiliation, role; |
933 occupant.affiliation, occupant.role = affiliation, role; |
937 end |
934 end |
938 p.attr.from = nick; |
935 for jid,pres in pairs(occupant.sessions) do -- remove for all sessions of the nick |
939 for jid in pairs(occupant.sessions) do -- remove for all sessions of the nick |
|
940 if not role then self._jid_nick[jid] = nil; end |
936 if not role then self._jid_nick[jid] = nil; end |
|
937 local p = st.clone(pres); |
|
938 p.attr.from = nick; |
|
939 p.attr.type = presence_type; |
941 p.attr.to = jid; |
940 p.attr.to = jid; |
|
941 p:add_child(x); |
942 self:_route_stanza(p); |
942 self:_route_stanza(p); |
|
943 if occupant.jid == jid then |
|
944 modified_nicks[nick] = p; |
|
945 end |
943 end |
946 end |
944 end |
947 end |
945 end |
948 end |
946 if self.save then self:save(); end |
949 if self.save then self:save(); end |
947 if callback then callback(); end |
950 if callback then callback(); end |
948 for _, nick in ipairs(modified_nicks) do |
951 for nick,p in pairs(modified_nicks) do |
949 p.attr.from = nick; |
952 p.attr.from = nick; |
950 self:broadcast_except_nick(p, nick); |
953 self:broadcast_except_nick(p, nick); |
951 end |
954 end |
952 return true; |
955 return true; |
953 end |
956 end |