comparison mod_muc_markers/mod_muc_markers.lua @ 4033:7b6bcb91493e

mod_muc_markers: Allow tracking multiple markers
author Matthew Wild <mwild1@gmail.com>
date Thu, 21 May 2020 16:35:07 +0100
parents 787fc3030087
children 554f64c8d0c0
comparison
equal deleted inserted replaced
4032:787fc3030087 4033:7b6bcb91493e
11 local st = require "util.stanza"; 11 local st = require "util.stanza";
12 12
13 local xmlns_markers = "urn:xmpp:chat-markers:0"; 13 local xmlns_markers = "urn:xmpp:chat-markers:0";
14 14
15 local marker_element_name = module:get_option_string("muc_marker_type", "displayed"); 15 local marker_element_name = module:get_option_string("muc_marker_type", "displayed");
16 local marker_element_names = module:get_option_set("muc_marker_types", { marker_element_name });
16 17
17 local muc_marker_map_store = module:open_store("muc_markers", "map"); 18 local muc_marker_map_store = module:open_store("muc_markers", "map");
18 19
19 local function get_stanza_id(stanza, by_jid) 20 local function get_stanza_id(stanza, by_jid)
20 for tag in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do 21 for tag in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do
37 -- Add markable element to request markers from clients 38 -- Add markable element to request markers from clients
38 stanza:tag("markable", { xmlns = xmlns_markers }):up(); 39 stanza:tag("markable", { xmlns = xmlns_markers }):up();
39 end, -1); 40 end, -1);
40 41
41 module:hook("muc-occupant-groupchat", function (event) 42 module:hook("muc-occupant-groupchat", function (event)
42 local marker = event.stanza:get_child(marker_element_name, xmlns_markers); 43 local marker = event.stanza:child_with_ns(xmlns_markers);
43 if not marker then return; end 44 if not marker or not marker_element_names:contains(marker.name) then
45 return; -- No marker, or not one we are interested in
46 end
44 47
45 -- Store the id that the user has received to 48 -- Store the id that the user has received to
46 module:log("warn", "New marker for %s: %s", event.occupant.bare_jid, marker.attr.id); 49 module:log("warn", "New marker for %s: %s", event.occupant.bare_jid, marker.attr.id);
47 muc_marker_map_store:set(event.occupant.bare_jid, event.room.jid, marker.attr.id); 50 muc_marker_map_store:set(event.occupant.bare_jid, event.room.jid, marker.attr.id);
48 51