Mercurial > prosody-modules
comparison mod_muc_inject_mentions/mod_muc_inject_mentions.lua @ 4253:32b4901a9d8d
mod_muc_inject_mentions: Add new setting to trigger mentions only if a prefix is found
author | Seve Ferrer <seve@delape.net> |
---|---|
date | Tue, 17 Nov 2020 13:45:33 +0100 |
parents | aed7038ab2ab |
children | a6c253bc63a5 |
comparison
equal
deleted
inserted
replaced
4252:1327e1e1c94e | 4253:32b4901a9d8d |
---|---|
9 local disabled_rooms = module:get_option("muc_inject_mentions_disabled_rooms", nil) | 9 local disabled_rooms = module:get_option("muc_inject_mentions_disabled_rooms", nil) |
10 local mention_delimiters = module:get_option_set("muc_inject_mentions_mention_delimiters", {" ", "", "\n", "\t"}) | 10 local mention_delimiters = module:get_option_set("muc_inject_mentions_mention_delimiters", {" ", "", "\n", "\t"}) |
11 local append_mentions = module:get_option("muc_inject_mentions_append_mentions", false) | 11 local append_mentions = module:get_option("muc_inject_mentions_append_mentions", false) |
12 local strip_out_prefixes = module:get_option("muc_inject_mentions_strip_out_prefixes", false) | 12 local strip_out_prefixes = module:get_option("muc_inject_mentions_strip_out_prefixes", false) |
13 local reserved_nicks = module:get_option("muc_inject_mentions_reserved_nicks", false) | 13 local reserved_nicks = module:get_option("muc_inject_mentions_reserved_nicks", false) |
14 local use_real_jid = module:get_option("muc_inject_mentions_use_real_jid", false) | 14 local use_bare_jid = module:get_option("muc_inject_mentions_use_bare_jid", true) |
15 local prefix_mandatory = module:get_option("muc_inject_mentions_prefix_mandatory", false) | |
15 local reserved_nicknames = {} | 16 local reserved_nicknames = {} |
16 | 17 |
17 local reference_xmlns = "urn:xmpp:reference:0" | 18 local reference_xmlns = "urn:xmpp:reference:0" |
18 | 19 |
19 local function update_reserved_nicknames(event) | 20 local function update_reserved_nicknames(event) |
48 end | 49 end |
49 end | 50 end |
50 end | 51 end |
51 | 52 |
52 local function get_jid(room, nickname) | 53 local function get_jid(room, nickname) |
53 local real_jid = reserved_nicknames[room.jid][nickname] | 54 local bare_jid = reserved_nicknames[room.jid][nickname] |
54 if real_jid and use_real_jid then | 55 if bare_jid and use_bare_jid then |
55 return real_jid | 56 return bare_jid |
56 end | 57 end |
57 | 58 |
58 if real_jid and not use_real_jid then | 59 if bare_jid and not use_bare_jid then |
59 return room.jid .. "/" .. nickname | 60 return room.jid .. "/" .. nickname |
60 end | 61 end |
61 end | 62 end |
62 | 63 |
63 local function get_participants(room) | 64 local function get_participants(room) |
191 -- Mention delimiter found, current_word is completed now | 192 -- Mention delimiter found, current_word is completed now |
192 if mention_delimiters:contains(char) and current_word_start then | 193 if mention_delimiters:contains(char) and current_word_start then |
193 -- Check for nickname without prefix | 194 -- Check for nickname without prefix |
194 local jid = get_jid(room, current_word) | 195 local jid = get_jid(room, current_word) |
195 if jid then | 196 if jid then |
196 add_mention(mentions, jid, current_word_start, i - 1, prefix_indices, false) | 197 if not prefix_mandatory then |
198 add_mention(mentions, jid, current_word_start, i - 1, prefix_indices, false) | |
199 end | |
197 else | 200 else |
198 -- Check for nickname with affixes | 201 -- Check for nickname with affixes |
199 local prefix = prefixes:contains(current_word:sub(1,1)) | 202 local prefix = prefixes:contains(current_word:sub(1,1)) |
200 local suffix = suffixes:contains(current_word:sub(-1)) | 203 local suffix = suffixes:contains(current_word:sub(-1)) |
201 if prefix and suffix then | 204 if prefix and suffix then |
206 elseif prefix then | 209 elseif prefix then |
207 jid = get_jid(room, current_word:sub(2)) | 210 jid = get_jid(room, current_word:sub(2)) |
208 if jid then | 211 if jid then |
209 add_mention(mentions, jid, current_word_start + 1, i - 1, prefix_indices, true) | 212 add_mention(mentions, jid, current_word_start + 1, i - 1, prefix_indices, true) |
210 end | 213 end |
211 elseif suffix then | 214 elseif suffix and not prefix_mandatory then |
212 jid = get_jid(room, current_word:sub(1, -2)) | 215 jid = get_jid(room, current_word:sub(1, -2)) |
213 if jid then | 216 if jid then |
214 add_mention(mentions, jid, current_word_start, i - 2, prefix_indices, false) | 217 add_mention(mentions, jid, current_word_start, i - 2, prefix_indices, false) |
215 end | 218 end |
216 end | 219 end |