BlueGit

ict rusty-teams

feat(messages): Loop components show as a card that opens in the browser

- componentUrl from the fluidEmbedCard content, no save button

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-05 · 3 weeks ago

Hash
61c5b54449aafda2e004ed0a5d795778352b76d2
Parent
0b8834de
4 files changed +42 −6
crates/app-base/src/agent_api/extras.rs +1 −0
@@ -77,6 +77,7 @@ fn file_type(kind: teams_core::FileKind) -> &'static str {
77 77 teams_core::FileKind::Pdf => "pdf",
78 78 teams_core::FileKind::Image => "image",
79 79 teams_core::FileKind::Archive => "archive",
80 teams_core::FileKind::Loop => "loop",
80 81 teams_core::FileKind::Other => "other",
81 82 }
82 83 }
@@ -77,6 +77,7 @@ fn file_type(kind: teams_core::FileKind) -> &'static str {
77 teams_core::FileKind::Pdf => "pdf",
77 teams_core::FileKind::Pdf => "pdf",
78 teams_core::FileKind::Image => "image",
78 teams_core::FileKind::Image => "image",
79 teams_core::FileKind::Archive => "archive",
79 teams_core::FileKind::Archive => "archive",
80 teams_core::FileKind::Loop => "loop",
80 teams_core::FileKind::Other => "other",
81 teams_core::FileKind::Other => "other",
81 }
82 }
82}
83}
crates/app/src/views/attachments.rs +2 −1
@@ -142,6 +142,7 @@ fn kind_style(kind: FileKind) -> KindStyle {
142 142 FileKind::Pdf => ("PDF", "PDF document", 0xB91C1C),
143 143 FileKind::Image => ("IMG", "Image", 0x7C3AED),
144 144 FileKind::Archive => ("ZIP", "Archive", 0xB45309),
145 FileKind::Loop => ("", "Loop component", 0x7C3AED),
145 146 FileKind::Other => ("", "File", 0x525252),
146 147 };
147 148 KindStyle {
@@ -252,7 +253,7 @@ fn file_view(
252 253 .and_then(Option::as_ref);
253 254 let progress = downloads::progress_fraction(state);
254 255 let button = actions
255 .filter(|_| !card.open_url.is_empty())
256 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
256 257 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
257 258 h_flex()
258 259 .id(ElementId::Name(id.into()))
@@ -142,6 +142,7 @@ fn kind_style(kind: FileKind) -> KindStyle {
142 FileKind::Pdf => ("PDF", "PDF document", 0xB91C1C),
142 FileKind::Pdf => ("PDF", "PDF document", 0xB91C1C),
143 FileKind::Image => ("IMG", "Image", 0x7C3AED),
143 FileKind::Image => ("IMG", "Image", 0x7C3AED),
144 FileKind::Archive => ("ZIP", "Archive", 0xB45309),
144 FileKind::Archive => ("ZIP", "Archive", 0xB45309),
145 FileKind::Loop => ("", "Loop component", 0x7C3AED),
145 FileKind::Other => ("", "File", 0x525252),
146 FileKind::Other => ("", "File", 0x525252),
146 };
147 };
147 KindStyle {
148 KindStyle {
@@ -252,7 +253,7 @@ fn file_view(
252 .and_then(Option::as_ref);
253 .and_then(Option::as_ref);
253 let progress = downloads::progress_fraction(state);
254 let progress = downloads::progress_fraction(state);
254 let button = actions
255 let button = actions
255 .filter(|_| !card.open_url.is_empty())
256 .filter(|_| !card.open_url.is_empty() && card.kind != FileKind::Loop)
256 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
257 .map(|actions| save_button(state, format!("{id}-save"), index, actions.activate.clone()));
257 h_flex()
258 h_flex()
258 .id(ElementId::Name(id.into()))
259 .id(ElementId::Name(id.into()))
crates/core/src/preview.rs +1 −2
@@ -7,7 +7,7 @@ use crate::external_image::is_giphy_url;
7 7 use crate::forwarded::FORWARDED_CONTENT_TYPE;
8 8 use crate::roster_event::{RosterChange, roster_event};
9 9 use crate::spans::{Span, html_to_spans};
10 use crate::stored::{AttachmentInfo, attachments};
10 use crate::stored::{AttachmentInfo, LOOP_CARD_TYPE, attachments};
11 11
12 12 const MAX_PREVIEW_CHARS: usize = 200;
13 13
@@ -35,7 +35,6 @@ const EVENT_PREVIEWS: [&str; 6] = [
35 35 ];
36 36
37 37 const AUDIO_CARD_TYPE: &str = "application/vnd.microsoft.card.audio";
38 const LOOP_CARD_TYPE: &str = "application/vnd.microsoft.card.fluidEmbedCard";
39 38 const FILE_CONTENT_TYPE: &str = "reference";
40 39 const RECORDING_TYPE: &str = "#microsoft.graph.callRecordingEventMessageDetail";
41 40 const TRANSCRIPT_TYPE: &str = "#microsoft.graph.callTranscriptEventMessageDetail";
@@ -7,7 +7,7 @@ use crate::external_image::is_giphy_url;
7use crate::forwarded::FORWARDED_CONTENT_TYPE;
7use crate::forwarded::FORWARDED_CONTENT_TYPE;
8use crate::roster_event::{RosterChange, roster_event};
8use crate::roster_event::{RosterChange, roster_event};
9use crate::spans::{Span, html_to_spans};
9use crate::spans::{Span, html_to_spans};
10use crate::stored::{AttachmentInfo, attachments};
10use crate::stored::{AttachmentInfo, LOOP_CARD_TYPE, attachments};
11
11
12const MAX_PREVIEW_CHARS: usize = 200;
12const MAX_PREVIEW_CHARS: usize = 200;
13
13
@@ -35,7 +35,6 @@ const EVENT_PREVIEWS: [&str; 6] = [
35];
35];
36
36
37const AUDIO_CARD_TYPE: &str = "application/vnd.microsoft.card.audio";
37const AUDIO_CARD_TYPE: &str = "application/vnd.microsoft.card.audio";
38const LOOP_CARD_TYPE: &str = "application/vnd.microsoft.card.fluidEmbedCard";
39const FILE_CONTENT_TYPE: &str = "reference";
38const FILE_CONTENT_TYPE: &str = "reference";
40const RECORDING_TYPE: &str = "#microsoft.graph.callRecordingEventMessageDetail";
39const RECORDING_TYPE: &str = "#microsoft.graph.callRecordingEventMessageDetail";
41const TRANSCRIPT_TYPE: &str = "#microsoft.graph.callTranscriptEventMessageDetail";
40const TRANSCRIPT_TYPE: &str = "#microsoft.graph.callTranscriptEventMessageDetail";
crates/core/src/stored.rs +38 −3
@@ -14,6 +14,8 @@ const EMOJI_ITEMTYPE: &str = "schema.skype.com/Emoji";
14 14 const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
15 15 const LINK_UNFURL_APP_ID: &str = "4623DD0C-D55C-4C95-9290-AD31619B577A";
16 16 const LINK_UNFURL_CARD_PREFIX: &str = "app-preview-card";
17 pub(crate) const LOOP_CARD_TYPE: &str = "application/vnd.microsoft.card.fluidEmbedCard";
18 const LOOP_CARD_NAME: &str = "Loop component";
17 19
18 20 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19 21 pub struct AttachmentInfo {
@@ -45,6 +47,7 @@ pub enum FileKind {
45 47 Pdf,
46 48 Image,
47 49 Archive,
50 Loop,
48 51 Other,
49 52 }
50 53
@@ -153,6 +156,18 @@ impl AttachmentInfo {
153 156 pub fn is_file(&self) -> bool {
154 157 self.content_type.as_deref() == Some("reference") && self.url.is_some()
155 158 }
159
160 fn loop_component_url(&self) -> Option<String> {
161 if self.content_type.as_deref() != Some(LOOP_CARD_TYPE) {
162 return None;
163 }
164 let from_content = self
165 .content
166 .as_deref()
167 .and_then(|content| serde_json::from_str::<serde_json::Value>(content).ok())
168 .and_then(|content| content.get("componentUrl")?.as_str().map(str::to_owned));
169 from_content.or_else(|| self.url.clone()).filter(|url| !url.is_empty())
170 }
156 171 }
157 172
158 173 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -392,9 +407,9 @@ pub struct FileCard {
392 407
393 408 /// File attachments (`reference` type) with a name and a URL. `size` is rarely known; Graph does not send it for these.
394 409 pub fn files(record: &MessageRecord) -> Vec<FileCard> {
395 attachments(record)
396 .into_iter()
397 .filter(AttachmentInfo::is_file)
410 let all = attachments(record);
411 all.iter()
412 .filter(|attachment| attachment.is_file())
398 413 .map(|attachment| FileCard {
399 414 kind: attachment.file_kind(),
400 415 name: attachment.name.clone().unwrap_or_default(),
@@ -402,6 +417,15 @@ pub fn files(record: &MessageRecord) -> Vec<FileCard> {
402 417 size: attachment.size,
403 418 open_url: attachment.url.clone().unwrap_or_default(),
404 419 })
420 .chain(all.iter().filter_map(|attachment| {
421 Some(FileCard {
422 open_url: attachment.loop_component_url()?,
423 kind: FileKind::Loop,
424 name: attachment.name.clone().unwrap_or_else(|| LOOP_CARD_NAME.to_owned()),
425 content_type: attachment.content_type.clone(),
426 size: None,
427 })
428 }))
405 429 .collect()
406 430 }
407 431
@@ -1113,6 +1137,17 @@ mod tests {
1113 1137 assert_eq!(found[0].size, None);
1114 1138 }
1115 1139
1140 #[test]
1141 fn a_loop_component_opens_its_component_url() {
1142 let json = r#"[{"content_type":"application/vnd.microsoft.card.fluidEmbedCard","name":null,"url":null,"text":null,"id":"placeholder","content":"{\"componentUrl\":\"https://x/loop.fluid\",\"sourceType\":\"Compose\"}"}]"#;
1143 let found = files(&record("", json));
1144 assert_eq!(found.len(), 1);
1145 assert_eq!(
1146 (found[0].name.as_str(), found[0].kind, found[0].open_url.as_str()),
1147 ("Loop component", FileKind::Loop, "https://x/loop.fluid")
1148 );
1149 }
1150
1116 1151 #[test]
1117 1152 fn copy_text_flattens_markup_and_keeps_mentions_and_lines() {
1118 1153 let html = r#"<p>Hi <at id="0">Ada</at>, <b>look</b></p><p>second <a href="https://x">link</a></p>"#;
@@ -14,6 +14,8 @@ const EMOJI_ITEMTYPE: &str = "schema.skype.com/Emoji";
14const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
14const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
15const LINK_UNFURL_APP_ID: &str = "4623DD0C-D55C-4C95-9290-AD31619B577A";
15const LINK_UNFURL_APP_ID: &str = "4623DD0C-D55C-4C95-9290-AD31619B577A";
16const LINK_UNFURL_CARD_PREFIX: &str = "app-preview-card";
16const LINK_UNFURL_CARD_PREFIX: &str = "app-preview-card";
17pub(crate) const LOOP_CARD_TYPE: &str = "application/vnd.microsoft.card.fluidEmbedCard";
18const LOOP_CARD_NAME: &str = "Loop component";
17
19
18#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
20#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19pub struct AttachmentInfo {
21pub struct AttachmentInfo {
@@ -45,6 +47,7 @@ pub enum FileKind {
45 Pdf,
47 Pdf,
46 Image,
48 Image,
47 Archive,
49 Archive,
50 Loop,
48 Other,
51 Other,
49}
52}
50
53
@@ -153,6 +156,18 @@ impl AttachmentInfo {
153 pub fn is_file(&self) -> bool {
156 pub fn is_file(&self) -> bool {
154 self.content_type.as_deref() == Some("reference") && self.url.is_some()
157 self.content_type.as_deref() == Some("reference") && self.url.is_some()
155 }
158 }
159
160 fn loop_component_url(&self) -> Option<String> {
161 if self.content_type.as_deref() != Some(LOOP_CARD_TYPE) {
162 return None;
163 }
164 let from_content = self
165 .content
166 .as_deref()
167 .and_then(|content| serde_json::from_str::<serde_json::Value>(content).ok())
168 .and_then(|content| content.get("componentUrl")?.as_str().map(str::to_owned));
169 from_content.or_else(|| self.url.clone()).filter(|url| !url.is_empty())
170 }
156}
171}
157
172
158#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
173#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -392,9 +407,9 @@ pub struct FileCard {
392
407
393/// File attachments (`reference` type) with a name and a URL. `size` is rarely known; Graph does not send it for these.
408/// File attachments (`reference` type) with a name and a URL. `size` is rarely known; Graph does not send it for these.
394pub fn files(record: &MessageRecord) -> Vec<FileCard> {
409pub fn files(record: &MessageRecord) -> Vec<FileCard> {
395 attachments(record)
410 let all = attachments(record);
396 .into_iter()
411 all.iter()
397 .filter(AttachmentInfo::is_file)
412 .filter(|attachment| attachment.is_file())
398 .map(|attachment| FileCard {
413 .map(|attachment| FileCard {
399 kind: attachment.file_kind(),
414 kind: attachment.file_kind(),
400 name: attachment.name.clone().unwrap_or_default(),
415 name: attachment.name.clone().unwrap_or_default(),
@@ -402,6 +417,15 @@ pub fn files(record: &MessageRecord) -> Vec<FileCard> {
402 size: attachment.size,
417 size: attachment.size,
403 open_url: attachment.url.clone().unwrap_or_default(),
418 open_url: attachment.url.clone().unwrap_or_default(),
404 })
419 })
420 .chain(all.iter().filter_map(|attachment| {
421 Some(FileCard {
422 open_url: attachment.loop_component_url()?,
423 kind: FileKind::Loop,
424 name: attachment.name.clone().unwrap_or_else(|| LOOP_CARD_NAME.to_owned()),
425 content_type: attachment.content_type.clone(),
426 size: None,
427 })
428 }))
405 .collect()
429 .collect()
406}
430}
407
431
@@ -1113,6 +1137,17 @@ mod tests {
1113 assert_eq!(found[0].size, None);
1137 assert_eq!(found[0].size, None);
1114 }
1138 }
1115
1139
1140 #[test]
1141 fn a_loop_component_opens_its_component_url() {
1142 let json = r#"[{"content_type":"application/vnd.microsoft.card.fluidEmbedCard","name":null,"url":null,"text":null,"id":"placeholder","content":"{\"componentUrl\":\"https://x/loop.fluid\",\"sourceType\":\"Compose\"}"}]"#;
1143 let found = files(&record("", json));
1144 assert_eq!(found.len(), 1);
1145 assert_eq!(
1146 (found[0].name.as_str(), found[0].kind, found[0].open_url.as_str()),
1147 ("Loop component", FileKind::Loop, "https://x/loop.fluid")
1148 );
1149 }
1150
1116 #[test]
1151 #[test]
1117 fn copy_text_flattens_markup_and_keeps_mentions_and_lines() {
1152 fn copy_text_flattens_markup_and_keeps_mentions_and_lines() {
1118 let html = r#"<p>Hi <at id="0">Ada</at>, <b>look</b></p><p>second <a href="https://x">link</a></p>"#;
1153 let html = r#"<p>Hi <at id="0">Ada</at>, <b>look</b></p><p>second <a href="https://x">link</a></p>"#;