annotate mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua @ 5553:67152838afbc

mod_http_oauth2: Improve error messages for URI properties Since there are separate validation checks for URI properties, including that they should use https, with better and more specific error reporting. Reverts 'luaPattern' to 'pattern' which is not currently supported by util.jsonschema, but allows anything that retrieves the schema over http to validate against it, should they wish to do so.
author Kim Alvefur <zash@zash.se>
date Sat, 17 Jun 2023 18:15:00 +0200
parents c83bc703825d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4772
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local jid = require "util.jid";
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local set = require "util.set";
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local active_affiliations = set.new({ "member", "admin", "owner" });
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 module:hook("muc-occupant-joined", function (event)
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local room, occupant = event.room, event.occupant;
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local user_jid = occupant.bare_jid;
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local user_affiliation = room:get_affiliation(user_jid);
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 if not active_affiliations:contains(user_affiliation) then
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 return;
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 end
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local aff_data = event.room:get_affiliation_data(user_jid);
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 if not aff_data then
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local reserved_nick = jid.resource(occupant.nick);
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 module:log("debug", "Automatically reserving nickname '%s' for <%s>", reserved_nick, user_jid);
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 room:set_affiliation_data(user_jid, "reserved_nickname", reserved_nick);
4951
c83bc703825d mod_muc_auto_reserve_nicks: Force refresh of nickname (thanks phryk)
Kim Alvefur <zash@zash.se>
parents: 4772
diff changeset
18 room._reserved_nicks = nil; -- force refresh of nickname map
4772
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 end
85d4ab318d66 mod_muc_auto_reserve_nicks: Automatically reserve nicknames of MUC occupants
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end);