Software / code / prosody-modules
Comparison
mod_csi_muc_priorities/mod_csi_muc_priorities.lua @ 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 |
| parent | 3628:2444fb3b05b7 |
| child | 3988:569f754bd126 |
comparison
equal
deleted
inserted
replaced
| 3753:cf3247ec5e01 | 3754:d77a61d81555 |
|---|---|
| 5 | 5 |
| 6 module:hook("csi-is-stanza-important", function (event) | 6 module:hook("csi-is-stanza-important", function (event) |
| 7 local stanza, session = event.stanza, event.session; | 7 local stanza, session = event.stanza, event.session; |
| 8 if stanza.name == "message" then | 8 if stanza.name == "message" then |
| 9 if stanza.attr.type == "groupchat" then | 9 if stanza.attr.type == "groupchat" then |
| 10 local body = stanza:get_child_text("body"); | |
| 11 if not body then return end | |
| 12 | |
| 13 local room_jid = jid_bare(stanza.attr.from); | 10 local room_jid = jid_bare(stanza.attr.from); |
| 14 | 11 |
| 15 local username = session.username; | 12 local username = session.username; |
| 16 local priorities = user_sessions[username].csi_muc_priorities; | 13 local priorities = user_sessions[username].csi_muc_priorities; |
| 17 | 14 |
| 18 if not priorities or priorities[room_jid] ~= false then | 15 if priorities then |
| 19 return nil; | 16 local priority = priorities[room_jid]; |
| 17 if priority ~= nil then | |
| 18 return priority; | |
| 19 end | |
| 20 end | 20 end |
| 21 | 21 |
| 22 -- Look for mention | 22 -- Look for mention |
| 23 local rooms = session.rooms_joined; | 23 local rooms = session.rooms_joined; |
| 24 if rooms then | 24 if rooms then |
| 25 local body = stanza:get_child_text("body"); | |
| 26 if not body then return end | |
| 25 local room_nick = rooms[room_jid]; | 27 local room_nick = rooms[room_jid]; |
| 26 if room_nick then | 28 if room_nick then |
| 27 if body:find(room_nick, 1, true) then | 29 if body:find(room_nick, 1, true) then |
| 28 return true; | 30 return true; |
| 29 end | 31 end |
| 32 -- Your own messages | |
| 30 if stanza.attr.from == (room_jid .. "/" .. room_nick) then | 33 if stanza.attr.from == (room_jid .. "/" .. room_nick) then |
| 31 return true; | 34 return true; |
| 32 end | 35 end |
| 33 end | 36 end |
| 34 elseif session.directed and session.directed[stanza.attr.from] then | |
| 35 -- fallback if no mod_track_muc_joins | |
| 36 return true; | |
| 37 end | 37 end |
| 38 | 38 |
| 39 -- Unimportant and no mention | 39 -- Standard importance and no mention, leave to other modules to decide for now |
| 40 return false; | 40 return nil; |
| 41 end | 41 end |
| 42 end | 42 end |
| 43 end); | 43 end); |
| 44 | 44 |
| 45 module:depends("adhoc"); | 45 module:depends("adhoc"); |
| 59 name = "FORM_TYPE"; | 59 name = "FORM_TYPE"; |
| 60 value = "xmpp:modules.prosody.im/mod_"..module.name; | 60 value = "xmpp:modules.prosody.im/mod_"..module.name; |
| 61 }; | 61 }; |
| 62 { | 62 { |
| 63 type = "jid-multi"; | 63 type = "jid-multi"; |
| 64 name = "important"; | |
| 65 label = "Higher priority"; | |
| 66 desc = "Group chats more important to you"; | |
| 67 }; | |
| 68 { | |
| 69 type = "jid-multi"; | |
| 64 name = "unimportant"; | 70 name = "unimportant"; |
| 65 label = "Lower priority"; | 71 label = "Lower priority"; |
| 66 desc = "E.g. large noisy public channels"; | 72 desc = "E.g. large noisy public channels"; |
| 67 }; | 73 }; |
| 68 } | 74 } |
| 74 end); | 80 end); |
| 75 | 81 |
| 76 local adhoc_command_handler = adhoc_inital_data(priority_settings_form, function (data) | 82 local adhoc_command_handler = adhoc_inital_data(priority_settings_form, function (data) |
| 77 local username = jid_split(data.from); | 83 local username = jid_split(data.from); |
| 78 local prioritized_jids = user_sessions[username].csi_muc_priorities or store:get(username); | 84 local prioritized_jids = user_sessions[username].csi_muc_priorities or store:get(username); |
| 85 local important = {}; | |
| 79 local unimportant = {}; | 86 local unimportant = {}; |
| 80 if prioritized_jids then | 87 if prioritized_jids then |
| 81 for jid in pairs(prioritized_jids) do | 88 for jid, priority in pairs(prioritized_jids) do |
| 82 table.insert(unimportant, jid); | 89 if priority then |
| 90 table.insert(important, jid); | |
| 91 else | |
| 92 table.insert(unimportant, jid); | |
| 93 end | |
| 83 end | 94 end |
| 95 table.sort(important); | |
| 84 table.sort(unimportant); | 96 table.sort(unimportant); |
| 85 end | 97 end |
| 86 return { unimportant = unimportant }; | 98 return { |
| 99 important = important; | |
| 100 unimportant = unimportant; | |
| 101 }; | |
| 87 end, function(fields, form_err, data) | 102 end, function(fields, form_err, data) |
| 88 if form_err then | 103 if form_err then |
| 89 return { status = "completed", error = { message = "Problem in submitted form" } }; | 104 return { status = "completed", error = { message = "Problem in submitted form" } }; |
| 90 end | 105 end |
| 91 local prioritized_jids = {}; | 106 local prioritized_jids = {}; |
| 92 if fields.unimportant then | 107 if fields.unimportant then |
| 93 for _, jid in ipairs(fields.unimportant) do | 108 for _, jid in ipairs(fields.unimportant) do |
| 94 prioritized_jids[jid] = false; | 109 prioritized_jids[jid] = false; |
| 110 end | |
| 111 for _, jid in ipairs(fields.important) do | |
| 112 prioritized_jids[jid] = true; | |
| 95 end | 113 end |
| 96 end | 114 end |
| 97 | 115 |
| 98 local username = jid_split(data.from); | 116 local username = jid_split(data.from); |
| 99 local ok, err = store:set(username, prioritized_jids); | 117 local ok, err = store:set(username, prioritized_jids); |