Mercurial > prosody-modules
annotate mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua @ 5713:dde83f6043e6
mod_audit_register: Include hostpart with audit events here too
mod_audit seems to expect this to be JIDs, not bare usernames.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 13 Nov 2023 17:23:49 +0100 |
parents | d5ff386dc97f |
children | 220502eb05aa |
rev | line source |
---|---|
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
1 local jid_split = require "util.jid".split; |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
2 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
3 local st = require "util.stanza"; |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
4 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
5 local mod_groups = module:depends("groups_internal") |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
6 local mod_pep = module:depends("pep") |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
7 |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
8 local XMLNS_BM2 = "urn:xmpp:bookmarks:1"; |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
9 local XMLNS_XEP0060 = "http://jabber.org/protocol/pubsub"; |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
10 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
11 local default_options = { |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
12 ["persist_items"] = true; |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
13 ["max_items"] = "max"; |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
14 ["send_last_published_item"] = "never"; |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
15 ["access_model"] = "whitelist"; |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
16 }; |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
17 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
18 local function get_current_bookmarks(jid, service) |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
19 local ok, items = service:get_items(XMLNS_BM2, jid) |
4863
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
20 if not ok then |
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
21 if items == "item-not-found" then |
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
22 return {}, nil; |
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
23 else |
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
24 return nil, items; |
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
25 end |
fdf50c4d23a3
mod_groups_muc_bookmarks: restore bookmark injection on empty store
Jonas Schäfer <jonas@wielicki.name>
parents:
4862
diff
changeset
|
26 end |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
27 return items or {}; |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
28 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
29 |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
30 local function update_bookmark(jid, service, room, bookmark) |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
31 local ok, err = service:publish(XMLNS_BM2, jid, room, bookmark, default_options); |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
32 if ok then |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
33 module:log("debug", "found existing matching bookmark, updated") |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
34 else |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
35 module:log("error", "failed to update bookmarks: %s", err) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
36 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
37 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
38 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
39 local function find_matching_bookmark(storage, room) |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
40 return storage[room]; |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
41 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
42 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
43 local function inject_bookmark(jid, room, autojoin, name) |
5686
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
44 module:log("debug", "Injecting bookmark for %s into %s", room, jid); |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
45 local pep_service = mod_pep.get_pep_service(jid_split(jid)) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
46 |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
47 local current, err = get_current_bookmarks(jid, pep_service); |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
48 if err then |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
49 module:log("error", "Could not retrieve existing bookmarks for %s: %s", jid, err); |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
50 return; |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
51 end |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
52 local found = find_matching_bookmark(current, room) |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
53 if found then |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
54 local existing = found:get_child("conference", XMLNS_BM2); |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
55 if autojoin ~= nil then |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
56 existing.attr.autojoin = autojoin and "true" or "false" |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
57 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
58 if name ~= nil then |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
59 -- do not change already configured names |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
60 if not existing.attr.name then |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
61 existing.attr.name = name |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
62 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
63 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
64 else |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
65 module:log("debug", "no existing bookmark found, adding new") |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
66 found = st.stanza("item", { xmlns = XMLNS_XEP0060; id = room }) |
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
67 :tag("conference", { xmlns = XMLNS_BM2; name = name; autojoin = autojoin and "true" or "false"; }) |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
68 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
69 |
4862
9a8a43d0faed
mod_groups_muc_bookmarks: fix typo/leftover from refactor
Jonas Schäfer <jonas@wielicki.name>
parents:
4861
diff
changeset
|
70 update_bookmark(jid, pep_service, room, found) |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
71 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
72 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
73 local function remove_bookmark(jid, room, autojoin, name) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
74 local pep_service = mod_pep.get_pep_service(jid_split(jid)) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
75 |
4861
5fadb991003d
mod_groups_muc_bookmarks: Switch to XEP-0402
Kim Alvefur <zash@zash.se>
parents:
4586
diff
changeset
|
76 return pep_service:retract(XMLNS_BM2, jid, room, st.stanza("retract", { id = room })); |
4425
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
77 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
78 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
79 local function handle_user_added(event) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
80 if not event.group_info.muc_jid then |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
81 module:log("debug", "ignoring user added event on group %s because it has no MUC", event.id) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
82 return |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
83 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
84 local jid = event.user .. "@" .. event.host |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
85 inject_bookmark(jid, event.group_info.muc_jid, true, event.group_info.name) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
86 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
87 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
88 local function handle_user_removed(event) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
89 if not event.group_info.muc_jid then |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
90 module:log("debug", "ignoring user removed event on group %s because it has no MUC", event.id) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
91 return |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
92 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
93 -- Removing the bookmark is fine as the user just lost any privilege to |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
94 -- be in the MUC (as group MUCs are members-only). |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
95 local jid = event.user .. "@" .. event.host |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
96 remove_bookmark(jid, event.group_info.muc_jid, true, event.group_info.name) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
97 end |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
98 |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
99 module:hook("group-user-added", handle_user_added) |
b3e0295e14a3
mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff
changeset
|
100 module:hook("group-user-removed", handle_user_removed) |
5686
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
101 |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
102 |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
103 local function handle_muc_added(event) |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
104 -- Add MUC to all members' bookmarks |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
105 module:log("info", "Adding new group chat to all member bookmarks..."); |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
106 local muc_jid, muc_name = event.muc.jid, event.muc.name; |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
107 for member_username in pairs(mod_groups.get_members(event.group_id)) do |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
108 local member_jid = member_username .. "@" .. module.host; |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
109 inject_bookmark(member_jid, muc_jid, true, muc_name); |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
110 end |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
111 end |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
112 |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
113 local function handle_muc_removed(event) |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
114 -- Remove MUC from all members' bookmarks |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
115 local muc_jid = event.muc.jid; |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
116 for member_username in ipairs(mod_groups.get_members(event.group_id)) do |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
117 local member_jid = member_username .. "@" .. module.host; |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
118 remove_bookmark(member_jid, muc_jid); |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
119 end |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
120 end |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
121 |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
122 module:hook("group-chat-added", handle_muc_added) |
d5ff386dc97f
mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents:
4863
diff
changeset
|
123 module:hook("group-chat-removed", handle_muc_removed) |