Software /
code /
prosody-modules
Annotate
mod_csi_muc_priorities/mod_csi_muc_priorities.lua @ 6182:62ff93af69d5
mod_groups_internal: Remove broken links
author | Rémi Bardon <remi@remibardon.name> |
---|---|
date | Fri, 31 Jan 2025 02:13:19 +0100 (8 weeks ago) |
parent | 5997:d3812826c1cd |
child | 6211:750d64c47ec6 |
rev | line source |
---|---|
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
1 local jid_bare, jid_split = import("util.jid", "bare", "split"); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
2 |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
3 -- luacheck: ignore 122 |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
4 local user_sessions = prosody.hosts[module.host].sessions; |
3532
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 |
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 module:hook("csi-is-stanza-important", function (event) |
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local stanza, session = event.stanza, event.session; |
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 if stanza.name == "message" then |
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 if stanza.attr.type == "groupchat" then |
3534
700340b57851
mod_csi_muc_priorities: Break out room jid into a variable
Kim Alvefur <zash@zash.se>
parents:
3533
diff
changeset
|
10 local room_jid = jid_bare(stanza.attr.from); |
700340b57851
mod_csi_muc_priorities: Break out room jid into a variable
Kim Alvefur <zash@zash.se>
parents:
3533
diff
changeset
|
11 |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
12 local username = session.username; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
13 local priorities = user_sessions[username].csi_muc_priorities; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
14 |
3535
bcb0eb9121a9
mod_csi_muc_priorities: Add a comment
Kim Alvefur <zash@zash.se>
parents:
3534
diff
changeset
|
15 -- Look for mention |
3532
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local rooms = session.rooms_joined; |
3538
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
17 if rooms then |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
18 local body = stanza:get_child_text("body"); |
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
19 if not body then return end |
3538
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
20 local room_nick = rooms[room_jid]; |
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
21 if room_nick then |
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
22 if body:find(room_nick, 1, true) then |
4014
1b68954a743a
mod_csi_muc_priorities: Report reason for importance decision
Kim Alvefur <zash@zash.se>
parents:
3992
diff
changeset
|
23 event.reason = "muc mention"; |
3538
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
24 return true; |
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
25 end |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
26 -- Your own messages |
3539
6d51f44bc725
mod_csi_muc_priorities: Consider own MUC messages as important
Kim Alvefur <zash@zash.se>
parents:
3538
diff
changeset
|
27 if stanza.attr.from == (room_jid .. "/" .. room_nick) then |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
28 event.reason = "muc own message"; |
3539
6d51f44bc725
mod_csi_muc_priorities: Consider own MUC messages as important
Kim Alvefur <zash@zash.se>
parents:
3538
diff
changeset
|
29 return true; |
6d51f44bc725
mod_csi_muc_priorities: Consider own MUC messages as important
Kim Alvefur <zash@zash.se>
parents:
3538
diff
changeset
|
30 end |
3538
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
31 end |
946902fa4088
mod_csi_muc_priorities: Undo early return to make following commit clearer
Kim Alvefur <zash@zash.se>
parents:
3537
diff
changeset
|
32 end |
3628
2444fb3b05b7
mod_csi_muc_priorities: Signal unimportance (thanks tmolitor)
Kim Alvefur <zash@zash.se>
parents:
3601
diff
changeset
|
33 |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
34 -- No mentions found, check other logic: |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
35 -- deflaultlow=f or nil defaultlow=t |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
36 -- in high prio nil nil |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
37 -- in low prio false false |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
38 -- not in either nil false |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
39 -- |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
40 -- true means: important (always send immediately) |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
41 -- nil means: normal (respect other mods for stuff like grace period/reactions/etc) |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
42 -- false means: unimportant (delay sending) |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
43 if priorities then |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
44 local priority = priorities[room_jid]; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
45 if priority == false then -- low priority |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
46 event.reason = "muc priority"; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
47 return false; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
48 end |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
49 if priorities[false] and priorities[false]["defaultlow"] and not priority then -- defaultlow is false or nil or not high priority |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
50 event.reason = "muc user default low"; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
51 return false; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
52 end |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
53 end |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
54 |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
55 -- Standard importance and no mention, leave to other modules to decide for now |
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
56 return nil; |
3532
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 end |
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 end |
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 end); |
85c357b69eec
mod_csi_muc_priorities: Reduce importance of group chat messages
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
61 module:depends("adhoc"); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
62 |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
63 local dataform = require"util.dataforms"; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
64 local adhoc_inital_data = require "util.adhoc".new_initial_data_form; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
65 local instructions = [[ |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
66 These settings affect battery optimizations performed by the server |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
67 while your client has indicated that it is inactive. |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
68 ]] |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
69 |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
70 local priority_settings_form = dataform.new { |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
71 title = "Prioritize addresses of group chats"; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
72 instructions = instructions; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
73 { |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
74 type = "hidden"; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
75 name = "FORM_TYPE"; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
76 value = "xmpp:modules.prosody.im/mod_"..module.name; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
77 }; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
78 { |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
79 type = "jid-multi"; |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
80 name = "important"; |
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
81 label = "Higher priority"; |
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
82 desc = "Group chats more important to you"; |
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
83 }; |
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
84 { |
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
85 type = "jid-multi"; |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
86 name = "unimportant"; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
87 label = "Lower priority"; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
88 desc = "E.g. large noisy public channels"; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
89 }; |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
90 { |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
91 type = "boolean"; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
92 name = "defaultlow"; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
93 label = "Default to lower priority"; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
94 desc = "Mark all channels lower priority as default"; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
95 }; |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
96 } |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
97 |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
98 local store = module:open_store(); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
99 module:hook("resource-bind", function (event) |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
100 local username = event.session.username; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
101 user_sessions[username].csi_muc_priorities = store:get(username); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
102 end); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
103 |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
104 local adhoc_command_handler = adhoc_inital_data(priority_settings_form, function (data) |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
105 local username = jid_split(data.from); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
106 local prioritized_jids = user_sessions[username].csi_muc_priorities or store:get(username); |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
107 local important = {}; |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
108 local unimportant = {}; |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
109 local defaultlow = false; -- Default to high priority |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
110 if prioritized_jids then |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
111 for jid, priority in pairs(prioritized_jids) do |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
112 if jid then |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
113 if priority then |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
114 table.insert(important, jid); |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
115 else |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
116 table.insert(unimportant, jid); |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
117 end |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
118 end |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
119 end |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
120 table.sort(important); |
3537
7d6fb9570395
mod_csi_muc_priorities: Sort list of JIDs
Kim Alvefur <zash@zash.se>
parents:
3536
diff
changeset
|
121 table.sort(unimportant); |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
122 |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
123 if prioritized_jids[false] then |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
124 defaultlow = prioritized_jids[false]["defaultlow"]; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
125 end |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
126 end |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
127 |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
128 return { |
3988
569f754bd126
mod_csi_muc_priorities: Adjust indentation
Kim Alvefur <zash@zash.se>
parents:
3754
diff
changeset
|
129 important = important; |
569f754bd126
mod_csi_muc_priorities: Adjust indentation
Kim Alvefur <zash@zash.se>
parents:
3754
diff
changeset
|
130 unimportant = unimportant; |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
131 defaultlow = defaultlow |
3988
569f754bd126
mod_csi_muc_priorities: Adjust indentation
Kim Alvefur <zash@zash.se>
parents:
3754
diff
changeset
|
132 }; |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
133 end, function(fields, form_err, data) |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
134 if form_err then |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
135 return { status = "completed", error = { message = "Problem in submitted form" } }; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
136 end |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
137 local prioritized_jids = {}; |
3601
013ef96a6d4d
mod_csi_muc_priorities: Fix traceback due to empty field
Kim Alvefur <zash@zash.se>
parents:
3540
diff
changeset
|
138 if fields.unimportant then |
5992
bdfb0ed56399
mod_csi_muc_priorities: Fix saving list with only high-priority MUCs (thanks aereaux)
Kim Alvefur <zash@zash.se>
parents:
4014
diff
changeset
|
139 for _, jid in ipairs(fields.unimportant) do |
bdfb0ed56399
mod_csi_muc_priorities: Fix saving list with only high-priority MUCs (thanks aereaux)
Kim Alvefur <zash@zash.se>
parents:
4014
diff
changeset
|
140 prioritized_jids[jid] = false; |
3601
013ef96a6d4d
mod_csi_muc_priorities: Fix traceback due to empty field
Kim Alvefur <zash@zash.se>
parents:
3540
diff
changeset
|
141 end |
5992
bdfb0ed56399
mod_csi_muc_priorities: Fix saving list with only high-priority MUCs (thanks aereaux)
Kim Alvefur <zash@zash.se>
parents:
4014
diff
changeset
|
142 end |
bdfb0ed56399
mod_csi_muc_priorities: Fix saving list with only high-priority MUCs (thanks aereaux)
Kim Alvefur <zash@zash.se>
parents:
4014
diff
changeset
|
143 if fields.important then |
bdfb0ed56399
mod_csi_muc_priorities: Fix saving list with only high-priority MUCs (thanks aereaux)
Kim Alvefur <zash@zash.se>
parents:
4014
diff
changeset
|
144 for _, jid in ipairs(fields.important) do |
bdfb0ed56399
mod_csi_muc_priorities: Fix saving list with only high-priority MUCs (thanks aereaux)
Kim Alvefur <zash@zash.se>
parents:
4014
diff
changeset
|
145 prioritized_jids[jid] = true; |
3754
d77a61d81555
mod_csi_muc_priorities: Add a high priority list (BC)
Kim Alvefur <zash@zash.se>
parents:
3628
diff
changeset
|
146 end |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
147 end |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
148 |
5997
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
149 local misc_data = {defaultlow = fields.defaultlow}; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
150 prioritized_jids[false] = misc_data; |
d3812826c1cd
mod_csi_muc_priorities: Allow setting the default priority for mucs to low
aereaux <aidan@jmad.org>
parents:
5992
diff
changeset
|
151 |
3536
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
152 local username = jid_split(data.from); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
153 local ok, err = store:set(username, prioritized_jids); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
154 if ok then |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
155 user_sessions[username].csi_muc_priorities = prioritized_jids; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
156 return { status = "completed", info = "Priorities updated" }; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
157 else |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
158 return { status = "completed", error = { message = "Error saving priorities: "..err } }; |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
159 end |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
160 end); |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
161 |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
162 module:add_item("adhoc", module:require "adhoc".new("Configure group chat priorities", |
eed657091329
mod_csi_muc_priorities: Allow specifying which MUC JIDs are less important
Kim Alvefur <zash@zash.se>
parents:
3535
diff
changeset
|
163 "xmpp:modules.prosody.im/mod_"..module.name, adhoc_command_handler, "local_user")); |