Comparison

mod_muc_limits/mod_muc_limits.lua @ 1428:091ee76745e8

mod_muc_limits: Make compatible with new MUC API
author Vadim Misbakh-Soloviov <mva@mva.name>
date Sun, 01 Jun 2014 16:08:05 +0700
parent 1205:7d2d440e2fa5
child 1768:163967467308
comparison
equal deleted inserted replaced
1427:322a076f53e8 1428:091ee76745e8
1 1
2 if not hosts[module.host].modules.muc then 2 local rooms = module:shared "muc/rooms";
3 if not rooms then
3 module:log("error", "This module only works on MUC components!"); 4 module:log("error", "This module only works on MUC components!");
4 return; 5 return;
5 end 6 end
6 7
7 local jid_split, jid_bare = require "util.jid".split, require "util.jid".bare; 8 local jid_split, jid_bare = require "util.jid".split, require "util.jid".bare;
8 local st = require "util.stanza"; 9 local st = require "util.stanza";
9 local new_throttle = require "util.throttle".create; 10 local new_throttle = require "util.throttle".create;
10 local t_insert, t_concat = table.insert, table.concat; 11 local t_insert, t_concat = table.insert, table.concat;
11 local hosts = prosody.hosts;
12 12
13 local xmlns_muc = "http://jabber.org/protocol/muc"; 13 local xmlns_muc = "http://jabber.org/protocol/muc";
14 14
15 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0); 15 local period = math.max(module:get_option_number("muc_event_rate", 0.5), 0);
16 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1); 16 local burst = math.max(module:get_option_number("muc_burst_factor", 6), 1);
29 local origin, stanza = event.origin, event.stanza; 29 local origin, stanza = event.origin, event.stanza;
30 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving 30 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving
31 return; 31 return;
32 end 32 end
33 local dest_room, dest_host, dest_nick = jid_split(stanza.attr.to); 33 local dest_room, dest_host, dest_nick = jid_split(stanza.attr.to);
34 local room = hosts[module.host].modules.muc.rooms[dest_room.."@"..dest_host]; 34 local room = rooms[dest_room.."@"..dest_host];
35 if not room then return; end 35 if not room then return; end
36 local from_jid = stanza.attr.from; 36 local from_jid = stanza.attr.from;
37 local occupant = room._occupants[room._jid_nick[from_jid]]; 37 local occupant = room._occupants[room._jid_nick[from_jid]];
38 if (occupant and occupant.affiliation) or (not(occupant) and room._affiliations[jid_bare(from_jid)]) then 38 if (occupant and occupant.affiliation) or (not(occupant) and room._affiliations[jid_bare(from_jid)]) then
39 module:log("debug", "Skipping stanza from affiliated user..."); 39 module:log("debug", "Skipping stanza from affiliated user...");
75 return true; 75 return true;
76 end 76 end
77 end 77 end
78 78
79 function module.unload() 79 function module.unload()
80 for room_jid, room in pairs(hosts[module.host].modules.muc.rooms) do 80 for room_jid, room in pairs(rooms) do
81 room.throttle = nil; 81 room.throttle = nil;
82 end 82 end
83 end 83 end
84 84
85 module:hook("message/bare", handle_stanza, 501); 85 module:hook("message/bare", handle_stanza, 501);