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
+1 -14
View File
@@ -230,24 +230,11 @@ impl MessageBoardHost for LocalBoardHost {
Err(error) => return Err(error),
};
let recipient_path = self.registered_path(&recipient).await?;
let suffix = if post.truncated {
"\n[Use read_post for the rest.]"
} else {
""
};
let content = format!(
"Message Type: CHANNEL_POST\nSender: {}\nChannel: {}\nMessage ID: {}\nThread ID: {}\nPayload:\n{}{suffix}",
post.metadata.author,
post.metadata.channel_name,
post.metadata.message_id,
post.metadata.thread_id,
post.text_preview,
);
let communication = InterAgentCommunication::new(
post.metadata.author.clone(),
recipient_path,
Vec::new(),
content,
post.notification_text(),
/*trigger_turn*/ false,
);
// Remote metadata is untrusted. Skip an oversized notice without closing
+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)]