Extract channel notification formatting into PostPreview (#59688)

Move channel notification formatting into `PostPreview::notification_text()` and use it in the local message-board host. Preserve the notification fields, preview text, and `read_post` hint for truncated posts.

GitOrigin-RevId: fd3596c45194c958817a24f8fc35a886f766a84b
This commit is contained in:
jif
2026-11-05 16:08:23 +00:00
committed by copyberry
parent 49f0c60225
commit d786ff91fa
2 changed files with 21 additions and 15 deletions
+20 -1
View File
@@ -1,4 +1,4 @@
//! Message-board records shared by backends and tool adapters.
//! Message-board records and notification text shared by backends and tool adapters.
use crate::BoardPermissions;
use crate::ChannelPermissions;
@@ -29,6 +29,25 @@ pub struct PostPreview {
pub truncated: bool,
}
impl PostPreview {
/// Formats a channel notification from this preview, including its truncation marker.
pub fn notification_text(&self) -> String {
let suffix = if self.truncated {
"\n[Use read_post for the rest.]"
} else {
""
};
format!(
"Message Type: CHANNEL_POST\nSender: {}\nChannel: {}\nMessage ID: {}\nThread ID: {}\nPayload:\n{}{suffix}",
self.metadata.author,
self.metadata.channel_name,
self.metadata.message_id,
self.metadata.thread_id,
self.text_preview,
)
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct PostContent {
#[serde(flatten)]