annotate mod_groups_muc_bookmarks/mod_groups_muc_bookmarks.lua @ 4676:a2cf3b69a3d6

mod_http_muc_log: Add way to list certain rooms in a specified order
author Kim Alvefur <zash@zash.se>
date Sun, 12 Sep 2021 00:13:32 +0200
parents 240fa534f586
children 5fadb991003d
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
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
8 local PUBSUB_NODE_XEP0048 = "storage:bookmarks";
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_XEP0048 = "storage:bookmarks";
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
10 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
11
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
12 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
13 ["persist_items"] = true;
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
14 ["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
15 };
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 local function get_current_bookmarks(jid, service)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
18 local ok, id, item = service:get_last_item(PUBSUB_NODE_XEP0048, jid)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
19 if not ok or id == nil then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
20 if id == "item-not-found" or id == nil then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
21 -- return empty
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
22 return st.stanza("storage", { xmlns = XMLNS_XEP0048 });
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
23 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
24 return nil, result
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
25 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
26 -- first item is the actual storage element
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
27 local hit = item:get_child("storage", XMLNS_XEP0048);
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
28 if not hit then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
29 return nil, "internal-server-error"
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
30 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
31 return hit
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
32 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
33
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
34 local function update_bookmarks(jid, service, storage)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
35 local item = st.stanza("item", { xmlns = XMLNS_XEP0060, id = "current" }):add_child(storage)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
36 module:log("debug", "updating bookmarks with %q", item)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
37 local ok, err = service:publish(
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
38 PUBSUB_NODE_XEP0048,
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
39 jid,
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
40 "current",
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
41 item,
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
42 default_options
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
43 )
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
44 if not ok then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
45 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
46 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
47 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
48
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
49 local function find_matching_bookmark(storage, room)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
50 for node in storage:childtags("conference") do
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
51 if node.attr.jid == room then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
52 return node
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
53 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
54 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
55 return nil
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
56 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
57
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
58 local function inject_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
59 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
60
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
61 autojoin = autojoin or false and true
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
62 local current = get_current_bookmarks(jid, pep_service)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
63 local existing = find_matching_bookmark(current, room)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
64 if existing then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
65 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
66 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
67 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
68 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
69 -- 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
70 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
71 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
72 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
73 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
74 done = true
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
75 module:log("debug", "found existing matching bookmark, updated")
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
76 else
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
77 module:log("debug", "no existing bookmark found, adding new")
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
78 current:tag("conference", {
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
79 name = name,
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
80 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
81 jid = room,
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
82 xmlns = XMLNS_XEP0048,
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
83 })
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
84 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
85
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
86 update_bookmarks(jid, pep_service, current)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
87 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
88
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
89 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
90 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
91
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
92 autojoin = autojoin or false and true
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
93 local current = get_current_bookmarks(jid, pep_service)
4586
240fa534f586 mod_groups_muc_bookmarks: handle removal of accounts without bookmarks
Jonas Schäfer <jonas@wielicki.name>
parents: 4425
diff changeset
94 if not current then
240fa534f586 mod_groups_muc_bookmarks: handle removal of accounts without bookmarks
Jonas Schäfer <jonas@wielicki.name>
parents: 4425
diff changeset
95 return
240fa534f586 mod_groups_muc_bookmarks: handle removal of accounts without bookmarks
Jonas Schäfer <jonas@wielicki.name>
parents: 4425
diff changeset
96 end
4425
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
97 current:maptags(function (node)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
98 if node.attr.xmlns and node.attr.xmlns ~= XMLNS_XEP0048 then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
99 return node
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
100 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
101 if node.name ~= "conference" then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
102 return node
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
103 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
104 if node.attr.jid == room then
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
105 -- remove matching bookmark
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
106 return nil
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
107 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
108 return node
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
109 end)
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
110
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
111 update_bookmarks(jid, pep_service, current)
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 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
115 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
116 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
117 return
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
118 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
119 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
120 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
121 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
122
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
123 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
124 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
125 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
126 return
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
127 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
128 -- 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
129 -- 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
130 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
131 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
132 end
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
133
b3e0295e14a3 mod_groups_muc_bookmarks: manage PEP (XEP-0048) bookmarks of group members
Jonas Schäfer <jonas@wielicki.name>
parents:
diff changeset
134 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
135 module:hook("group-user-removed", handle_user_removed)