init
This commit is contained in:
commit
883f31932e
169 changed files with 5676 additions and 0 deletions
40
ansible/roles/prosody/templates/mod_default_contacts.lua.j2
Normal file
40
ansible/roles/prosody/templates/mod_default_contacts.lua.j2
Normal 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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue