From 2c653013c846008b1d138d8290423186d9e9e144 Mon Sep 17 00:00:00 2001 From: Niko Diamadis Date: Fri, 3 Jan 2025 05:20:55 -0500 Subject: [PATCH] Support [Matrix] summary endpoint (#10782) * feat: add support for Matrix summary endpoint * docs: update Matrix documentation * refactor: abstract logic into more functions * refactor: revert custom timeout for tests * test: add test for fetchMode override on matrix.org * fix: validate the fetchMode value * docs: extend fetchMode description * fix: add await keywords * clarify test description --------- Co-authored-by: chris48s --- services/matrix/matrix.service.js | 94 ++++++++++++++++----- services/matrix/matrix.tester.js | 135 +++++++++++++++++++++++++++++- 2 files changed, 204 insertions(+), 25 deletions(-) diff --git a/services/matrix/matrix.service.js b/services/matrix/matrix.service.js index dca11a8060..60b22ed730 100644 --- a/services/matrix/matrix.service.js +++ b/services/matrix/matrix.service.js @@ -5,9 +5,15 @@ import { pathParam, queryParam, } from '../index.js' +import { nonNegativeInteger } from '../validators.js' + +const fetchModeEnum = ['guest', 'summary'] const queryParamSchema = Joi.object({ server_fqdn: Joi.string().hostname(), + fetchMode: Joi.string() + .valid(...fetchModeEnum) + .default('guest'), }).required() const matrixRegisterSchema = Joi.object({ @@ -31,9 +37,16 @@ const matrixStateSchema = Joi.array() ) .required() +const matrixSummarySchema = Joi.object({ + num_joined_members: nonNegativeInteger, +}).required() + const description = ` In order for this badge to work, the host of your room must allow guest accounts or dummy accounts to register, and the room must be world readable (chat history visible to anyone). +Alternatively access via the experimental summary endpoint ([MSC3266](https://github.com/matrix-org/matrix-spec-proposals/pull/3266)) can be configured with the query parameter fetchMode for less server load and better performance, if supported by the homeserver
+For the matrix.org homeserver fetchMode is hard-coded to summary. + The following steps will show you how to setup the badge URL using the Element Matrix client.