Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(visitors): Sends msg history to new visitor nodes.

damenchod2f20c49afa0
diff --git a/resources/prosody-plugins/mod_fmuc.lua b/resources/prosody-plugins/mod_fmuc.lua
index e9344bce5a..dd7578c1f5 100644
--- a/resources/prosody-plugins/mod_fmuc.lua
+++ b/resources/prosody-plugins/mod_fmuc.lua
@@ -17,6 +17,7 @@ local filters = require 'util.filters';
local array = require 'util.array';
local set = require 'util.set';
local json = require 'cjson.safe';
+local datetime = require 'util.datetime';
local util = module:require 'util';
local is_admin = util.is_admin;
@@ -476,6 +477,46 @@ local function message_handler(event)
end
end
+-- Receives history messages from the main prosody and adds them to the local history
+-- this happens before the first participant joins and that participant gets the history using the standard flow on join
+local function history_message_handler(event)
+ local origin, stanza = event.origin, event.stanza;
+
+ local delay_elem = stanza:get_child('delay', 'urn:xmpp:delay');
+ if not delay_elem then
+ return;
+ end
+
+ -- now let's add it history, we do not use the event as we want to keep
+ -- the delay element
+ local room = get_room_from_jid(room_jid_match_rewrite(
+ jid.bare(stanza.attr.from):sub(1, -(main_domain:len() + 1))..local_domain));
+
+ if not room then
+ return;
+ end
+
+ if room:get_historylength() == 0 then
+ return;
+ end
+
+ local history = room._history;
+ if not history then history = {}; room._history = history; end
+
+ local history_stanza = st.clone(stanza);
+ history_stanza.attr.to = '';
+
+ local node, host, resource = jid.split(room_jid_match_rewrite(history_stanza.attr.from));
+ history_stanza.attr.from = jid.join(node, local_muc_domain, resource);
+ -- the from in the delay extension is still the main prosody jid, not used for now
+ local entry = { stanza = history_stanza, timestamp = datetime.parse(delay_elem.attr.stamp) };
+ table.insert(history, entry);
+ while #history > room:get_historylength() do table.remove(history, 1) end
+
+ return false;
+end
+module:hook('message/host', history_message_handler);
+
process_host_module(local_domain, function(host_module, host)
host_module:hook('iq/host', stanza_handler, 10);
host_module:hook('message/full', message_handler);
diff --git a/resources/prosody-plugins/mod_visitors.lua b/resources/prosody-plugins/mod_visitors.lua
index cc84ccbcf6..65a6370303 100644
--- a/resources/prosody-plugins/mod_visitors.lua
+++ b/resources/prosody-plugins/mod_visitors.lua
@@ -17,6 +17,7 @@ local is_admin = util.is_admin;
local presence_check_status = util.presence_check_status;
local process_host_module = util.process_host_module;
local is_transcriber_jigasi = util.is_transcriber_jigasi;
+local room_jid_match_rewrite = util.room_jid_match_rewrite;
local json = require 'cjson.safe';
-- Debug flag
@@ -167,6 +168,20 @@ local function connect_vnode(event)
-- send update initially so we can report the moderators that will join
send_visitors_iq(conference_service, room, 'update');
+ -- let's send message history
+ local event = {
+ room = room;
+ to = conference_service;
+ next_stanza = function() end; -- muc-get-history should define this iterator
+ };
+ module:context(main_muc_component_config):fire_event("muc-get-history", event);
+ for msg in event.next_stanza, event do
+ -- the messages stored in history has been stored before domain_mapper and
+ -- contain the virtual jid for a from
+ msg.attr.from = room_jid_match_rewrite(msg.attr.from);
+ room:route_stanza(msg);
+ end
+
for _, o in room:each_occupant() do
if not is_admin(o.bare_jid) then
local fmuc_pr = filter_stanza_nick_if_needed(st.clone(o:get_presence()), room);