# HG changeset patch # User Matthew Wild # Date 1736429026 0 # Node ID 9cd5b3484a1dc9be251e96782c5a3a29e007c43b # Parent 8617f5962e47b5735bb2bca1f46b1f4ea8021b4d mod_invites: Add support for invites_page option to use external invites pages This allows Prosody to easily provide friendly invitation links, even without setting up mod_invites_page (which is a community module). Admins can configure it to use a third-party deployment such as https://xmpp.link or they can deploy their own based on https://github.com/modernxmpp/easy-xmpp-invitation Alternatively they can just install mod_invites_page and this will all be handled automatically by that. diff -r 8617f5962e47 -r 9cd5b3484a1d plugins/mod_invites.lua --- a/plugins/mod_invites.lua Wed Jan 08 22:46:21 2025 +0100 +++ b/plugins/mod_invites.lua Thu Jan 09 13:23:46 2025 +0000 @@ -6,6 +6,14 @@ local argparse = require "prosody.util.argparse"; local human_io = require "prosody.util.human.io"; +local url_escape = require "util.http".urlencode; +local render_url = require "util.interpolation".new("%b{}", url_escape, { + urlescape = url_escape; + noscheme = function (urlstring) + return (urlstring:gsub("^[^:]+:", "")); + end; +}); + local default_ttl = module:get_option_period("invite_expiry", "1 week"); local token_storage; @@ -202,6 +210,34 @@ return invite and invite:use(); end +-- Point at e.g. a deployment of https://github.com/modernxmpp/easy-xmpp-invitation +-- This URL must always be absolute, as it is shared standalone +local invite_url_template = module:get_option_string("invites_page"); +local invites_page_supports = module:get_option_set("invites_page_supports", { "account", "contact", "account-and-contact" }); + +local function add_landing_url(invite) + if not invite_url_template or invite.landing_page then return; end + + -- Determine whether this type of invitation is supported by the landing page + local invite_type; + if invite.type == "register" then + invite_type = "account"; + elseif invite.type == "roster" then + if invite.allow_registration then + invite_type = "account-and-contact"; + else + invite_type = "contact-only"; + end + end + if not invites_page_supports:contains(invite_type) then + return; -- Invitation type unsupported + end + + invite.landing_page = render_url(invite_url_template, { host = module.host, invite = invite }); +end + +module:hook("invite-created", add_landing_url, -1); + --- shell command module:add_item("shell-command", { section = "invite";