Software /
code /
prosody-modules
Comparison
mod_muc_limits/mod_muc_limits.lua @ 3417:1534d0715d35
mod_muc_limits: Add support for new MUC API in Prosody 0.11
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 23 Dec 2018 21:46:06 +0100 |
parent | 3402:6a3060d5e85d |
child | 3418:9be9dd434813 |
comparison
equal
deleted
inserted
replaced
3416:c6dd65354db0 | 3417:1534d0715d35 |
---|---|
1 | 1 |
2 local mod_muc = module:depends"muc"; | 2 local mod_muc = module:depends"muc"; |
3 local rooms = rawget(mod_muc, "rooms"); -- Old MUC API | 3 local rooms = rawget(mod_muc, "rooms"); -- Old MUC API |
4 if not rooms then | |
5 error "Not compatible with 0.11 MUC API" | |
6 end | |
7 | 4 |
8 local jid_split, jid_bare = require "util.jid".split, require "util.jid".bare; | 5 local jid_split, jid_bare = require "util.jid".split, require "util.jid".bare; |
9 local st = require "util.stanza"; | 6 local st = require "util.stanza"; |
10 local new_throttle = require "util.throttle".create; | 7 local new_throttle = require "util.throttle".create; |
11 local t_insert, t_concat = table.insert, table.concat; | 8 local t_insert, t_concat = table.insert, table.concat; |
29 local origin, stanza = event.origin, event.stanza; | 26 local origin, stanza = event.origin, event.stanza; |
30 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving | 27 if stanza.name == "presence" and stanza.attr.type == "unavailable" then -- Don't limit room leaving |
31 return; | 28 return; |
32 end | 29 end |
33 local dest_room, dest_host, dest_nick = jid_split(stanza.attr.to); | 30 local dest_room, dest_host, dest_nick = jid_split(stanza.attr.to); |
34 local room = rooms[dest_room.."@"..dest_host]; | 31 local room = event.room or rooms[dest_room.."@"..dest_host]; |
35 if not room then return; end | 32 if not room then return; end |
36 local from_jid = stanza.attr.from; | 33 local from_jid = stanza.attr.from; |
37 local occupant = room._occupants[room._jid_nick[from_jid]]; | 34 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 | 35 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..."); | 36 module:log("debug", "Skipping stanza from affiliated user..."); |
80 for room_jid, room in pairs(rooms) do | 77 for room_jid, room in pairs(rooms) do |
81 room.throttle = nil; | 78 room.throttle = nil; |
82 end | 79 end |
83 end | 80 end |
84 | 81 |
85 module:hook("message/bare", handle_stanza, 501); | 82 if rooms then |
86 module:hook("message/full", handle_stanza, 501); | 83 module:hook("message/bare", handle_stanza, 501); |
87 module:hook("presence/bare", handle_stanza, 501); | 84 module:hook("message/full", handle_stanza, 501); |
88 module:hook("presence/full", handle_stanza, 501); | 85 module:hook("presence/bare", handle_stanza, 501); |
86 module:hook("presence/full", handle_stanza, 501); | |
87 else | |
88 module:hook("muc-occupant-pre-join", handle_stanza); | |
89 module:hook("muc-occupant-pre-change", handle_stanza); | |
90 module:hook("muc-occupant-groupchat", handle_stanza); | |
91 end |