BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / src / stored.rs

stored.rs

stored.rs 45.9 KiB Download Raw
1use chrono::{DateTime, Utc};
2use scraper::{ElementRef, Html};
3use serde::{Deserialize, Serialize};
4use store::MessageRecord;
5
6use crate::adaptive_card::{AdaptiveCard, card_content_text};
7use crate::external_image::{external_image_url, is_giphy_url};
8use crate::forwarded::{ForwardHeader, ForwardInfo, forwarded_texts, inline_forwards, no_forward_header};
9use crate::markdown::escape_html;
10use crate::mentions::MentionInput;
11use crate::spans::{Span, html_to_spans};
12
13const EMOJI_ITEMTYPE: &str = "schema.skype.com/Emoji";
14const REPLY_ITEMTYPE: &str = "schema.skype.com/Reply";
15
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub struct AttachmentInfo {
18 pub content_type: Option<String>,
19 pub name: Option<String>,
20 pub url: Option<String>,
21 pub text: Option<String>,
22 #[serde(default)]
23 pub size: Option<u64>,
24 #[serde(default)]
25 pub quote: Option<QuoteInfo>,
26 #[serde(default)]
27 pub id: Option<String>,
28 /// Raw content, kept only for quotes and cards so an edit can send them back unchanged.
29 #[serde(default)]
30 pub content: Option<String>,
31 /// A forward whose original Graph did not return; it is not fetched again.
32 #[serde(default, skip_serializing_if = "std::ops::Not::not")]
33 pub unavailable: bool,
34}
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
37pub enum FileKind {
38 Word,
39 Excel,
40 PowerPoint,
41 Pdf,
42 Image,
43 Archive,
44 Other,
45}
46
47impl FileKind {
48 pub fn from_name(name: &str) -> FileKind {
49 let Some((_, extension)) = name.rsplit_once('.') else {
50 return FileKind::Other;
51 };
52 match extension.to_ascii_lowercase().as_str() {
53 "doc" | "docx" | "docm" | "dot" | "dotx" | "rtf" | "odt" => FileKind::Word,
54 "xls" | "xlsx" | "xlsm" | "xlsb" | "csv" | "ods" => FileKind::Excel,
55 "ppt" | "pptx" | "pptm" | "pps" | "ppsx" | "odp" => FileKind::PowerPoint,
56 "pdf" => FileKind::Pdf,
57 "png" | "jpg" | "jpeg" | "gif" | "bmp" | "webp" | "svg" | "heic" | "tif" | "tiff" => {
58 FileKind::Image
59 }
60 "zip" | "rar" | "7z" | "tar" | "gz" | "tgz" => FileKind::Archive,
61 _ => FileKind::Other,
62 }
63 }
64}
65
66#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67pub struct QuoteInfo {
68 pub message_id: String,
69 pub preview: String,
70 pub sender_name: Option<String>,
71}
72
73/// Image inside a message body. `key()` is the image cache key.
74#[derive(Debug, Clone, PartialEq, Eq)]
75pub struct ImageRef {
76 pub id: String,
77 pub url: String,
78 pub width: Option<u32>,
79 pub height: Option<u32>,
80 pub alt: Option<String>,
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq)]
84pub enum ImageKind {
85 Inline,
86 Gif,
87 Sticker,
88}
89
90impl ImageRef {
91 pub fn key(&self) -> &str {
92 &self.url
93 }
94
95 pub fn kind(&self) -> ImageKind {
96 match external_image_url(&self.url) {
97 None => ImageKind::Inline,
98 Some(direct) if is_giphy_url(&direct) => ImageKind::Gif,
99 Some(_) => ImageKind::Sticker,
100 }
101 }
102}
103
104impl AttachmentInfo {
105 pub fn is_card(&self) -> bool {
106 self.content_type
107 .as_deref()
108 .is_some_and(|content_type| content_type.contains("card"))
109 }
110
111 pub fn adaptive_card(&self) -> Option<AdaptiveCard> {
112 self.content
113 .as_deref()
114 .filter(|_| self.is_card())
115 .and_then(AdaptiveCard::parse)
116 }
117
118 pub fn card_text(&self) -> Option<String> {
119 let content = self.content.as_deref().filter(|_| self.is_card())?;
120 card_content_text(content).or_else(|| self.text.clone())
121 }
122
123 pub fn file_kind(&self) -> FileKind {
124 match self.name.as_deref().map(FileKind::from_name) {
125 Some(FileKind::Other) | None if self.has_image_content_type() => FileKind::Image,
126 Some(kind) => kind,
127 None => FileKind::Other,
128 }
129 }
130
131 fn has_image_content_type(&self) -> bool {
132 self.content_type
133 .as_deref()
134 .is_some_and(|content_type| content_type.starts_with("image/"))
135 }
136
137 pub fn is_file(&self) -> bool {
138 self.content_type.as_deref() == Some("reference") && self.url.is_some()
139 }
140}
141
142#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
143pub struct ReactionInfo {
144 pub reaction_type: String,
145 pub user_id: Option<String>,
146 pub user_name: Option<String>,
147 #[serde(default)]
148 pub created_at: Option<DateTime<Utc>>,
149}
150
151#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
152pub struct MentionInfo {
153 pub user_id: Option<String>,
154 pub name: String,
155 #[serde(default)]
156 pub id: Option<i64>,
157 #[serde(default)]
158 pub target_id: Option<String>,
159 #[serde(default)]
160 pub group: bool,
161}
162
163pub fn attachments(record: &MessageRecord) -> Vec<AttachmentInfo> {
164 serde_json::from_str(&record.attachments_json).unwrap_or_default()
165}
166
167pub fn adaptive_cards(record: &MessageRecord) -> Vec<AdaptiveCard> {
168 attachments(record)
169 .iter()
170 .filter_map(AttachmentInfo::adaptive_card)
171 .collect()
172}
173
174pub fn card_texts(record: &MessageRecord) -> Vec<String> {
175 attachments(record)
176 .iter()
177 .filter_map(AttachmentInfo::card_text)
178 .collect()
179}
180
181pub fn reactions(record: &MessageRecord) -> Vec<ReactionInfo> {
182 serde_json::from_str(&record.reactions_json).unwrap_or_default()
183}
184
185pub fn mentions(record: &MessageRecord) -> Vec<MentionInfo> {
186 let mut infos: Vec<MentionInfo> =
187 serde_json::from_str(&record.mentions_json).unwrap_or_default();
188 for (index, info) in infos.iter_mut().enumerate() {
189 info.id = info.id.or(i64::try_from(index).ok());
190 info.target_id = info.target_id.take().or_else(|| info.user_id.clone());
191 }
192 infos
193}
194
195pub fn quotes(record: &MessageRecord) -> Vec<QuoteInfo> {
196 attachments(record)
197 .into_iter()
198 .filter_map(|attachment| attachment.quote)
199 .collect()
200}
201
202pub fn message_quote(record: &MessageRecord) -> Option<QuoteInfo> {
203 quotes(record)
204 .into_iter()
205 .next()
206 .or_else(|| inline_reply_quote(record))
207}
208
209fn inline_reply_quote(record: &MessageRecord) -> Option<QuoteInfo> {
210 let fragment = Html::parse_fragment(&record.body_html);
211 let blockquote = fragment
212 .root_element()
213 .descendants()
214 .filter_map(ElementRef::wrap)
215 .find(|element| {
216 element.value().name() == "blockquote"
217 && element
218 .value()
219 .attr("itemtype")
220 .is_some_and(|itemtype| itemtype.contains(REPLY_ITEMTYPE))
221 && !element
222 .ancestors()
223 .filter_map(ElementRef::wrap)
224 .any(|ancestor| ancestor.value().name() == "blockquote")
225 })?;
226 let text_of = |property: &str| {
227 blockquote
228 .descendants()
229 .filter_map(ElementRef::wrap)
230 .find(|element| element.value().attr("itemprop") == Some(property))
231 .map(|element| element.text().collect::<String>().trim().to_owned())
232 .filter(|text| !text.is_empty())
233 };
234 Some(QuoteInfo {
235 message_id: blockquote.value().attr("itemid")?.to_owned(),
236 preview: text_of("preview").unwrap_or_default(),
237 sender_name: text_of("mri"),
238 })
239}
240
241pub fn images(record: &MessageRecord) -> Vec<ImageRef> {
242 if record.deleted {
243 return Vec::new();
244 }
245 let fragment = Html::parse_fragment(&inline_forwards(record, record.body_html.clone(), &no_forward_header));
246 let mut found: Vec<ImageRef> = Vec::new();
247 for element in fragment
248 .root_element()
249 .descendants()
250 .filter_map(ElementRef::wrap)
251 {
252 let value = element.value();
253 let is_emoji = value
254 .attr("itemtype")
255 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
256 let Some(url) = value
257 .attr("src")
258 .filter(|url| value.name() == "img" && !is_emoji && !url.is_empty())
259 else {
260 continue;
261 };
262 if found.iter().any(|image| image.url == url) {
263 continue;
264 }
265 let style = value.attr("style").unwrap_or_default();
266 found.push(ImageRef {
267 id: image_id(found.len(), url),
268 url: url.to_owned(),
269 width: dimension(value.attr("width"), style, "width"),
270 height: dimension(value.attr("height"), style, "height"),
271 alt: value
272 .attr("alt")
273 .map(str::trim)
274 .filter(|alt| !alt.is_empty())
275 .map(str::to_owned),
276 });
277 }
278 found
279}
280
281#[derive(Debug, Clone, Default, PartialEq, Eq)]
282pub struct EditPreserved {
283 pub images_html: String,
284 pub files: Vec<graph::FileReference>,
285 pub kept: Vec<graph::KeptAttachment>,
286}
287
288/// What an edit must carry over: the `<img>` elements, the file attachments and the quote or card attachments, each matched to its `<attachment id>` tag.
289pub fn edit_preserved(record: &MessageRecord) -> EditPreserved {
290 let fragment = Html::parse_fragment(&record.body_html);
291 let mut preserved = EditPreserved::default();
292 let mut tag_ids: Vec<&str> = Vec::new();
293 for element in fragment
294 .root_element()
295 .descendants()
296 .filter_map(ElementRef::wrap)
297 {
298 let value = element.value();
299 let is_emoji = value
300 .attr("itemtype")
301 .is_some_and(|itemtype| itemtype.contains(EMOJI_ITEMTYPE));
302 match value.name() {
303 "img" if !is_emoji && value.attr("src").is_some_and(|src| !src.is_empty()) => {
304 preserved
305 .images_html
306 .push_str(&format!("<p>{}</p>", element.html()));
307 }
308 "attachment" => tag_ids.extend(value.attr("id")),
309 _ => {}
310 }
311 }
312 let stored = attachments(record);
313 let attachment_id = |attachment: &AttachmentInfo| {
314 attachment.id.clone().or_else(|| {
315 attachment
316 .quote
317 .as_ref()
318 .map(|quote| quote.message_id.clone())
319 })
320 };
321 let mut unclaimed: Vec<&str> = tag_ids
322 .iter()
323 .copied()
324 .filter(|id| {
325 !stored.iter().any(|attachment| {
326 !attachment.is_file() && attachment_id(attachment).as_deref() == Some(*id)
327 })
328 })
329 .collect();
330 for attachment in stored {
331 if attachment.is_file() {
332 let id = match attachment_id(&attachment) {
333 Some(id) if tag_ids.contains(&id.as_str()) => id,
334 Some(_) => continue,
335 None if unclaimed.is_empty() => continue,
336 None => unclaimed.remove(0).to_owned(),
337 };
338 if let Some(content_url) = attachment.url {
339 preserved.files.push(graph::FileReference {
340 attachment_id: id,
341 content_url,
342 name: attachment.name.unwrap_or_default(),
343 });
344 }
345 } else if let Some(id) = attachment_id(&attachment)
346 && tag_ids.contains(&id.as_str())
347 && attachment.content.is_some()
348 {
349 preserved.kept.push(graph::KeptAttachment {
350 id,
351 content_type: attachment.content_type,
352 content: attachment.content,
353 content_url: attachment.url,
354 name: attachment.name,
355 });
356 }
357 }
358 preserved
359}
360
361#[derive(Debug, Clone, PartialEq, Eq)]
362pub struct FileCard {
363 pub name: String,
364 pub kind: FileKind,
365 pub content_type: Option<String>,
366 pub size: Option<u64>,
367 pub open_url: String,
368}
369
370/// File attachments (`reference` type) with a name and a URL. `size` is rarely known; Graph does not send it for these.
371pub fn files(record: &MessageRecord) -> Vec<FileCard> {
372 attachments(record)
373 .into_iter()
374 .filter(AttachmentInfo::is_file)
375 .map(|attachment| FileCard {
376 kind: attachment.file_kind(),
377 name: attachment.name.clone().unwrap_or_default(),
378 content_type: attachment.content_type.clone(),
379 size: attachment.size,
380 open_url: attachment.url.clone().unwrap_or_default(),
381 })
382 .collect()
383}
384
385/// Text for the clipboard: body and card text, mentions as `@name`, no markup.
386pub fn copy_text(record: &MessageRecord) -> String {
387 let mut text = String::new();
388 push_plain(&mut text, &message_spans(record));
389 for extra_text in forwarded_texts(record).into_iter().chain(card_texts(record)) {
390 text.push('\n');
391 text.push_str(&extra_text);
392 }
393 text.trim().to_owned()
394}
395
396pub fn readable_text(record: &MessageRecord) -> String {
397 if let Some(event) = crate::call_event::call_event(record) {
398 return event.plain_text();
399 }
400 let spans: Vec<Span> = message_spans(record)
401 .into_iter()
402 .filter(|span| !matches!(span, Span::Quote { .. }))
403 .collect();
404 let mut text = String::new();
405 push_plain(&mut text, &spans);
406 text.trim().to_owned()
407}
408
409#[derive(Debug, Clone, PartialEq, Eq)]
410pub struct ReactionSummary {
411 pub emoji: String,
412 pub count: usize,
413 pub mine: bool,
414}
415
416pub fn reaction_summaries(
417 record: &MessageRecord,
418 my_user_id: Option<&str>,
419) -> Vec<ReactionSummary> {
420 let mut summaries: Vec<ReactionSummary> = Vec::new();
421 for reaction in reactions(record) {
422 let emoji = base_reaction_emoji(&reaction.reaction_type);
423 let position = match summaries.iter().position(|summary| summary.emoji == emoji) {
424 Some(position) => position,
425 None => {
426 summaries.push(ReactionSummary {
427 emoji,
428 count: 0,
429 mine: false,
430 });
431 summaries.len() - 1
432 }
433 };
434 let summary = &mut summaries[position];
435 summary.count += 1;
436 summary.mine |= my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id;
437 }
438 summaries
439}
440
441fn base_reaction_emoji(reaction_type: &str) -> String {
442 let legacy = match reaction_type {
443 "like" => "\u{1F44D}",
444 "heart" => "\u{2764}",
445 "laugh" => "\u{1F606}",
446 "surprised" => "\u{1F62E}",
447 "sad" => "\u{1F641}",
448 "angry" => "\u{1F620}",
449 other => other,
450 };
451 legacy
452 .chars()
453 .filter(|character| {
454 *character != '\u{FE0F}' && !('\u{1F3FB}'..='\u{1F3FF}').contains(character)
455 })
456 .collect()
457}
458
459pub(crate) fn push_plain(text: &mut String, spans: &[Span]) {
460 for span in spans {
461 match span {
462 Span::Text(value) | Span::Code(value) => text.push_str(value),
463 Span::CodeBlock { code, .. } => {
464 text.push_str(code);
465 text.push('\n');
466 }
467 Span::Bold(children)
468 | Span::Italic(children)
469 | Span::Strike(children)
470 | Span::Superscript(children)
471 | Span::Subscript(children)
472 | Span::Sized(_, children)
473 | Span::Underline(children)
474 | Span::Colored { children, .. }
475 | Span::Quote { children, .. }
476 | Span::BlockQuote(children)
477 | Span::Link { children, .. } => push_plain(text, children),
478 Span::Heading { children, .. } => {
479 push_plain(text, children);
480 text.push('\n');
481 }
482 Span::Mention { name, .. } => {
483 text.push('@');
484 text.push_str(name);
485 }
486 Span::LineBreak | Span::Rule => text.push('\n'),
487 Span::List {
488 ordered,
489 start,
490 items,
491 } => {
492 for (offset, item) in items.iter().enumerate() {
493 if *ordered {
494 text.push_str(&format!("{}. ", *start as usize + offset));
495 } else {
496 text.push_str("- ");
497 }
498 push_plain(text, item);
499 text.push('\n');
500 }
501 }
502 Span::Table { rows, .. } => {
503 for row in rows {
504 for (index, cell) in row.iter().enumerate() {
505 if index > 0 {
506 text.push('\t');
507 }
508 push_plain(text, cell);
509 }
510 text.push('\n');
511 }
512 }
513 Span::Image { .. } => {}
514 }
515 }
516}
517
518/// Own, not deleted. Whether the conversation supports the write is the engine's call.
519pub fn can_edit(record: &MessageRecord, my_user_id: &str) -> bool {
520 !record.deleted && record.sender_id.as_deref() == Some(my_user_id)
521}
522
523pub fn can_delete(record: &MessageRecord, my_user_id: &str) -> bool {
524 can_edit(record, my_user_id)
525}
526
527/// Position in the message plus an FNV-1a hash of the URL, so two GIFs from the same host never share an id.
528fn image_id(position: usize, url: &str) -> String {
529 let hash = url.bytes().fold(0x811c_9dc5_u32, |hash, byte| {
530 (hash ^ u32::from(byte)).wrapping_mul(0x0100_0193)
531 });
532 format!("{position}-{hash:08x}")
533}
534
535fn dimension(attribute: Option<&str>, style: &str, property: &str) -> Option<u32> {
536 let from_style = || {
537 style.split(';').find_map(|declaration| {
538 let (name, value) = declaration.split_once(':')?;
539 (name.trim() == property).then(|| leading_number(value))?
540 })
541 };
542 attribute
543 .and_then(leading_number)
544 .or_else(from_style)
545 .filter(|pixels| *pixels > 0)
546}
547
548fn leading_number(text: &str) -> Option<u32> {
549 let digits: String = text
550 .trim()
551 .chars()
552 .take_while(char::is_ascii_digit)
553 .collect();
554 digits.parse().ok()
555}
556
557pub fn message_spans(record: &MessageRecord) -> Vec<Span> {
558 spans_with_mentions(record, &mentions(record))
559}
560
561pub const PROFILE_LINK_PREFIX: &str = "teams-profile:";
562
563/// Like `message_spans`, with the id of each user mention replaced by a profile link.
564pub fn linked_message_spans(record: &MessageRecord) -> Vec<Span> {
565 linked_message_spans_with(record, &|_| None, &no_forward_header)
566}
567
568/// Like `linked_message_spans`, but a quote shows `quoted_text(message_id)` when known instead of the one-line server preview, and a forward shows `forward_header(forward)` above the original.
569pub fn linked_message_spans_with(
570 record: &MessageRecord,
571 quoted_text: &dyn Fn(&str) -> Option<String>,
572 forward_header: &dyn Fn(&ForwardInfo) -> ForwardHeader,
573) -> Vec<Span> {
574 let infos = mentions(record);
575 let html = inline_forwards(record, with_inline_quotes(record, quoted_text), forward_header);
576 let mut spans = html_to_spans(&html);
577 merge_split_mentions(&mut spans, &infos);
578 link_user_mentions(&mut spans, &infos);
579 spans
580}
581
582/// The spans of `record` with its body replaced by the translated html.
583pub fn translated_spans(
584 record: &MessageRecord,
585 translated_html: &str,
586 forward_header: &dyn Fn(&ForwardInfo) -> ForwardHeader,
587) -> Vec<Span> {
588 let mut translated = record.clone();
589 translated.body_html = translated_html.to_owned();
590 linked_message_spans_with(&translated, &|_| None, forward_header)
591}
592
593fn link_user_mentions(spans: &mut [Span], infos: &[MentionInfo]) {
594 for span in spans {
595 match span {
596 Span::Bold(children)
597 | Span::Italic(children)
598 | Span::Strike(children)
599 | Span::Superscript(children)
600 | Span::Subscript(children)
601 | Span::Sized(_, children)
602 | Span::Underline(children)
603 | Span::Colored { children, .. }
604 | Span::Heading { children, .. }
605 | Span::Quote { children, .. }
606 | Span::BlockQuote(children)
607 | Span::Link { children, .. } => link_user_mentions(children, infos),
608 Span::List { items, .. } => items
609 .iter_mut()
610 .for_each(|item| link_user_mentions(item, infos)),
611 Span::Table { rows, .. } => rows
612 .iter_mut()
613 .flatten()
614 .for_each(|cell| link_user_mentions(cell, infos)),
615 Span::Mention { id, .. } => {
616 let parsed: Option<i64> = id.as_deref().and_then(|id| id.parse().ok());
617 let user_id = infos
618 .iter()
619 .find(|info| parsed.is_some() && info.id == parsed)
620 .and_then(|info| info.user_id.as_deref());
621 if let Some(user_id) = user_id {
622 *id = Some(format!("{PROFILE_LINK_PREFIX}{user_id}"));
623 }
624 }
625 _ => {}
626 }
627 }
628}
629
630fn spans_with_mentions(record: &MessageRecord, infos: &[MentionInfo]) -> Vec<Span> {
631 let mut spans = html_to_spans(&with_inline_quotes(record, &|_| None));
632 merge_split_mentions(&mut spans, infos);
633 spans
634}
635
636fn with_inline_quotes(record: &MessageRecord, quoted_text: &dyn Fn(&str) -> Option<String>) -> String {
637 let mut html = record.body_html.clone();
638 for attachment in attachments(record) {
639 let Some(mut quote) = attachment.quote else {
640 continue;
641 };
642 if let Some(text) = quoted_text(&quote.message_id).filter(|text| !text.trim().is_empty()) {
643 quote.preview = text;
644 }
645 let id = attachment.id.unwrap_or_else(|| quote.message_id.clone());
646 let tag = format!("<attachment id=\"{id}\"></attachment>");
647 let block = quote_html(&quote);
648 if html.contains(&tag) {
649 html = html.replacen(&tag, &block, 1);
650 } else {
651 html.insert_str(0, &block);
652 }
653 }
654 html
655}
656
657pub fn quote_html(quote: &QuoteInfo) -> String {
658 let sender = quote
659 .sender_name
660 .as_deref()
661 .map(|name| format!("<strong itemprop=\"mri\">{}</strong>", escape_html(name)))
662 .unwrap_or_default();
663 let time = quote_time(&quote.message_id)
664 .map(|time| format!(" <span itemprop=\"time\">{time}</span>"))
665 .unwrap_or_default();
666 let preview = escape_html(quote.preview.trim()).replace('\n', "<br>");
667 format!(
668 "<blockquote itemscope=\"\" itemtype=\"http://{REPLY_ITEMTYPE}\" itemid=\"{}\">{sender}{time}<p itemprop=\"preview\">{preview}</p></blockquote>",
669 escape_html(&quote.message_id),
670 )
671}
672
673fn quote_time(message_id: &str) -> Option<String> {
674 let millis = message_id.parse::<i64>().ok()?;
675 let time = chrono::DateTime::from_timestamp_millis(millis)?;
676 Some(time.with_timezone(&chrono::Local).format("%d/%m/%Y %H:%M").to_string())
677}
678
679pub fn user_mention_inputs(record: &MessageRecord) -> Vec<MentionInput> {
680 let infos = mentions(record);
681 let mut inputs = Vec::new();
682 collect_user_mentions(&spans_with_mentions(record, &infos), &infos, &mut inputs);
683 inputs
684}
685
686fn collect_user_mentions(spans: &[Span], infos: &[MentionInfo], inputs: &mut Vec<MentionInput>) {
687 for span in spans {
688 match span {
689 Span::Bold(children)
690 | Span::Italic(children)
691 | Span::Strike(children)
692 | Span::Superscript(children)
693 | Span::Subscript(children)
694 | Span::Sized(_, children)
695 | Span::Underline(children)
696 | Span::Colored { children, .. }
697 | Span::Heading { children, .. }
698 | Span::Quote { children, .. }
699 | Span::BlockQuote(children)
700 | Span::Link { children, .. } => collect_user_mentions(children, infos, inputs),
701 Span::List { items, .. } => items
702 .iter()
703 .for_each(|item| collect_user_mentions(item, infos, inputs)),
704 Span::Table { rows, .. } => rows
705 .iter()
706 .flatten()
707 .for_each(|cell| collect_user_mentions(cell, infos, inputs)),
708 Span::Mention { name, id } => {
709 let parsed: Option<i64> = id.as_deref().and_then(|id| id.parse().ok());
710 let user_id = infos
711 .iter()
712 .find(|info| parsed.is_some() && info.id == parsed)
713 .and_then(|info| info.user_id.as_deref());
714 if let Some(user_id) = user_id {
715 inputs.push(MentionInput::user(user_id, name));
716 }
717 }
718 _ => {}
719 }
720 }
721}
722
723fn merge_split_mentions(spans: &mut Vec<Span>, mentions: &[MentionInfo]) {
724 let target_of = |id: &Option<String>| -> Option<String> {
725 let parsed: i64 = id.as_deref()?.parse().ok()?;
726 mentions
727 .iter()
728 .find(|info| info.id == Some(parsed))?
729 .target_id
730 .clone()
731 };
732 let mut merged: Vec<Span> = Vec::with_capacity(spans.len());
733 for mut span in std::mem::take(spans) {
734 match &mut span {
735 Span::Bold(children)
736 | Span::Italic(children)
737 | Span::Strike(children)
738 | Span::Superscript(children)
739 | Span::Subscript(children)
740 | Span::Sized(_, children)
741 | Span::Underline(children)
742 | Span::Colored { children, .. }
743 | Span::Heading { children, .. }
744 | Span::Quote { children, .. }
745 | Span::BlockQuote(children)
746 | Span::Link { children, .. } => merge_split_mentions(children, mentions),
747 Span::List { items, .. } => items
748 .iter_mut()
749 .for_each(|item| merge_split_mentions(item, mentions)),
750 Span::Table { rows, .. } => rows
751 .iter_mut()
752 .flatten()
753 .for_each(|cell| merge_split_mentions(cell, mentions)),
754 Span::Mention { name, id } => {
755 let continues = match merged.as_slice() {
756 [
757 ..,
758 Span::Mention {
759 id: previous_id, ..
760 },
761 Span::Text(gap),
762 ] => {
763 gap.trim().is_empty()
764 && target_of(id).is_some()
765 && target_of(previous_id) == target_of(id)
766 }
767 _ => false,
768 };
769 if continues {
770 merged.pop();
771 if let Some(Span::Mention {
772 name: previous_name,
773 ..
774 }) = merged.last_mut()
775 {
776 previous_name.push(' ');
777 previous_name.push_str(name);
778 }
779 continue;
780 }
781 }
782 _ => {}
783 }
784 merged.push(span);
785 }
786 *spans = merged;
787}
788
789#[cfg(test)]
790mod tests {
791 use chrono::Utc;
792
793 use super::*;
794
795 fn record(body_html: &str, attachments_json: &str) -> MessageRecord {
796 MessageRecord {
797 subject: None,
798 conversation_id: "c".to_owned(),
799 message_id: "m".to_owned(),
800 reply_to_id: None,
801 sender_id: Some("u".to_owned()),
802 sender_name: None,
803 sender_application_id: None,
804 links_json: "[]".to_owned(),
805 created_at: Utc::now(),
806 edited_at: None,
807 deleted: false,
808 body_html: body_html.to_owned(),
809 attachments_json: attachments_json.to_owned(),
810 reactions_json: "[]".to_owned(),
811 mentions_json: "[]".to_owned(),
812 call_event_json: None,
813 }
814 }
815
816 #[test]
817 fn reaction_without_created_at_still_parses() {
818 let mut stored = record("", "[]");
819 stored.reactions_json =
820 r#"[{"reaction_type":"like","user_id":"u","user_name":null}]"#.to_owned();
821 let parsed = reactions(&stored);
822 assert_eq!(parsed.len(), 1);
823 assert_eq!(parsed[0].created_at, None);
824 }
825
826 #[test]
827 fn images_cover_hosted_contents_and_ams_and_skip_emoji() {
828 let html = concat!(
829 r#"<p>a</p><img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value" style="width:300px; height: 120px">"#,
830 r#"<img itemtype="http://schema.skype.com/AMSImage" src="https://eu-api.asm.skype.com/v1/objects/0-weu-d1-abc/views/imgo" width="64" height="auto">"#,
831 r#"<img itemtype="http://schema.skype.com/Emoji" src="https://x/e.png" alt="x">"#,
832 r#"<img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value">"#,
833 );
834 let found = images(&record(html, "[]"));
835 assert_eq!(found.len(), 2);
836 assert_eq!((found[0].width, found[0].height), (Some(300), Some(120)));
837 assert_eq!((found[1].width, found[1].height), (Some(64), None));
838 assert!(found[0].id.starts_with("0-"));
839 assert!(found[1].id.starts_with("1-"));
840 }
841
842 #[test]
843 fn two_giphy_gifs_get_different_image_ids_and_the_gif_kind() {
844 let html = concat!(
845 r#"<img src="https://media0.giphy.com/media/abc/giphy.gif" alt=" dancing cat ">"#,
846 r#"<img src="https://media1.giphy.com/media/def/giphy.gif">"#,
847 r#"<img src="https://statics.teams.cdn.office.net/evergreen-assets/stickerassets/a/b.gif">"#,
848 r#"<img src="https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/aWQ9/$value">"#,
849 );
850 let found = images(&record(html, "[]"));
851 let ids: std::collections::HashSet<&str> =
852 found.iter().map(|image| image.id.as_str()).collect();
853 assert_eq!(ids.len(), 4);
854 assert_eq!(found[0].id, images(&record(html, "[]"))[0].id);
855 assert_eq!(found[0].alt.as_deref(), Some("dancing cat"));
856 assert_eq!(found[1].alt, None);
857 let kinds: Vec<ImageKind> = found.iter().map(ImageRef::kind).collect();
858 assert_eq!(
859 kinds,
860 [
861 ImageKind::Gif,
862 ImageKind::Gif,
863 ImageKind::Sticker,
864 ImageKind::Inline
865 ]
866 );
867 }
868
869 #[test]
870 fn readable_text_keeps_lines_lists_code_and_mentions_and_drops_the_reply_quote() {
871 let html = concat!(
872 r#"<blockquote itemscope="" itemtype="http://schema.skype.com/Reply" itemid="Q0"><strong itemprop="mri">Bob</strong><p itemprop="preview">old words</p></blockquote>"#,
873 r#"<p>Hi <at id="0">Ada</at></p><ul><li>one</li><li>two</li></ul><pre>let x = 1;</pre><p>last</p>"#,
874 );
875 let json = r#"[{"user_id":"U1","name":"Ada","id":0,"target_id":"U1"}]"#;
876 let text = readable_text(&with_mentions(html, json));
877 assert!(!text.contains("old words"), "{text}");
878 assert!(!text.contains("Bob"), "{text}");
879 assert!(text.starts_with("Hi @Ada\n"), "{text}");
880 assert!(text.contains("- one\n- two\n"), "{text}");
881 assert!(text.contains("let x = 1;\n"), "{text}");
882 assert!(text.ends_with("last"), "{text}");
883 }
884
885 #[test]
886 fn a_quote_keeps_its_lines_and_shows_when_the_quoted_message_was_sent() {
887 let html = quote_html(&QuoteInfo {
888 message_id: "1760517360000".to_owned(),
889 preview: "first link\nsecond link".to_owned(),
890 sender_name: Some("Ada".to_owned()),
891 });
892 assert!(html.contains("first link<br>second link"), "{html}");
893 assert!(html.contains("/2025 "), "{html}");
894 let without_time = quote_html(&QuoteInfo {
895 message_id: "Q9".to_owned(),
896 preview: "text".to_owned(),
897 sender_name: None,
898 });
899 assert!(!without_time.contains("itemprop=\"time\""), "{without_time}");
900 }
901
902 #[test]
903 fn a_reply_blockquote_in_the_body_becomes_the_quote() {
904 let html = format!(
905 "{}<p>answer</p>",
906 quote_html(&QuoteInfo {
907 message_id: "Q9".to_owned(),
908 preview: "a < b".to_owned(),
909 sender_name: Some("Ada".to_owned()),
910 })
911 );
912 let stored = record(&html, "[]");
913 assert_eq!(
914 message_quote(&stored),
915 Some(QuoteInfo {
916 message_id: "Q9".to_owned(),
917 preview: "a < b".to_owned(),
918 sender_name: Some("Ada".to_owned()),
919 })
920 );
921 assert_eq!(readable_text(&stored), "answer");
922 assert_eq!(message_quote(&record("<p>plain</p>", "[]")), None);
923 }
924
925 #[test]
926 fn a_reply_blockquote_nested_in_a_normal_blockquote_is_not_the_quote() {
927 let html = format!(
928 "<blockquote>{}</blockquote><p>answer</p>",
929 quote_html(&QuoteInfo {
930 message_id: "Q9".to_owned(),
931 preview: "inner".to_owned(),
932 sender_name: None,
933 })
934 );
935 assert_eq!(message_quote(&record(&html, "[]")), None);
936 }
937
938 #[test]
939 fn readable_text_drops_the_stored_quote_and_card_text() {
940 let json = r#"[{"content_type":"messageReference","name":null,"url":null,"text":null,"id":"Q1","quote":{"message_id":"Q1","preview":"quoted","sender_name":"Ada"}}]"#;
941 let stored = record("<attachment id=\"Q1\"></attachment><p>answer</p>", json);
942 assert_eq!(readable_text(&stored), "answer");
943 }
944
945 #[test]
946 fn reactions_group_by_base_emoji_and_merge_skin_tones() {
947 let mut stored = record("", "[]");
948 stored.reactions_json = r#"[
949 {"reaction_type":"like","user_id":"a"},
950 {"reaction_type":"\ud83d\udc4d\ud83c\udffd","user_id":"me"},
951 {"reaction_type":"\ud83d\udc4d","user_id":"b"},
952 {"reaction_type":"heart","user_id":"a"},
953 {"reaction_type":"\u2764\ufe0f","user_id":"c"}
954 ]"#
955 .to_owned();
956 let summaries = reaction_summaries(&stored, Some("me"));
957 assert_eq!(
958 summaries,
959 vec![
960 ReactionSummary {
961 emoji: "\u{1F44D}".to_owned(),
962 count: 3,
963 mine: true
964 },
965 ReactionSummary {
966 emoji: "\u{2764}".to_owned(),
967 count: 2,
968 mine: false
969 },
970 ]
971 );
972 assert!(
973 reaction_summaries(&stored, None)
974 .iter()
975 .all(|summary| !summary.mine)
976 );
977 }
978
979 #[test]
980 fn deleted_messages_have_no_images() {
981 let mut deleted = record(r#"<img src="https://x/y">"#, "[]");
982 deleted.deleted = true;
983 assert!(images(&deleted).is_empty());
984 }
985
986 #[test]
987 fn edits_keep_images_and_match_files_to_their_attachment_tags() {
988 let html = "<p>text</p><p><img src=\"https://graph.microsoft.com/v1.0/chats/c/messages/1/hostedContents/9/$value\"></p><attachment id=\"G1\"></attachment>";
989 let attachments = r#"[{"content_type":"reference","name":"a.pdf","url":"https://x/a.pdf","text":null,"id":"G1"}]"#;
990 let preserved = edit_preserved(&record(html, attachments));
991 assert!(
992 preserved
993 .images_html
994 .starts_with("<p><img src=\"https://graph.microsoft.com/")
995 );
996 assert!(!preserved.images_html.contains("text"));
997 assert_eq!(preserved.files.len(), 1);
998 assert_eq!(preserved.files[0].attachment_id, "G1");
999 assert_eq!(preserved.files[0].content_url, "https://x/a.pdf");
1000 assert_eq!(preserved.files[0].name, "a.pdf");
1001 assert!(preserved.kept.is_empty());
1002 }
1003
1004 const QUOTED_HTML: &str =
1005 "<attachment id=\"Q1\"></attachment><p>answer</p><attachment id=\"F1\"></attachment>";
1006
1007 #[test]
1008 fn a_quoted_reply_keeps_its_quote_and_pairs_the_file_by_id() {
1009 let attachments = r#"[
1010 {"content_type":"messageReference","name":null,"url":null,"text":null,"id":"Q1","content":"{\"messageId\":\"Q1\",\"messagePreview\":\"hi\"}","quote":{"message_id":"Q1","preview":"hi","sender_name":null}},
1011 {"content_type":"reference","name":"a.pdf","url":"https://x/a.pdf","text":null,"id":"F1"}
1012 ]"#;
1013 let preserved = edit_preserved(&record(QUOTED_HTML, attachments));
1014 assert_eq!(preserved.files.len(), 1);
1015 assert_eq!(preserved.files[0].attachment_id, "F1");
1016 assert_eq!(preserved.kept.len(), 1);
1017 assert_eq!(preserved.kept[0].id, "Q1");
1018 assert_eq!(
1019 preserved.kept[0].content_type.as_deref(),
1020 Some("messageReference")
1021 );
1022 assert!(
1023 preserved.kept[0]
1024 .content
1025 .as_deref()
1026 .unwrap()
1027 .contains("messagePreview")
1028 );
1029 }
1030
1031 #[test]
1032 fn records_cached_before_content_was_stored_leave_the_quote_out() {
1033 let attachments = r#"[
1034 {"content_type":"messageReference","name":null,"url":null,"text":null,"quote":{"message_id":"Q1","preview":"hi","sender_name":null}},
1035 {"content_type":"reference","name":"a.pdf","url":"https://x/a.pdf","text":null}
1036 ]"#;
1037 let preserved = edit_preserved(&record(QUOTED_HTML, attachments));
1038 assert_eq!(preserved.files[0].attachment_id, "F1");
1039 assert!(preserved.kept.is_empty());
1040 }
1041
1042 #[test]
1043 fn file_kind_follows_the_extension_then_the_content_type() {
1044 let kind = |name: Option<&str>, content_type: &str| {
1045 AttachmentInfo {
1046 content_type: Some(content_type.to_owned()),
1047 name: name.map(str::to_owned),
1048 url: None,
1049 text: None,
1050 size: None,
1051 quote: None,
1052 id: None,
1053 content: None,
1054 unavailable: false,
1055 }
1056 .file_kind()
1057 };
1058 assert_eq!(kind(Some("Plan.DOCX"), "reference"), FileKind::Word);
1059 assert_eq!(kind(Some("a.xlsx"), "reference"), FileKind::Excel);
1060 assert_eq!(kind(Some("a.pptx"), "reference"), FileKind::PowerPoint);
1061 assert_eq!(kind(Some("a.pdf"), "reference"), FileKind::Pdf);
1062 assert_eq!(kind(Some("a.PNG"), "reference"), FileKind::Image);
1063 assert_eq!(kind(Some("a.zip"), "reference"), FileKind::Archive);
1064 assert_eq!(kind(Some("a.bin"), "reference"), FileKind::Other);
1065 assert_eq!(kind(None, "image/png"), FileKind::Image);
1066 assert_eq!(kind(Some("noextension"), "reference"), FileKind::Other);
1067 }
1068
1069 #[test]
1070 fn files_expose_name_kind_and_open_url() {
1071 let json = r#"[{"content_type":"reference","name":"Plan.docx","url":"https://x/Plan.docx","text":null},{"content_type":"messageReference","name":null,"url":null,"text":null}]"#;
1072 let found = files(&record("", json));
1073 assert_eq!(found.len(), 1);
1074 assert_eq!(
1075 (found[0].name.as_str(), found[0].kind),
1076 ("Plan.docx", FileKind::Word)
1077 );
1078 assert_eq!(found[0].open_url, "https://x/Plan.docx");
1079 assert_eq!(found[0].size, None);
1080 }
1081
1082 #[test]
1083 fn copy_text_flattens_markup_and_keeps_mentions_and_lines() {
1084 let html = r#"<p>Hi <at id="0">Ada</at>, <b>look</b></p><p>second <a href="https://x">link</a></p>"#;
1085 let text = copy_text(&record(html, "[]"));
1086 assert!(text.starts_with("Hi @Ada, look"), "{text}");
1087 assert!(text.contains("second link"), "{text}");
1088 assert!(text.contains('\n'));
1089 }
1090
1091 #[test]
1092 fn old_cached_attachments_still_parse() {
1093 let parsed = attachments(&record(
1094 "",
1095 r#"[{"content_type":"reference","name":"a.pdf","url":"u","text":null}]"#,
1096 ));
1097 assert_eq!(parsed.len(), 1);
1098 assert!(parsed[0].is_file());
1099 assert_eq!(parsed[0].size, None);
1100 }
1101
1102 #[test]
1103 fn quote_references_are_extracted_from_the_message_reference_attachment() {
1104 let attachment = graph::Attachment {
1105 id: Some("1".to_owned()),
1106 content_type: Some("messageReference".to_owned()),
1107 content_url: None,
1108 name: None,
1109 content: Some(
1110 r#"{"messageId":"1728","messagePreview":"Hello","messageSender":{"user":{"displayName":"Adele"}}}"#.to_owned(),
1111 ),
1112 };
1113 let info = crate::mapping::attachment_info(&attachment);
1114 assert_eq!(
1115 info.quote,
1116 Some(QuoteInfo {
1117 message_id: "1728".to_owned(),
1118 preview: "Hello".to_owned(),
1119 sender_name: Some("Adele".to_owned())
1120 })
1121 );
1122 let stored = record("", &serde_json::to_string(&[info]).unwrap());
1123 assert_eq!(quotes(&stored).len(), 1);
1124 }
1125
1126 #[test]
1127 fn a_message_reference_renders_as_a_reply_quote_where_its_tag_sits() {
1128 let json = r#"[{"content_type":"messageReference","name":null,"url":null,"text":null,"id":"Q1","quote":{"message_id":"Q1","preview":"a < b","sender_name":"Ada"}}]"#;
1129 let stored = record(
1130 "<p></p><attachment id=\"Q1\"></attachment>\ntest<p></p>",
1131 json,
1132 );
1133 let spans = message_spans(&stored);
1134 let Some(Span::Quote { children, .. }) = spans.first() else {
1135 panic!("expected a reply quote first, got {spans:?}");
1136 };
1137 let mut quoted = String::new();
1138 push_plain(&mut quoted, children);
1139 assert!(quoted.contains("Ada"));
1140 assert!(quoted.contains("a < b"));
1141 let mut own = String::new();
1142 push_plain(&mut own, &spans[1..]);
1143 assert_eq!(own.trim(), "test");
1144 }
1145
1146 #[test]
1147 fn a_message_reference_without_its_tag_still_shows_the_quote() {
1148 let json = r#"[{"content_type":"messageReference","name":null,"url":null,"text":null,"quote":{"message_id":"Q1","preview":"hi","sender_name":null}}]"#;
1149 let spans = message_spans(&record("<p>answer</p>", json));
1150 assert!(matches!(spans.first(), Some(Span::Quote { .. })));
1151 }
1152
1153 fn with_mentions(body_html: &str, mentions_json: &str) -> MessageRecord {
1154 let mut stored = record(body_html, "[]");
1155 stored.mentions_json = mentions_json.to_owned();
1156 stored
1157 }
1158
1159 fn mention_names(spans: &[Span]) -> Vec<&str> {
1160 spans
1161 .iter()
1162 .filter_map(|span| match span {
1163 Span::Mention { name, .. } => Some(name.as_str()),
1164 _ => None,
1165 })
1166 .collect()
1167 }
1168
1169 #[test]
1170 fn user_mentions_link_to_their_profile_and_groups_do_not() {
1171 let json = r#"[
1172 {"user_id":"U1","name":"Ada","id":0,"target_id":"U1"},
1173 {"user_id":null,"name":"Team","id":1,"target_id":"T1"}
1174 ]"#;
1175 let html = r#"<at id="0">Ada</at> <at id="1">Team</at>"#;
1176 let ids: Vec<Option<String>> = linked_message_spans(&with_mentions(html, json))
1177 .into_iter()
1178 .filter_map(|span| match span {
1179 Span::Mention { id, .. } => Some(id),
1180 _ => None,
1181 })
1182 .collect();
1183 assert_eq!(
1184 ids,
1185 vec![Some("teams-profile:U1".to_owned()), Some("1".to_owned())]
1186 );
1187 }
1188
1189 #[test]
1190 fn a_tag_mention_split_per_word_merges_into_one() {
1191 let json = r#"[
1192 {"user_id":null,"name":"Tip","id":0,"target_id":"T1"},
1193 {"user_id":null,"name":"of","id":1,"target_id":"T1"},
1194 {"user_id":null,"name":"the","id":2,"target_id":"T1"},
1195 {"user_id":null,"name":"day","id":3,"target_id":"T1"}
1196 ]"#;
1197 let html = r#"<p>Hey <at id="0">Tip</at> <at id="1">of</at> <at id="2">the</at> <at id="3">day</at>!</p>"#;
1198 let spans = message_spans(&with_mentions(html, json));
1199 assert_eq!(mention_names(&spans), vec!["Tip of the day"]);
1200 assert_eq!(
1201 copy_text(&with_mentions(html, json)),
1202 "Hey @Tip of the day!"
1203 );
1204 }
1205
1206 #[test]
1207 fn a_two_word_user_name_merges_but_different_users_stay_apart() {
1208 let json = r#"[
1209 {"user_id":"U1","name":"Ada","id":0,"target_id":"U1"},
1210 {"user_id":"U1","name":"Lovelace","id":1,"target_id":"U1"},
1211 {"user_id":"U2","name":"Bob","id":2,"target_id":"U2"}
1212 ]"#;
1213 let html = r#"<at id="0">Ada</at> <at id="1">Lovelace</at> <at id="2">Bob</at>"#;
1214 let spans = message_spans(&with_mentions(html, json));
1215 assert_eq!(mention_names(&spans), vec!["Ada Lovelace", "Bob"]);
1216 }
1217
1218 #[test]
1219 fn different_users_next_to_each_other_stay_two_mentions() {
1220 let json = r#"[
1221 {"user_id":"U1","name":"Ada","id":0,"target_id":"U1"},
1222 {"user_id":"U2","name":"Bob","id":1,"target_id":"U2"}
1223 ]"#;
1224 let html = r#"<at id="0">Ada</at> <at id="1">Bob</at>"#;
1225 let spans = message_spans(&with_mentions(html, json));
1226 assert_eq!(mention_names(&spans), vec!["Ada", "Bob"]);
1227 }
1228
1229 #[test]
1230 fn nested_split_mentions_merge() {
1231 let json = r#"[
1232 {"user_id":"U1","name":"Ada","id":0,"target_id":"U1"},
1233 {"user_id":"U1","name":"Lovelace","id":1,"target_id":"U1"}
1234 ]"#;
1235 let html = r#"<b><at id="0">Ada</at> <at id="1">Lovelace</at></b>"#;
1236 let spans = message_spans(&with_mentions(html, json));
1237 let [Span::Bold(children)] = spans.as_slice() else {
1238 panic!("bold expected: {spans:?}")
1239 };
1240 assert_eq!(mention_names(children), vec!["Ada Lovelace"]);
1241 }
1242
1243 #[test]
1244 fn old_mention_json_without_ids_merges_users_by_position() {
1245 let json = r#"[{"user_id":"U1","name":"Ada"},{"user_id":"U1","name":"Lovelace"},{"user_id":null,"name":"Tip"},{"user_id":null,"name":"day"}]"#;
1246 let html = r#"<at id="0">Ada</at> <at id="1">Lovelace</at> <at id="2">Tip</at> <at id="3">day</at>"#;
1247 let stored = with_mentions(html, json);
1248 let parsed = mentions(&stored);
1249 assert_eq!(
1250 (parsed[1].id, parsed[1].target_id.as_deref()),
1251 (Some(1), Some("U1"))
1252 );
1253 assert_eq!(
1254 mention_names(&message_spans(&stored)),
1255 vec!["Ada Lovelace", "Tip", "day"]
1256 );
1257 }
1258
1259 #[test]
1260 fn edit_mentions_follow_the_merged_names() {
1261 let json = r#"[
1262 {"user_id":"U1","name":"Ada","id":0,"target_id":"U1"},
1263 {"user_id":"U1","name":"Lovelace","id":1,"target_id":"U1"},
1264 {"user_id":"U2","name":"Bob","id":2,"target_id":"U2"}
1265 ]"#;
1266 let html = r#"<at id="0">Ada</at> <at id="1">Lovelace</at> and <at id="2">Bob</at>"#;
1267 assert_eq!(
1268 user_mention_inputs(&with_mentions(html, json)),
1269 vec![
1270 MentionInput::user("U1", "Ada Lovelace"),
1271 MentionInput::user("U2", "Bob"),
1272 ]
1273 );
1274 }
1275}