Software /
code /
prosody-modules
Changeset
3754:d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
This changes the default priority to mention-only.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 25 Aug 2019 20:59:05 +0200 |
parents | 3753:cf3247ec5e01 |
children | 3755:bb18a1f5e9d7 |
files | mod_csi_muc_priorities/mod_csi_muc_priorities.lua |
diffstat | 1 files changed, 31 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_csi_muc_priorities/mod_csi_muc_priorities.lua Sun Nov 17 16:34:56 2019 +0100 +++ b/mod_csi_muc_priorities/mod_csi_muc_priorities.lua Sun Aug 25 20:59:05 2019 +0200 @@ -7,37 +7,37 @@ local stanza, session = event.stanza, event.session; if stanza.name == "message" then if stanza.attr.type == "groupchat" then - local body = stanza:get_child_text("body"); - if not body then return end - local room_jid = jid_bare(stanza.attr.from); local username = session.username; local priorities = user_sessions[username].csi_muc_priorities; - if not priorities or priorities[room_jid] ~= false then - return nil; + if priorities then + local priority = priorities[room_jid]; + if priority ~= nil then + return priority; + end end -- Look for mention local rooms = session.rooms_joined; if rooms then + local body = stanza:get_child_text("body"); + if not body then return end local room_nick = rooms[room_jid]; if room_nick then if body:find(room_nick, 1, true) then return true; end + -- Your own messages if stanza.attr.from == (room_jid .. "/" .. room_nick) then return true; end end - elseif session.directed and session.directed[stanza.attr.from] then - -- fallback if no mod_track_muc_joins - return true; end - -- Unimportant and no mention - return false; + -- Standard importance and no mention, leave to other modules to decide for now + return nil; end end end); @@ -61,6 +61,12 @@ }; { type = "jid-multi"; + name = "important"; + label = "Higher priority"; + desc = "Group chats more important to you"; + }; + { + type = "jid-multi"; name = "unimportant"; label = "Lower priority"; desc = "E.g. large noisy public channels"; @@ -76,14 +82,23 @@ local adhoc_command_handler = adhoc_inital_data(priority_settings_form, function (data) local username = jid_split(data.from); local prioritized_jids = user_sessions[username].csi_muc_priorities or store:get(username); + local important = {}; local unimportant = {}; if prioritized_jids then - for jid in pairs(prioritized_jids) do - table.insert(unimportant, jid); + for jid, priority in pairs(prioritized_jids) do + if priority then + table.insert(important, jid); + else + table.insert(unimportant, jid); + end end + table.sort(important); table.sort(unimportant); end - return { unimportant = unimportant }; + return { + important = important; + unimportant = unimportant; +}; end, function(fields, form_err, data) if form_err then return { status = "completed", error = { message = "Problem in submitted form" } }; @@ -93,6 +108,9 @@ for _, jid in ipairs(fields.unimportant) do prioritized_jids[jid] = false; end + for _, jid in ipairs(fields.important) do + prioritized_jids[jid] = true; + end end local username = jid_split(data.from);