This commit is contained in:
Tiara Rodney 2026-03-14 05:38:45 +01:00
commit 883f31932e
No known key found for this signature in database
GPG key ID: 5CD8EC1D46106723
169 changed files with 5676 additions and 0 deletions

View file

@ -0,0 +1,40 @@
local rostermanager = require "core.rostermanager";
local host = module.host;
local default_contacts = module:get_option("default_contacts", {});
module:hook("resource-bind", function(event)
local user = event.session.username;
local user_jid = user .. "@" .. host;
local roster = rostermanager.load_roster(user, host);
for _, contact in ipairs(default_contacts) do
local contact_user = contact.jid:match("^([^@]+)@");
if contact_user ~= user and not roster[contact.jid] then
-- Add contact to this user's roster
local groups = {};
for _, gname in ipairs(contact.groups or {}) do
groups[gname] = true;
end
roster[contact.jid] = {
subscription = "both";
name = contact.name;
groups = groups;
};
rostermanager.save_roster(user, host);
rostermanager.roster_push(user, host, contact.jid);
-- Add this user to the contact's roster (for bidirectional presence)
local contact_roster = rostermanager.load_roster(contact_user, host);
if contact_roster and not contact_roster[user_jid] then
contact_roster[user_jid] = {
subscription = "both";
name = user;
groups = {};
};
rostermanager.save_roster(contact_user, host);
rostermanager.roster_push(contact_user, host, user_jid);
end
end
end
end);