Mercurial > prosody-hg
comparison plugins/mod_muc.lua @ 833:5da1130054d1
MUC: Removed commented and unused code
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Sat, 21 Feb 2009 01:24:23 +0500 |
| parents | e2d2095705dc |
| children | 596a6b425eb9 |
comparison
equal
deleted
inserted
replaced
| 832:282ae70db19f | 833:5da1130054d1 |
|---|---|
| 117 rooms_info:set(room, 'subject', subject); | 117 rooms_info:set(room, 'subject', subject); |
| 118 save_room(); | 118 save_room(); |
| 119 local msg = st.message({type='groupchat', from=current_nick}) | 119 local msg = st.message({type='groupchat', from=current_nick}) |
| 120 :tag('subject'):text(subject):up(); | 120 :tag('subject'):text(subject):up(); |
| 121 broadcast_message_stanza(room, msg, false); | 121 broadcast_message_stanza(room, msg, false); |
| 122 --broadcast_message(current_nick, room, subject or "", nil); | |
| 123 return true; | 122 return true; |
| 124 end | 123 end |
| 125 | 124 |
| 126 function broadcast_presence(type, from, room, code, newnick) | |
| 127 local data = rooms:get(room, from); | |
| 128 local stanza = st.presence({type=type, from=from}) | |
| 129 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) | |
| 130 :tag("item", {affiliation=data.affiliation, role=data.role, nick = newnick}):up(); | |
| 131 if code then | |
| 132 stanza:tag("status", {code=code}):up(); | |
| 133 end | |
| 134 local me; | |
| 135 local r = rooms:get(room); | |
| 136 if r then | |
| 137 for occupant, o_data in pairs(r) do | |
| 138 if occupant ~= from then | |
| 139 stanza.attr.to = o_data.jid; | |
| 140 core_route_stanza(component, stanza); | |
| 141 else | |
| 142 me = o_data.jid; | |
| 143 end | |
| 144 end | |
| 145 end | |
| 146 if me then | |
| 147 stanza:tag("status", {code='110'}); | |
| 148 stanza.attr.to = me; | |
| 149 core_route_stanza(component, stanza); | |
| 150 end | |
| 151 end | |
| 152 function broadcast_message(from, room, subject, body) | |
| 153 local stanza = st.message({type='groupchat', from=from}); | |
| 154 if subject then stanza:tag('subject'):text(subject):up(); end | |
| 155 if body then stanza:tag('body'):text(body):up(); end | |
| 156 local r = rooms:get(room); | |
| 157 if r then | |
| 158 for occupant, o_data in pairs(r) do | |
| 159 stanza.attr.to = o_data.jid; | |
| 160 core_route_stanza(component, stanza); | |
| 161 end | |
| 162 if not subject and body then -- add to history | |
| 163 local history = rooms_info:get(room, 'history'); | |
| 164 if not history then history = {}; rooms_info:set(room, 'history', history); end | |
| 165 -- stanza = st.clone(stanza); | |
| 166 stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203 | |
| 167 stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated) | |
| 168 t_insert(history, st.clone(st.preserialize(stanza))); | |
| 169 while #history > history_length do t_remove(history, 1) end | |
| 170 end | |
| 171 end | |
| 172 end | |
| 173 function broadcast_message_stanza(room, stanza, historic) | 125 function broadcast_message_stanza(room, stanza, historic) |
| 174 local r = rooms:get(room); | 126 local r = rooms:get(room); |
| 175 if r then | 127 if r then |
| 176 for occupant, o_data in pairs(r) do | 128 for occupant, o_data in pairs(r) do |
| 177 for jid in pairs(o_data.sessions) do | 129 for jid in pairs(o_data.sessions) do |
| 235 if current_nick then | 187 if current_nick then |
| 236 log("debug", "kicking %s from %s", current_nick, room); | 188 log("debug", "kicking %s from %s", current_nick, room); |
| 237 local data = rooms:get(room, current_nick); | 189 local data = rooms:get(room, current_nick); |
| 238 data.role = 'none'; | 190 data.role = 'none'; |
| 239 local pr = st.presence({type='unavailable', from=current_nick}):tag('status'):text('This participant is kicked from the room because he sent an error presence'):up() | 191 local pr = st.presence({type='unavailable', from=current_nick}):tag('status'):text('This participant is kicked from the room because he sent an error presence'):up() |
| 240 --:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) | |
| 241 --:tag("item", {affiliation=data.affiliation, role=data.role}):up(); | |
| 242 broadcast_presence_stanza(room, pr); | 192 broadcast_presence_stanza(room, pr); |
| 243 --broadcast_presence('unavailable', current_nick, room); -- TODO also add <status>This participant is kicked from the room because he sent an error presence: badformed error stanza</status> | |
| 244 rooms:remove(room, current_nick); | 193 rooms:remove(room, current_nick); |
| 245 jid_nick:remove(from, room); | 194 jid_nick:remove(from, room); |
| 246 end | 195 end |
| 247 elseif type == "unavailable" then -- unavailable | 196 elseif type == "unavailable" then -- unavailable |
| 248 if current_nick then | 197 if current_nick then |
| 249 log("debug", "%s leaving %s", current_nick, room); | 198 log("debug", "%s leaving %s", current_nick, room); |
| 250 -- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data)); | |
| 251 -- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data)); | |
| 252 local data = rooms:get(room, current_nick); | 199 local data = rooms:get(room, current_nick); |
| 253 data.role = 'none'; | 200 data.role = 'none'; |
| 254 broadcast_presence_stanza(room, pr); | 201 broadcast_presence_stanza(room, pr); |
| 255 --broadcast_presence('unavailable', current_nick, room); | |
| 256 rooms:remove(room, current_nick); | 202 rooms:remove(room, current_nick); |
| 257 jid_nick:remove(from, room); | 203 jid_nick:remove(from, room); |
| 258 end | 204 end |
| 259 elseif not type then -- available | 205 elseif not type then -- available |
| 260 if current_nick then | 206 if current_nick then |
| 270 else | 216 else |
| 271 local data = rooms:get(room, current_nick); | 217 local data = rooms:get(room, current_nick); |
| 272 local to_nick = select(3, jid_split(to)); | 218 local to_nick = select(3, jid_split(to)); |
| 273 if to_nick then | 219 if to_nick then |
| 274 log("debug", "%s (%s) changing nick to %s", current_nick, data.jid, to); | 220 log("debug", "%s (%s) changing nick to %s", current_nick, data.jid, to); |
| 275 -- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data)); | |
| 276 -- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data)); | |
| 277 local p = st.presence({type='unavailable', from=current_nick}); | 221 local p = st.presence({type='unavailable', from=current_nick}); |
| 278 --[[:tag('x', {xmlns='http://jabber.org/protocol/muc#user'}) | |
| 279 :tag('item', {affiliation=data.affiliation, role=data.role, nick=to_nick}):up() | |
| 280 :tag('status', {code='303'});]] | |
| 281 broadcast_presence_stanza(room, p, '303', to_nick); | 222 broadcast_presence_stanza(room, p, '303', to_nick); |
| 282 --broadcast_presence('unavailable', current_nick, room, '303', to_nick); | |
| 283 rooms:remove(room, current_nick); | 223 rooms:remove(room, current_nick); |
| 284 rooms:set(room, to, data); | 224 rooms:set(room, to, data); |
| 285 jid_nick:set(from, room, to); | 225 jid_nick:set(from, room, to); |
| 286 pr.attr.from = to; | 226 pr.attr.from = to; |
| 287 rooms:get(room, to).sessions[from] = pr; | 227 rooms:get(room, to).sessions[from] = pr; |
| 288 broadcast_presence_stanza(room, pr); | 228 broadcast_presence_stanza(room, pr); |
| 289 -- log("debug", "rooms: %s", require "util.serialization".serialize(rooms.data)); | |
| 290 -- log("debug", "jid_nick: %s", require "util.serialization".serialize(jid_nick.data)); | |
| 291 --broadcast_presence(nil, to, room, nil); | |
| 292 else | 229 else |
| 293 --TODO malformed-jid | 230 --TODO malformed-jid |
| 294 end | 231 end |
| 295 end | 232 end |
| 296 end | 233 end |
| 323 if r then | 260 if r then |
| 324 for occupant, o_data in pairs(r) do | 261 for occupant, o_data in pairs(r) do |
| 325 if occupant ~= to then | 262 if occupant ~= to then |
| 326 local pres = get_filtered_presence(o_data.sessions[o_data.jid]); | 263 local pres = get_filtered_presence(o_data.sessions[o_data.jid]); |
| 327 pres.attr.to, pres.attr.from = from, occupant; | 264 pres.attr.to, pres.attr.from = from, occupant; |
| 328 pres | 265 pres:tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) |
| 329 --local pres = st.presence({to=from, from=occupant}) | |
| 330 :tag("x", {xmlns='http://jabber.org/protocol/muc#user'}) | |
| 331 :tag("item", {affiliation=o_data.affiliation, role=o_data.role}):up(); | 266 :tag("item", {affiliation=o_data.affiliation, role=o_data.role}):up(); |
| 332 core_route_stanza(component, pres); | 267 core_route_stanza(component, pres); |
| 333 end | 268 end |
| 334 end | 269 end |
| 335 end | 270 end |
| 336 pr.attr.from = to; | 271 pr.attr.from = to; |
| 337 broadcast_presence_stanza(room, pr); | 272 broadcast_presence_stanza(room, pr); |
| 338 --broadcast_presence(nil, to, room); | |
| 339 local history = rooms_info:get(room, 'history'); -- send discussion history | 273 local history = rooms_info:get(room, 'history'); -- send discussion history |
| 340 if history then | 274 if history then |
| 341 for _, msg in ipairs(history) do | 275 for _, msg in ipairs(history) do |
| 342 msg = st.deserialize(msg); | 276 msg = st.deserialize(msg); |
| 343 msg.attr.to=from; | 277 msg.attr.to=from; |
| 404 stanza.attr.from = current_nick; | 338 stanza.attr.from = current_nick; |
| 405 local subject = getText(stanza, {"subject"}); | 339 local subject = getText(stanza, {"subject"}); |
| 406 if subject then | 340 if subject then |
| 407 set_subject(current_nick, room, subject); -- TODO use broadcast_message_stanza | 341 set_subject(current_nick, room, subject); -- TODO use broadcast_message_stanza |
| 408 else | 342 else |
| 409 --broadcast_message(current_nick, room, nil, getText(stanza, {"body"})); | |
| 410 broadcast_message_stanza(room, stanza, true); | 343 broadcast_message_stanza(room, stanza, true); |
| 411 end | 344 end |
| 412 end | 345 end |
| 413 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick | 346 elseif stanza.name == "presence" then -- hack - some buggy clients send presence updates to the room rather than their nick |
| 414 local to = stanza.attr.to; | 347 local to = stanza.attr.to; |
