Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 2214:a4c8b5763d0a
Merge with trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 25 Nov 2009 17:40:24 +0000 |
parent | 2174:13375e6c4ecb |
child | 2216:dbbb5ed41365 |
child | 2845:f76139aa7cd5 |
comparison
equal
deleted
inserted
replaced
2213:141896297cea | 2214:a4c8b5763d0a |
---|---|
126 stanza.attr.to = sid; | 126 stanza.attr.to = sid; |
127 self:_route_stanza(stanza); | 127 self:_route_stanza(stanza); |
128 end | 128 end |
129 end | 129 end |
130 function room_mt:broadcast_message(stanza, historic) | 130 function room_mt:broadcast_message(stanza, historic) |
131 local to = stanza.attr.to; | |
131 for occupant, o_data in pairs(self._occupants) do | 132 for occupant, o_data in pairs(self._occupants) do |
132 for jid in pairs(o_data.sessions) do | 133 for jid in pairs(o_data.sessions) do |
133 stanza.attr.to = jid; | 134 stanza.attr.to = jid; |
134 self:_route_stanza(stanza); | 135 self:_route_stanza(stanza); |
135 end | 136 end |
136 end | 137 end |
138 stanza.attr.to = to; | |
137 if historic then -- add to history | 139 if historic then -- add to history |
138 local history = self._data['history']; | 140 local history = self._data['history']; |
139 if not history then history = {}; self._data['history'] = history; end | 141 if not history then history = {}; self._data['history'] = history; end |
140 -- stanza = st.clone(stanza); | 142 stanza = st.clone(stanza); |
141 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 | 143 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 |
142 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) | 144 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) |
143 t_insert(history, st.clone(st.preserialize(stanza))); | 145 t_insert(history, st.preserialize(stanza)); |
144 while #history > history_length do t_remove(history, 1) end | 146 while #history > history_length do t_remove(history, 1) end |
145 end | 147 end |
146 end | 148 end |
147 function room_mt:broadcast_except_nick(stanza, nick) | 149 function room_mt:broadcast_except_nick(stanza, nick) |
148 for rnick, occupant in pairs(self._occupants) do | 150 for rnick, occupant in pairs(self._occupants) do |
515 end | 517 end |
516 elseif stanza.name == "message" and type == "groupchat" then | 518 elseif stanza.name == "message" and type == "groupchat" then |
517 local from, to = stanza.attr.from, stanza.attr.to; | 519 local from, to = stanza.attr.from, stanza.attr.to; |
518 local room = jid_bare(to); | 520 local room = jid_bare(to); |
519 local current_nick = self._jid_nick[from]; | 521 local current_nick = self._jid_nick[from]; |
520 if not current_nick then -- not in room | 522 local occupant = self._occupants[current_nick]; |
523 if not occupant then -- not in room | |
521 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); | 524 origin.send(st.error_reply(stanza, "cancel", "not-acceptable")); |
525 elseif occupant.role == "visitor" then | |
526 origin.send(st.error_reply(stanza, "cancel", "forbidden")); | |
522 else | 527 else |
523 local from = stanza.attr.from; | 528 local from = stanza.attr.from; |
524 stanza.attr.from = current_nick; | 529 stanza.attr.from = current_nick; |
525 local subject = getText(stanza, {"subject"}); | 530 local subject = getText(stanza, {"subject"}); |
526 if subject then | 531 if subject then |
527 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza | 532 if occupant.role == "moderator" then |
533 self:set_subject(current_nick, subject); -- TODO use broadcast_message_stanza | |
534 else | |
535 stanza.attr.from = from; | |
536 origin.send(st.error_reply(stanza, "cancel", "forbidden")); | |
537 end | |
528 else | 538 else |
529 self:broadcast_message(stanza, true); | 539 self:broadcast_message(stanza, true); |
530 end | 540 end |
541 stanza.attr.from = from; | |
531 end | 542 end |
532 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then | 543 elseif stanza.name == "message" and type == "error" and is_kickable_error(stanza) then |
533 local current_nick = self._jid_nick[stanza.attr.from]; | 544 local current_nick = self._jid_nick[stanza.attr.from]; |
534 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); | 545 log("debug", "%s kicked from %s for sending an error message", current_nick, self.jid); |
535 self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) | 546 self:handle_to_occupant(origin, st.presence({type='unavailable', from=stanza.attr.from, to=stanza.attr.to}) |