Annotate

util/presence.lua @ 8791:8da11142fabf

muc: Allow clients to change multiple affiliations or roles at once (#345) According to XEP-0045 sections 9.2, 9.5 and 9.8 affiliation lists and role lists should allow mass-modification. Prosody however would just use the first entry of the list and ignore the rest. This is fixed by introducing a `for` loop to `set` stanzas of the respective `muc#admin` namespace. In order for this loop to work, the error handling was changed a little. Prosody no longer returns after the first error. Instead, an error reply is sent for each malformed or otherwise wrong entry, but the loop keeps going over the other entries. This may lead to multiple error messages being sent for one client request. A notable exception from this is when the XML Schema for `muc#admin` requests is violated. In that case the loop is aborted with an error message to the client. The change is a bit bigger than that in order to have the loop only for `set` stanzas without changing the behaviour of the `get` stanzas. This is now more in line with trunk, where there are separate methods for each stanza type. References: #345
author Lennart Sauerbeck <devel@lennart.sauerbeck.org>
date Sat, 18 Mar 2017 18:47:28 +0100
parent 7279:051279755cad
child 8885:d4f5d47f874d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7279
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Prosody IM
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 --
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 --
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local t_insert = table.insert;
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local function select_top_resources(user)
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local priority = 0;
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 local recipients = {};
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 for _, session in pairs(user.sessions) do -- find resource with greatest priority
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 if session.presence then
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 -- TODO check active privacy list for session
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local p = session.priority;
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 if p > priority then
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 priority = p;
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 recipients = {session};
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 elseif p == priority then
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 t_insert(recipients, session);
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 return recipients;
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 local function recalc_resource_map(user)
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 if user then
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 user.top_resources = select_top_resources(user);
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 if #user.top_resources == 0 then user.top_resources = nil; end
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 end
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 end
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 return {
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 select_top_resources = select_top_resources;
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 recalc_resource_map = recalc_resource_map;
051279755cad mod_presence: Move function for selecting "top resources" into a new util.presence
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 }