comparison mod_muc_markers/mod_muc_markers.lua @ 4024:95882b487ed2

mod_muc_markers: Allow configuration of which marker to track, default to displayed
author Matthew Wild <mwild1@gmail.com>
date Tue, 19 May 2020 14:06:42 +0100
parents 45c5603a6c07
children 57b4cdeba318
comparison
equal deleted inserted replaced
4023:7e2db4d61f6c 4024:95882b487ed2
7 -- is what some clients implement. 7 -- is what some clients implement.
8 -- Notably Conversations will ack the origin-id instead. We need to update the XEP to 8 -- Notably Conversations will ack the origin-id instead. We need to update the XEP to
9 -- clarify the correct behaviour. 9 -- clarify the correct behaviour.
10 10
11 local xmlns_markers = "urn:xmpp:chat-markers:0"; 11 local xmlns_markers = "urn:xmpp:chat-markers:0";
12
13 local marker_element_name = module:get_option_string("muc_marker_type", "displayed");
12 14
13 local muc_marker_map_store = module:open_store("muc_markers", "map"); 15 local muc_marker_map_store = module:open_store("muc_markers", "map");
14 16
15 local function get_stanza_id(stanza, by_jid) 17 local function get_stanza_id(stanza, by_jid)
16 for tag in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do 18 for tag in stanza:childtags("stanza-id", "urn:xmpp:sid:0") do
33 -- Add markable element to request markers from clients 35 -- Add markable element to request markers from clients
34 stanza:tag("markable", { xmlns = xmlns_markers }):up(); 36 stanza:tag("markable", { xmlns = xmlns_markers }):up();
35 end, -1); 37 end, -1);
36 38
37 module:hook("muc-occupant-groupchat", function (event) 39 module:hook("muc-occupant-groupchat", function (event)
38 local marker = event.stanza:get_child("received", xmlns_markers); 40 local marker = event.stanza:get_child(marker_element_name, xmlns_markers);
39 if not marker then return; end 41 if not marker then return; end
40 42
41 -- Store the id that the user has received to 43 -- Store the id that the user has received to
42 module:log("warn", "New marker for %s: %s", event.occupant.bare_jid, marker.attr.id); 44 module:log("warn", "New marker for %s: %s", event.occupant.bare_jid, marker.attr.id);
43 muc_marker_map_store:set(event.occupant.bare_jid, event.room.jid, marker.attr.id); 45 muc_marker_map_store:set(event.occupant.bare_jid, event.room.jid, marker.attr.id);