Annotate

mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua @ 5935:e7584fd5b191

mod_muc_restrict_pm: fix table in README
author Nicholas George <wirlaburla@worlio.com>
date Tue, 21 May 2024 01:09:12 -0500
parent 5849:791aa8072f58
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
5709
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
5846
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
73 local function remove_bookmark(jid, room)
4425
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)
5846
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
80 local group_info = event.group_info;
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
81
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
82 local jid = event.user .. "@" .. event.host
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
83
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
84 if group_info.muc_jid then
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
85 inject_bookmark(jid, group_info.muc_jid, true, group_info.name);
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
86 elseif group_info.mucs then
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
87 for _, chat in ipairs(mod_groups.get_group_chats(event.id)) do
5849
791aa8072f58 mod_groups_muc_bookmarks: Don't add deleted MUCs to user bookmarks
Matthew Wild <mwild1@gmail.com>
parents: 5846
diff changeset
88 if not chat.deleted then
791aa8072f58 mod_groups_muc_bookmarks: Don't add deleted MUCs to user bookmarks
Matthew Wild <mwild1@gmail.com>
parents: 5846
diff changeset
89 inject_bookmark(jid, chat.jid, true, chat.name);
791aa8072f58 mod_groups_muc_bookmarks: Don't add deleted MUCs to user bookmarks
Matthew Wild <mwild1@gmail.com>
parents: 5846
diff changeset
90 end
5846
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
91 end
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
92 else
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
93 module:log("debug", "ignoring user added event on group %s because it has no MUCs", event.id)
4425
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
94 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
95 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
96
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
97 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
98 -- 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
99 -- be in the MUC (as group MUCs are members-only).
5846
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
100 local group_info = event.group_info;
4425
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
101 local jid = event.user .. "@" .. event.host
5846
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
102
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
103 if group_info.muc_jid then
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
104 remove_bookmark(jid, event.group_info.muc_jid);
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
105 elseif group_info.mucs then
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
106 for _, muc_jid in ipairs(group_info.mucs) do
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
107 remove_bookmark(jid, muc_jid);
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
108 end
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
109 else
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
110 module:log("debug", "ignoring user removed event on group %s because it has no MUC", event.id)
220502eb05aa mod_groups_muc_bookmarks: Sync bookmarks when user is added/removed to/from multi-MUC group
Matthew Wild <mwild1@gmail.com>
parents: 5709
diff changeset
111 end
4425
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
112 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
113
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
114 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
115 module:hook("group-user-removed", handle_user_removed)
5709
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
116
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
117
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
118 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
119 -- 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
120 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
121 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
122 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
123 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
124 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
125 end
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
126 end
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
127
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
128 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
129 -- 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
130 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
131 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
132 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
133 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
134 end
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
135 end
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
136
d5ff386dc97f mod_groups_muc_bookmarks: Update bookmarks when a group MUC is added/removed
Matthew Wild <mwild1@gmail.com>
parents: 4863
diff changeset
137 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
138 module:hook("group-chat-removed", handle_muc_removed)