# HG changeset patch # User Matthew Wild # Date 1610905369 0 # Node ID 671bc55f0fc9d38b4274b6d8b08d6cc758f40174 # Parent 1bb08e9ffa826e72bb114fed4df60a57827387a4 mod_invites: Add support to internal API for creating reusable and custom-TTL invites diff -r 1bb08e9ffa82 -r 671bc55f0fc9 mod_invites/mod_invites.lua --- a/mod_invites/mod_invites.lua Sun Jan 17 13:58:52 2021 +0000 +++ b/mod_invites/mod_invites.lua Sun Jan 17 17:42:49 2021 +0000 @@ -4,7 +4,7 @@ local jid_node = require "util.jid".node; local jid_split = require "util.jid".split; -local invite_ttl = module:get_option_number("invite_expiry", 86400 * 7); +local default_ttl = module:get_option_number("invite_expiry", 86400 * 7); local token_storage; if prosody.process_type == "prosody" or prosody.shutdown then @@ -19,11 +19,11 @@ }); end -local function create_invite(invite_action, invite_jid, allow_registration, additional_data) +local function create_invite(invite_action, invite_jid, allow_registration, additional_data, ttl, reusable) local token = id.medium(); local created_at = os.time(); - local expires = created_at + invite_ttl; + local expires = created_at + (ttl or default_ttl); local invite_params = (invite_action == "roster" and allow_registration) and "ibr=y" or nil; @@ -39,6 +39,8 @@ created_at = created_at; expires = expires; + + reusable = reusable; }; module:fire_event("invite-created", invite); @@ -117,6 +119,10 @@ local valid_invite_mt = { __index = valid_invite_methods }; function valid_invite_methods:use() + if self.reusable then + return true; + end + if self.username then -- Also remove the contact invite if present, on the -- assumption that they now have a mutual subscription @@ -170,6 +176,7 @@ type = token_info and token_info.type or "roster"; uri = token_info and token_info.uri or get_uri("roster", username.."@"..module.host, token); additional_data = token_info and token_info.additional_data or nil; + reusable = token_info.reusable; }, valid_invite_mt); end