gatewayd: the texts that say who asked for a redirected approval

Implemented-By: OpenCode session (model recorded in docs/implementer-log.md)
This commit is contained in:
2026-09-24 11:51:43 -07:00
parent bf89512832
commit 989548419d
3 changed files with 136 additions and 0 deletions
+49
View File
@@ -173,3 +173,52 @@ pub fn ended_line(ended: &Ended) -> String {
pub fn with_ending(last: &str, ended: &Ended) -> String {
format!("{last}\n\n{}", ended_line(ended))
}
/// The most characters of an asker's message shown to the approver: it is context, not what is
/// approved, so it may be cut.
pub const PROMPT_SHOWN: usize = 2_000;
/// Who asked for an approval that is shown elsewhere (M4b spec, section 6).
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Asked {
/// `@username`, or the user id when the name could not be found.
pub by: String,
/// The channel's type: `D` a direct message, `G` a group message.
pub channel_type: String,
/// The text of the turn that asked.
pub prompt: String,
}
/// The first post of a redirected approval: who asked, where, and their message.
pub fn asked_post(id: u64, asked: &Asked) -> String {
let place = if asked.channel_type == "G" {
"a group message"
} else {
"a direct message"
};
let escaped = proto::escape::escape_model_text(&asked.prompt);
let total = escaped.chars().count();
let shown: String = escaped.chars().take(PROMPT_SHOWN).collect();
let mut post = format!(
"**Approval {id}** was asked by {} in {place} with the bot. Their message:\n{}",
asked.by,
fence(&shown)
);
if total > PROMPT_SHOWN {
post.push_str(&format!("\n(… {} more characters)", total - PROMPT_SHOWN));
}
post
}
/// The first post of an approval whose session `gatewayd` does not follow.
pub fn unfollowed_post(id: u64, session: &str) -> String {
format!(
"**Approval {id}** was asked in session {}, which gatewayd does not follow now (a restart, or a session from outside Mattermost).",
code(session)
)
}
/// The line left in the asking thread when its approval goes to an approver.
pub fn sent_to_approver(id: u64) -> String {
format!("waiting for approval {id}: it was sent to an approver")
}