Mercurial > prosody-modules
annotate mod_muc_inject_mentions/mod_muc_inject_mentions.lua @ 4249:64aa1d9d70ac
mod_rest: Catch and log errors in callback promise chain
From the code it looks like it should be possible to reply to an error
stanza, but it did not. Turns out I was saved by my local developer mode
module which throws errors if an attempt is made to create an errror
reply to an error stanza. However nothing collects this error from the
promise, so all I got was confusion.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 15 Nov 2020 16:25:49 +0100 |
parents | aed7038ab2ab |
children | 32b4901a9d8d |
rev | line source |
---|---|
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
1 module:depends("muc"); |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
2 |
4140
fea4a4831e10
mod_muc_inject_mentions: (W211) unused variable node, (W211) unused variable host
Seve Ferrer <seve@delape.net>
parents:
4139
diff
changeset
|
3 local jid_resource = require "util.jid".resource; |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
4 local st = require "util.stanza"; |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
5 |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
6 local prefixes = module:get_option_set("muc_inject_mentions_prefixes", {}) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
7 local suffixes = module:get_option_set("muc_inject_mentions_suffixes", {}) |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
8 local enabled_rooms = module:get_option("muc_inject_mentions_enabled_rooms", nil) |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
9 local disabled_rooms = module:get_option("muc_inject_mentions_disabled_rooms", nil) |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
10 local mention_delimiters = module:get_option_set("muc_inject_mentions_mention_delimiters", {" ", "", "\n", "\t"}) |
4162
f7bc0e4ab4a2
mod_muc_inject_mentions: Should not append mentions by default
Seve Ferrer <seve@delape.net>
parents:
4161
diff
changeset
|
11 local append_mentions = module:get_option("muc_inject_mentions_append_mentions", false) |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
12 local strip_out_prefixes = module:get_option("muc_inject_mentions_strip_out_prefixes", false) |
4164
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
13 local reserved_nicks = module:get_option("muc_inject_mentions_reserved_nicks", false) |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
14 local use_real_jid = module:get_option("muc_inject_mentions_use_real_jid", false) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
15 local reserved_nicknames = {} |
4155
308b92b07da6
mod_muc_inject_mentions: Refactor code using in_list utility function to improve readability
Seve Ferrer <seve@delape.net>
parents:
4145
diff
changeset
|
16 |
4159
94e3e7753220
mod_muc_inject_mentions: Improve mentions lookup by using a set instead of a list
Seve Ferrer <seve@delape.net>
parents:
4155
diff
changeset
|
17 local reference_xmlns = "urn:xmpp:reference:0" |
4155
308b92b07da6
mod_muc_inject_mentions: Refactor code using in_list utility function to improve readability
Seve Ferrer <seve@delape.net>
parents:
4145
diff
changeset
|
18 |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
19 local function update_reserved_nicknames(event) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
20 local room, data, jid = event.room.jid, event.data, event.jid |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
21 load_room_reserved_nicknames(event.room) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
22 local nickname = (data or {})["reserved_nickname"] |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
23 |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
24 if nickname then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
25 reserved_nicknames[room][nickname] = jid |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
26 else |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
27 local nickname_to_remove |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
28 for _nickname, _jid in pairs(reserved_nicknames[room]) do |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
29 if _jid == jid then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
30 nickname_to_remove = _nickname |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
31 break |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
32 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
33 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
34 if nickname_to_remove then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
35 reserved_nicknames[room][nickname_to_remove] = nil |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
36 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
37 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
38 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
39 |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
40 function load_room_reserved_nicknames(room) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
41 if not reserved_nicknames[room.jid] then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
42 reserved_nicknames[room.jid] = {} |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
43 for jid, data in pairs(room._affiliations_data or {}) do |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
44 local reserved_nickname = data["reserved_nickname"] |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
45 if reserved_nicknames then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
46 reserved_nicknames[room.jid][reserved_nickname] = jid |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
47 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
48 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
49 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
50 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
51 |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
52 local function get_jid(room, nickname) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
53 local real_jid = reserved_nicknames[room.jid][nickname] |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
54 if real_jid and use_real_jid then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
55 return real_jid |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
56 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
57 |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
58 if real_jid and not use_real_jid then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
59 return room.jid .. "/" .. nickname |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
60 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
61 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
62 |
4164
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
63 local function get_participants(room) |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
64 if not reserved_nicks then |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
65 local occupants = room._occupants |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
66 local key, occupant = next(occupants) |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
67 return function () |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
68 while occupant do -- luacheck: ignore |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
69 local nick = jid_resource(occupant.nick); |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
70 local bare_jid = occupant.bare_jid |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
71 key, occupant = next(occupants, key) |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
72 return bare_jid, nick |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
73 end |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
74 end |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
75 else |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
76 local generator = room:each_affiliation() |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
77 local jid, _, affiliation_data = generator(nil, nil) |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
78 return function () |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
79 while jid do |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
80 local bare_jid, nick = jid, (affiliation_data or {})["reserved_nickname"] |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
81 jid, _, affiliation_data = generator(nil, bare_jid) |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
82 if nick then |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
83 return bare_jid, nick |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
84 end |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
85 end |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
86 end |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
87 end |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
88 end |
a82b0745383b
mod_muc_inject_mentions: Add new configuration setting to choose between registered nicknames or online participants
Seve Ferrer <seve@delape.net>
parents:
4163
diff
changeset
|
89 |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
90 local function add_mention(mentions, bare_jid, first, last, prefix_indices, has_prefix) |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
91 if strip_out_prefixes then |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
92 if has_prefix then |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
93 table.insert(prefix_indices, first-1) |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
94 end |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
95 first = first - #prefix_indices |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
96 last = last - #prefix_indices |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
97 end |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
98 mentions[first] = {bare_jid=bare_jid, first=first, last=last} |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
99 end |
4161
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
100 |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
101 local function get_client_mentions(stanza) |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
102 local has_mentions = false |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
103 local client_mentions = {} |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
104 |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
105 for element in stanza:childtags("reference", reference_xmlns) do |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
106 if element.attr.type == "mention" then |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
107 local key = tonumber(element.attr.begin) + 1 -- count starts at 0 |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
108 client_mentions[key] = {bare_jid=element.attr.uri, first=element.attr.begin, last=element.attr["end"]} |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
109 has_mentions = true |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
110 end |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
111 end |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
112 |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
113 return has_mentions, client_mentions |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
114 end |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
115 |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
116 local function is_room_eligible(jid) |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
117 if not enabled_rooms and not disabled_rooms then |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
118 return true; |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
119 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
120 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
121 if enabled_rooms and not disabled_rooms then |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
122 for _, _jid in ipairs(enabled_rooms) do |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
123 if _jid == jid then |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
124 return true |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
125 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
126 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
127 return false |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
128 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
129 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
130 if disabled_rooms and not enabled_rooms then |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
131 for _, _jid in ipairs(disabled_rooms) do |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
132 if _jid == jid then |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
133 return false |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
134 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
135 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
136 return true |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
137 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
138 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
139 return true |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
140 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
141 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
142 local function has_nick_prefix(body, first) |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
143 -- There are no configured prefixes |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
144 if not prefixes or #prefixes < 1 then return false end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
145 |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
146 -- Prefix must have a space before it, |
4142
6906562af2ee
mod_muc_inject_mentions: Allow preffixes to be used after a new line
Seve Ferrer <seve@delape.net>
parents:
4141
diff
changeset
|
147 -- be the first character of the body |
6906562af2ee
mod_muc_inject_mentions: Allow preffixes to be used after a new line
Seve Ferrer <seve@delape.net>
parents:
4141
diff
changeset
|
148 -- or be the first character after a new line |
4159
94e3e7753220
mod_muc_inject_mentions: Improve mentions lookup by using a set instead of a list
Seve Ferrer <seve@delape.net>
parents:
4155
diff
changeset
|
149 if not mention_delimiters:contains(body:sub(first - 2, first - 2)) then |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
150 return false |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
151 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
152 |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
153 local prefix = body:sub(first - 1, first - 1) |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
154 for _, _prefix in ipairs(prefixes) do |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
155 if prefix == _prefix then |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
156 return true |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
157 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
158 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
159 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
160 return false |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
161 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
162 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
163 local function has_nick_suffix(body, last) |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
164 -- There are no configured suffixes |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
165 if not suffixes or #suffixes < 1 then return false end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
166 |
4143
b2080f76e0aa
mod_muc_inject_mentions: Allow suffixes to be used before a new line
Seve Ferrer <seve@delape.net>
parents:
4142
diff
changeset
|
167 -- Suffix must have a space after it, |
b2080f76e0aa
mod_muc_inject_mentions: Allow suffixes to be used before a new line
Seve Ferrer <seve@delape.net>
parents:
4142
diff
changeset
|
168 -- be the last character of the body |
b2080f76e0aa
mod_muc_inject_mentions: Allow suffixes to be used before a new line
Seve Ferrer <seve@delape.net>
parents:
4142
diff
changeset
|
169 -- or be the last character before a new line |
4159
94e3e7753220
mod_muc_inject_mentions: Improve mentions lookup by using a set instead of a list
Seve Ferrer <seve@delape.net>
parents:
4155
diff
changeset
|
170 if not mention_delimiters:contains(body:sub(last + 2, last + 2)) then |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
171 return false |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
172 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
173 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
174 local suffix = body:sub(last+1, last+1) |
4139
c6bb64a12f92
mod_muc_inject_mentions: (W213) unused loop variable i
Seve Ferrer <seve@delape.net>
parents:
4138
diff
changeset
|
175 for _, _suffix in ipairs(suffixes) do |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
176 if suffix == _suffix then |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
177 return true |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
178 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
179 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
180 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
181 return false |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
182 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
183 |
4161
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
184 local function search_mentions(room, body, client_mentions) |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
185 load_room_reserved_nicknames(room) |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
186 local mentions, prefix_indices = {}, {} |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
187 local current_word = "" |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
188 local current_word_start |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
189 for i = 1, #body+1 do |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
190 local char = body:sub(i,i) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
191 -- Mention delimiter found, current_word is completed now |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
192 if mention_delimiters:contains(char) and current_word_start then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
193 -- Check for nickname without prefix |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
194 local jid = get_jid(room, current_word) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
195 if jid then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
196 add_mention(mentions, jid, current_word_start, i - 1, prefix_indices, false) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
197 else |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
198 -- Check for nickname with affixes |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
199 local prefix = prefixes:contains(current_word:sub(1,1)) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
200 local suffix = suffixes:contains(current_word:sub(-1)) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
201 if prefix and suffix then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
202 jid = get_jid(room, current_word:sub(2, -2)) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
203 if jid then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
204 add_mention(mentions, jid, current_word_start + 1, i - 2, prefix_indices, true) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
205 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
206 elseif prefix then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
207 jid = get_jid(room, current_word:sub(2)) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
208 if jid then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
209 add_mention(mentions, jid, current_word_start + 1, i - 1, prefix_indices, true) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
210 end |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
211 elseif suffix then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
212 jid = get_jid(room, current_word:sub(1, -2)) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
213 if jid then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
214 add_mention(mentions, jid, current_word_start, i - 2, prefix_indices, false) |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
215 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
216 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
217 end |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
218 |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
219 current_word = "" |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
220 current_word_start = nil |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
221 elseif not mention_delimiters:contains(char) then |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
222 current_word_start = current_word_start or i |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
223 current_word = current_word .. char |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
224 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
225 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
226 |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
227 return mentions, prefix_indices |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
228 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
229 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
230 local function muc_inject_mentions(event) |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
231 local room, stanza = event.room, event.stanza; |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
232 local body = stanza:get_child_text("body") |
4161
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
233 |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
234 if not body or #body < 1 then return; end |
4161
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
235 |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
236 -- Inject mentions only if the room is configured for them |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
237 if not is_room_eligible(room.jid) then return; end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
238 |
4161
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
239 -- Only act on messages that do not include mentions |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
240 -- unless configuration states otherwise. |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
241 local has_mentions, client_mentions = get_client_mentions(stanza) |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
242 if has_mentions and not append_mentions then return; end |
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
243 |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
244 local mentions, prefix_indices = search_mentions(room, body, client_mentions) |
4161
032e1c79d039
mod_muc_inject_mentions: Add new configuration setting to look for mentions even if the client sent some already
Seve Ferrer <seve@delape.net>
parents:
4159
diff
changeset
|
245 for _, mention in pairs(mentions) do |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
246 -- https://xmpp.org/extensions/xep-0372.html#usecase_mention |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
247 stanza:tag( |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
248 "reference", { |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
249 xmlns=reference_xmlns, |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
250 begin=tostring(mention.first - 1), -- count starts at 0 |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
251 ["end"]=tostring(mention.last - 1), |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
252 type="mention", |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
253 uri="xmpp:" .. mention.bare_jid, |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
254 } |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
255 ):up() |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
256 end |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
257 |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
258 if strip_out_prefixes then |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
259 local body_without_prefixes = "" |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
260 local from = 0 |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
261 if #prefix_indices > 0 then |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
262 for _, prefix_index in ipairs(prefix_indices) do |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
263 body_without_prefixes = body_without_prefixes .. body:sub(from, prefix_index-1) |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
264 from = prefix_index + 1 |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
265 end |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
266 body_without_prefixes = body_without_prefixes .. body:sub(from, #body) |
4163
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
267 |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
268 -- Replace original body containing prefixes |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
269 stanza:maptags( |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
270 function(tag) |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
271 if tag.name ~= "body" then |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
272 return tag |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
273 end |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
274 return st.stanza("body"):text(body_without_prefixes) |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
275 end |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
276 ) |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
277 end |
320f6d374b5d
mod_muc_inject_mentions: Add new configuration setting to strip out prefixes from mentions
Seve Ferrer <seve@delape.net>
parents:
4162
diff
changeset
|
278 end |
4138
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
279 end |
e8c1b35bc25b
mod_muc_inject_mentions: Publish module to repository
Seve Ferrer <seve@delape.net>
parents:
diff
changeset
|
280 |
4243
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
281 module:hook("muc-occupant-groupchat", muc_inject_mentions) |
aed7038ab2ab
mod_muc_inject_mentions: Make module scalable by iterating through the body instead of participants list as the main loop
Seve Ferrer <seve@delape.net>
parents:
4164
diff
changeset
|
282 module:hook("muc-set-affiliation", update_reserved_nicknames) |