annotate mod_muc_auto_reserve_nicks/mod_muc_auto_reserve_nicks.lua @ 5119:048e339706ba

mod_rest: Remove manual reference expansion in schema This hack was originally added to reduce the number of definitions of common attributes (type, to, from etc) and payloads (e.g. delay). This predated pointers and references, and until now was needed because parsing picked out the correct stanza kind from the schema, which broke internal references. Removing this hack paves the way for allowing the schema to be configured or customized more easily.
author Kim Alvefur <zash@zash.se>
date Tue, 20 Dec 2022 21:48:28 +0100
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);