feat: Allow mentioing @room in an admin announcement

This commit is contained in:
Jade Ellis 2025-06-14 18:54:02 +01:00
parent 5d44653e3a
commit e52094a14f
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
2 changed files with 22 additions and 15 deletions

View file

@ -3,7 +3,7 @@
"$id": "https://continwuity.org/schema/announcements.schema.json", "$id": "https://continwuity.org/schema/announcements.schema.json",
"type": "object", "type": "object",
"properties": { "properties": {
"updates": { "announcements": {
"type": "array", "type": "array",
"items": { "items": {
"type": "object", "type": "object",
@ -16,6 +16,10 @@
}, },
"date": { "date": {
"type": "string" "type": "string"
},
"mention_room": {
"type": "boolean",
"description": "Whether to mention the room (@room) when posting this announcement"
} }
}, },
"required": [ "required": [
@ -26,6 +30,6 @@
} }
}, },
"required": [ "required": [
"updates" "announcements"
] ]
} }

View file

@ -20,7 +20,7 @@ use std::{sync::Arc, time::Duration};
use async_trait::async_trait; use async_trait::async_trait;
use conduwuit::{Result, Server, debug, info, warn}; use conduwuit::{Result, Server, debug, info, warn};
use database::{Deserialized, Map}; use database::{Deserialized, Map};
use ruma::events::room::message::RoomMessageEventContent; use ruma::events::{Mentions, room::message::RoomMessageEventContent};
use serde::Deserialize; use serde::Deserialize;
use tokio::{ use tokio::{
sync::Notify, sync::Notify,
@ -53,6 +53,8 @@ struct CheckForAnnouncementsResponseEntry {
id: u64, id: u64,
date: Option<String>, date: Option<String>,
message: String, message: String,
#[serde(default, skip_serializing_if = "bool::not")]
mention_room: bool,
} }
const CHECK_FOR_ANNOUNCEMENTS_URL: &str = const CHECK_FOR_ANNOUNCEMENTS_URL: &str =
@ -139,19 +141,20 @@ impl Service {
} else { } else {
info!("[announcements] {:#}", announcement.message); info!("[announcements] {:#}", announcement.message);
} }
let mut message = RoomMessageEventContent::text_markdown(format!(
"### New announcement{}\n\n{}",
announcement
.date
.as_ref()
.map_or_else(String::new, |date| format!(" - `{date}`")),
announcement.message
));
self.services if announcement.mention_room {
.admin message = message.add_mentions(Mentions::with_room_mention());
.send_message(RoomMessageEventContent::text_markdown(format!( }
"### New announcement{}\n\n{}",
announcement self.services.admin.send_message(message).await.ok();
.date
.as_ref()
.map_or_else(String::new, |date| format!(" - `{date}`")),
announcement.message
)))
.await
.ok();
} }
#[inline] #[inline]