73 lines
2.1 KiB
Lua
73 lines
2.1 KiB
Lua
-- Prosody IM
|
|
-- Copyright (C) 2008-2017 Matthew Wild
|
|
-- Copyright (C) 2008-2017 Waqas Hussain
|
|
-- Copyright (C) 2011-2017 Kim Alvefur
|
|
-- Copyright (C) 2011-2017 Stefan Sänger
|
|
--
|
|
-- This project is MIT/X11 licensed. Please see the
|
|
-- COPYING file in the source package for more information.
|
|
--
|
|
-- store groupchat messages from / to remote hosts based on mod_mam
|
|
--
|
|
|
|
local um = require "core.usermanager";
|
|
local st = require "util.stanza";
|
|
local rsm = require "util.rsm";
|
|
local jid_bare = require "util.jid".bare;
|
|
local jid_split = require "util.jid".split;
|
|
local jid_prepped_split = require "util.jid".prepped_split;
|
|
local host = module.host;
|
|
|
|
module:log("running on host: %s", host);
|
|
|
|
local archive_store = "muc_remote_inv";
|
|
local archive = module:open_store(archive_store, "archive");
|
|
|
|
|
|
|
|
local time_now = os.time;
|
|
local m_min = math.min;
|
|
local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse;
|
|
|
|
local function dumpTable(t, depth)
|
|
local result = "";
|
|
if (not depth) then depth = 0 end;
|
|
|
|
local prefix = string.rep(" ", depth);
|
|
|
|
if (type(t) ~= "table") then
|
|
result = result.." "..tostring(t);
|
|
else
|
|
for key,value in pairs(t) do
|
|
result = result..prefix..tostring(key).." => "..dumpTable(value, depth+1).."\n"
|
|
end
|
|
end
|
|
|
|
return result;
|
|
end
|
|
|
|
|
|
local function handle_vnc_invite(event)
|
|
-- module:log("info", "seen hooked invite from %s to %s", _to, _invitee);
|
|
|
|
-- module:log("info", "hooked event: %s ", dumpTable(event));
|
|
local muc_child = (event:get_child("x", "http://jabber.org/protocol/muc#user") or nil);
|
|
local room = event.attr.from or nil;
|
|
local to = event.attr.to or nil;
|
|
if (to) then
|
|
local to_node, to_host = jid_split(to);
|
|
local room_node, room_host = jid_split(room);
|
|
if not (prosody.hosts[to_host]) then
|
|
-- inviting remote user
|
|
module:log("info", "hooked room: %s => to: %s", room, to);
|
|
local with = to_node.."@"..to_host;
|
|
archive:append(room_node, nil, event, time_now(), with);
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-- Stanzas to local clients
|
|
module:hook("vnc-muc-invitation", handle_vnc_invite, 10);
|