Comparison

plugins/groupchat.lua @ 187:7ad218bd5fde

plugins.groupchat: Fix prev commit.
author Kim Alvefur <zash@zash.se>
date Tue, 25 Jan 2011 19:33:15 +0100
parent 186:bb34b8bc00ae
child 189:033f1bd7420d
comparison
equal deleted inserted replaced
186:bb34b8bc00ae 187:7ad218bd5fde
11 stream:add_plugin("presence") 11 stream:add_plugin("presence")
12 stream.rooms = {}; 12 stream.rooms = {};
13 13
14 stream:hook("stanza", function (stanza) 14 stream:hook("stanza", function (stanza)
15 local room_jid = jid.bare(stanza.attr.from); 15 local room_jid = jid.bare(stanza.attr.from);
16 local room = stream.rooms[room_jid] or stream.rooms[stanza.attr.to.." "..room_jid] or nil 16 if not room_jid then return end
17 local room = stream.rooms[room_jid]
18 if not room and stanza.attr.to and room_jid then
19 room = stream.rooms[stanza.attr.to.." "..room_jid]
20 end
17 if room and room.opts.source and stanza.attr.to ~= room.opts.source then return end 21 if room and room.opts.source and stanza.attr.to ~= room.opts.source then return end
18 if room then 22 if room then
19 local nick = select(3, jid.split(stanza.attr.from)); 23 local nick = select(3, jid.split(stanza.attr.from));
20 local body = stanza:get_child("body"); 24 local body = stanza:get_child("body");
21 local delay = stanza:get_child("delay", xmlns_delay); 25 local delay = stanza:get_child("delay", xmlns_delay);
35 39
36 function stream:join_room(jid, nick, opts) 40 function stream:join_room(jid, nick, opts)
37 if not nick then 41 if not nick then
38 return false, "no nickname supplied" 42 return false, "no nickname supplied"
39 end 43 end
44 opts = opts or {};
40 local room = setmetatable({ 45 local room = setmetatable({
41 stream = stream, jid = jid, nick = nick, 46 stream = stream, jid = jid, nick = nick,
42 subject = nil, 47 subject = nil,
43 occupants = {}, 48 occupants = {},
44 opts = opts, 49 opts = opts,
114 119
115 function room_mt:send(stanza) 120 function room_mt:send(stanza)
116 if stanza.name == "message" and not stanza.attr.type then 121 if stanza.name == "message" and not stanza.attr.type then
117 stanza.attr.type = "groupchat"; 122 stanza.attr.type = "groupchat";
118 end 123 end
119 if stanza.name == "presence" or not stanza.attr.to then 124 if stanza.name == "presence" then
120 stanza.attr.to = self.jid .."/"..self.nick; 125 stanza.attr.to = self.jid .."/"..self.nick;
121 end 126 end
122 if stanza.attr.type == "groupchat" or not stanza.attr.to then 127 if stanza.attr.type == "groupchat" or not stanza.attr.to then
123 stanza.attr.to = self.jid; 128 stanza.attr.to = self.jid;
124 end 129 end