use mcp::{
FileInfo, ImageInfo, ImageKind, LinkInfo, MentionInfo, MessageExtras, QuoteInfo, ReactionInfo,
};
use store::MessageRecord;
use teams_core::MentionTarget;
pub fn message_extras(record: &MessageRecord, my_user_id: Option<&str>) -> MessageExtras {
MessageExtras {
text: teams_core::readable_text(record),
images: teams_core::images(record)
.into_iter()
.map(|image| ImageInfo {
kind: image_kind(image.kind()),
image_id: image.id,
alt: image.alt,
})
.collect(),
reactions: teams_core::reaction_summaries(record, my_user_id)
.into_iter()
.map(|summary| ReactionInfo {
emoji: summary.emoji,
count: summary.count,
mine: summary.mine,
})
.collect(),
mentions: teams_core::user_mention_inputs(record)
.into_iter()
.map(|input| MentionInfo {
user_id: match input.target {
MentionTarget::User { user_id } => Some(user_id),
_ => None,
},
name: input.text,
})
.collect(),
files: teams_core::files(record)
.into_iter()
.map(|file| FileInfo {
name: file.name,
size: file.size,
file_type: Some(file_type(file.kind).to_owned()),
link: file.open_url,
})
.collect(),
quote: teams_core::message_quote(record).map(|quote| QuoteInfo {
message_id: quote.message_id,
sender: quote.sender_name,
text: quote.preview,
}),
cards: teams_core::card_texts(record),
links: teams_core::link_preview(record)
.into_iter()
.map(|preview| LinkInfo {
url: preview.url,
title: preview.title,
})
.collect(),
}
}
fn file_type(kind: teams_core::FileKind) -> &'static str {
match kind {
teams_core::FileKind::Word => "word",
teams_core::FileKind::Excel => "excel",
teams_core::FileKind::PowerPoint => "powerpoint",
teams_core::FileKind::Pdf => "pdf",
teams_core::FileKind::Image => "image",
teams_core::FileKind::Archive => "archive",
teams_core::FileKind::Other => "other",
}
}
pub fn image_kind(kind: teams_core::ImageKind) -> ImageKind {
match kind {
teams_core::ImageKind::Inline => ImageKind::Inline,
teams_core::ImageKind::Gif => ImageKind::Gif,
teams_core::ImageKind::Sticker => ImageKind::Sticker,
}
}
#[cfg(test)]
mod tests {
use chrono::{TimeZone, Utc};
use super::*;
fn record() -> MessageRecord {
MessageRecord {
conversation_id: "19:c@thread.v2".to_owned(),
message_id: "1728".to_owned(),
sender_id: Some("user-ada".to_owned()),
sender_name: Some("Ada Example".to_owned()),
created_at: Utc.with_ymd_and_hms(2026, 10, 6, 9, 0, 0).unwrap(),
body_html: concat!(
r#"
Hi

Bob Sampleearlier words
answer
"#.to_owned(), ..MessageRecord::default() }; let extras = message_extras(&stored, None); assert_eq!(extras.text, "answer"); assert_eq!( extras.quote, Some(QuoteInfo { message_id: "1700".to_owned(), sender: Some("Bob Sample".to_owned()), text: "earlier words".to_owned(), }) ); } #[test] fn a_plain_message_has_no_extras() { let plain = MessageRecord { body_html: "hello
".to_owned(), attachments_json: "[]".to_owned(), reactions_json: "[]".to_owned(), mentions_json: "[]".to_owned(), links_json: "[]".to_owned(), ..MessageRecord::default() }; let extras = message_extras(&plain, None); assert_eq!(extras.text, "hello"); assert_eq!( MessageExtras { text: String::new(), ..extras }, MessageExtras::default() ); } }