Skip to content

[Server Announcements] Implement excluded_user_ids option - #20407

Merged
sandhose merged 4 commits into
developfrom
anoa/server_announcements_exclude_user_ids
Nov 3, 2026
Merged

sandhose merged 4 commits into
developfrom
anoa/server_announcements_exclude_user_ids

Conversation

@anoadragon453

@anoadragon453 anoadragon453 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #20372, and re-uses the changelog.

Adds a new config option to exclude a given list of users from being proactively pushed events from a given announcement room.

Requested by the ESS team at #20344 (comment)

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct (run the linters)

Base automatically changed from anoa/server_announcements_config_rooms to develop October 26, 2026 17:20
@anoadragon453
anoadragon453 force-pushed the anoa/server_announcements_exclude_user_ids branch from 87b09c4 to f278d0f Compare October 26, 2026 17:20
@MadLittleMods MadLittleMods added the A-Server-Announcements Message all users on a homeserver at once (separate from "Server Notices") label Oct 26, 2026
@anoadragon453
anoadragon453 marked this pull request as ready for review October 28, 2026 18:13
@anoadragon453
anoadragon453 requested a review from a team as a code owner October 28, 2026 18:13
@anoadragon453
anoadragon453 requested review from reivilibre and removed request for a team October 28, 2026 18:13
Adds a new config option to exclude a given list of users from being
proactively pushed events from a given announcement room.

Requested by the ESS team at
#20344 (comment)
@anoadragon453
anoadragon453 force-pushed the anoa/server_announcements_exclude_user_ids branch from f278d0f to 1a19d4d Compare October 28, 2026 18:13
@anoadragon453
anoadragon453 requested review from sandhose and removed request for reivilibre October 28, 2026 18:14
Comment on lines +348 to +367
excluded_user_ids = room.get("excluded_user_ids", [])
if not isinstance(excluded_user_ids, list):
raise ConfigError(
"Must be a list", config_path + ("excluded_user_ids",)
)

for excluded_user_index, user_id in enumerate(excluded_user_ids):
user_config_path = config_path + (
"excluded_user_ids",
f"<item {excluded_user_index}>",
)
if not isinstance(user_id, str) or not UserID.is_valid_strict(user_id):
raise ConfigError(
"Must be a valid Matrix user ID", user_config_path
)
if UserID.from_string(user_id).domain != server_name:
raise ConfigError(
"Must be a local user: server announcement rooms are not federated",
user_config_path,
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a check that theres no user that is both in allowed_user_ids and excluded_user_ids at the same time

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did that in bd3cb29

],
)

def test_excluded_user_ids_default(self) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also have some tests for invalid configs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did that in 938c118

@sandhose
sandhose enabled stacked auto-merge (squash) November 3, 2026 12:45
@sandhose

sandhose commented Nov 3, 2026

Copy link
Copy Markdown
Member

Merging this as Andrew is on hol and the changes I had to do were pretty minor. Doing the actual implementation in /sync in another PR once this is merged

@sandhose
sandhose disabled stacked auto-merge November 3, 2026 16:50
@sandhose
sandhose merged commit 6860a7c into develop Nov 3, 2026
113 of 119 checks passed
@sandhose
sandhose deleted the anoa/server_announcements_exclude_user_ids branch November 3, 2026 16:50
sandhose added a commit that referenced this pull request Nov 4, 2026
…sers in legacy sync (#20465)

Follow-up to #20407, which
added the `excluded_user_ids` option without enforcing it. This makes
legacy `/sync` respect it: users listed in a room's `excluded_user_ids`
no longer get that room through the synthetic join. They can still read
it, as it is world-readable.

The cached lookup now maps room ID to config ID, so the per-user filter
runs in memory and adds no database query to `/sync`.
`get_server_announcement_room_ids()` is kept as a wrapper, so the
stacked PRs are unaffected.

Known limitation, documented in the config docs: changing the list does
not update rooms that clients already have. A newly excluded user keeps
the room, which stops updating. A user removed from the list gets new
events without the room's state until their next initial sync. I think
that's an okay limitation for now, as we don't really expect this list
to be used for real users

---------

Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Server-Announcements Message all users on a homeserver at once (separate from "Server Notices")

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants