# HG changeset patch # User Matthew Wild # Date 1594138088 -3600 # Node ID 92152437ecfea95cd6434488f97a42b03f18f2d8 # Parent b7c9e479e8571da7afb99ce8ff204fdb4d380f85 mod_muc_markers: replace configurable multi-marker tracking with better system Now tracks a single marker, but automatically applies rules from the XEP about "higher" markers implying "lower" markers - i.e. "displayed" implies "received". Still, just a single marker is tracked and synthesized at all times (the one configured with muc_marker_name). diff -r b7c9e479e857 -r 92152437ecfe mod_muc_markers/mod_muc_markers.lua --- a/mod_muc_markers/mod_muc_markers.lua Tue Jul 07 14:37:49 2020 +0200 +++ b/mod_muc_markers/mod_muc_markers.lua Tue Jul 07 17:08:08 2020 +0100 @@ -8,12 +8,29 @@ -- Notably Conversations will ack the origin-id instead. We need to update the XEP to -- clarify the correct behaviour. +local set = require "util.set"; local st = require "util.stanza"; local xmlns_markers = "urn:xmpp:chat-markers:0"; +local marker_order = { "received", "displayed", "acknowledged" }; + +-- Add reverse mapping +for priority, name in ipairs(marker_order) do + marker_order[name] = priority; +end + local marker_element_name = module:get_option_string("muc_marker_type", "displayed"); -local marker_element_names = module:get_option_set("muc_marker_types", { marker_element_name }); + +assert(marker_order[marker_element_name], "invalid marker name: "..marker_element_name); + +local marker_element_names = set.new(); + +-- "displayed" implies "received", etc. so we'll add the +-- chosen marker and any "higher" ones to the set +for i = marker_order[marker_element_name], #marker_order do + marker_element_names:add(marker_order[i]); +end local muc_marker_map_store = module:open_store("muc_markers", "map"); @@ -52,10 +69,10 @@ end); module:hook("muc-message-is-historic", function (event) - local marker = event.stanza:get_child("received", xmlns_markers); + local marker = event.stanza:get_child(nil, xmlns_markers) -- Prevent stanza from reaching the archive (it's just noise) - if marker then + if marker and marker_element_names:contains(marker.name) then return false end end); @@ -82,7 +99,7 @@ local room_nick = find_nickname(room, user_jid); if room_nick then local recv_marker = st.message({ type = "groupchat", from = room_nick, to = to }) - :tag("received", { xmlns = xmlns_markers, id = id }); + :tag(marker_element_name, { xmlns = xmlns_markers, id = id }); room:route_stanza(recv_marker); end end