diff options
author | Matthew Wild <mwild1@gmail.com> | 2025-01-09 13:23:46 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2025-01-09 13:23:46 +0000 |
commit | d0457564a32beb493af5d95a51e464aeb7302b15 (patch) | |
tree | 909fb7dde1c7028757280ecf37c65f8475b2c2f7 | |
parent | 7288595789612580bd50cdc1944de6ba93349eac (diff) | |
download | prosody-d0457564a32beb493af5d95a51e464aeb7302b15.tar.gz prosody-d0457564a32beb493af5d95a51e464aeb7302b15.zip |
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.
-rw-r--r-- | plugins/mod_invites.lua | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/plugins/mod_invites.lua b/plugins/mod_invites.lua index 5ee9430a..1dfc8804 100644 --- a/plugins/mod_invites.lua +++ b/plugins/mod_invites.lua @@ -6,6 +6,14 @@ local jid_split = require "prosody.util.jid".split; 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 @@ function use(token) --luacheck: ignore 131/use 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"; |