changeset 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 (2020-11-17)
parents 1327e1e1c94e
children a4e182d7ff0a
files mod_muc_inject_mentions/README.markdown mod_muc_inject_mentions/mod_muc_inject_mentions.lua
diffstat 2 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mod_muc_inject_mentions/README.markdown	Sun Nov 15 19:07:34 2020 +0100
+++ b/mod_muc_inject_mentions/README.markdown	Tue Nov 17 13:45:33 2020 +0100
@@ -91,10 +91,21 @@
 This can be changed using:
 
 ```
--- muc_inject_mentions_mention_delimiters =  {" ", "", "\n"}
+-- muc_inject_mentions_mention_delimiters =  {" ", "", "\n", "\t"}
 ```
 Generally speaking and unless the use-case is very specific, there should be no need to modify the defaults of this setting.
 
+When triggering a mention must only happen if that mention includes a prefix, this can be configured with:
+```
+-- muc_inject_mentions_prefix_mandatory = true
+```
+
+By default, mentions use the bare jid of the participant as the URI attribute.
+If the MUC jid of the participant (eg. room@chat.example.org/Romeo) is preferred, this can be set using:
+```
+-- muc_inject_mentions_use_real_jid = false
+```
+
 
 # Example stanzas
 
--- a/mod_muc_inject_mentions/mod_muc_inject_mentions.lua	Sun Nov 15 19:07:34 2020 +0100
+++ b/mod_muc_inject_mentions/mod_muc_inject_mentions.lua	Tue Nov 17 13:45:33 2020 +0100
@@ -11,7 +11,8 @@
 local append_mentions = module:get_option("muc_inject_mentions_append_mentions", false)
 local strip_out_prefixes = module:get_option("muc_inject_mentions_strip_out_prefixes", false)
 local reserved_nicks = module:get_option("muc_inject_mentions_reserved_nicks", false)
-local use_real_jid = module:get_option("muc_inject_mentions_use_real_jid", false)
+local use_bare_jid = module:get_option("muc_inject_mentions_use_bare_jid", true)
+local prefix_mandatory = module:get_option("muc_inject_mentions_prefix_mandatory", false)
 local reserved_nicknames = {}
 
 local reference_xmlns = "urn:xmpp:reference:0"
@@ -50,12 +51,12 @@
 end
 
 local function get_jid(room, nickname)
-    local real_jid = reserved_nicknames[room.jid][nickname]
-    if real_jid and use_real_jid then
-        return real_jid
+    local bare_jid = reserved_nicknames[room.jid][nickname]
+    if bare_jid and use_bare_jid then
+        return bare_jid
     end
 
-    if real_jid and not use_real_jid then
+    if bare_jid and not use_bare_jid then
         return room.jid .. "/" .. nickname
     end
 end
@@ -193,7 +194,9 @@
             -- Check for nickname without prefix
             local jid = get_jid(room, current_word)
             if jid then
-                add_mention(mentions, jid, current_word_start, i - 1, prefix_indices, false)
+                if not prefix_mandatory then
+                    add_mention(mentions, jid, current_word_start, i - 1, prefix_indices, false)
+                end
             else
                 -- Check for nickname with affixes
                 local prefix = prefixes:contains(current_word:sub(1,1))
@@ -208,7 +211,7 @@
                     if jid then
                         add_mention(mentions, jid, current_word_start + 1, i - 1, prefix_indices, true)
                     end
-                elseif suffix then
+                elseif suffix and not prefix_mandatory then
                     jid = get_jid(room, current_word:sub(1, -2))
                     if jid then
                         add_mention(mentions, jid, current_word_start, i - 2, prefix_indices, false)