40 lines
1.5 KiB
Django/Jinja
40 lines
1.5 KiB
Django/Jinja
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);
|