BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / pending_rows.rs

pending_rows.rs

pending_rows.rs 2.4 KiB Download Raw
1use chrono::{DateTime, Local, Utc};
2use teams_core::FileCard;
3
4use crate::render::layout_blocks;
5use crate::rows::{Delivery, LocalImage, MessageRow, Receipt, Series};
6use crate::views::attachment_tray::OutgoingImage;
7use crate::views::composer::Outgoing;
8
9pub fn pending_row(
10 key: String,
11 conversation_id: String,
12 my_user_id: Option<String>,
13 created_at: DateTime<Utc>,
14 outgoing: &Outgoing,
15 delivery: Delivery,
16) -> MessageRow {
17 MessageRow {
18 key,
19 conversation_id,
20 author: "You".to_owned(),
21 sender_id: my_user_id,
22 application_id: None,
23 created_at,
24 series: Series::default(),
25 time: created_at.with_timezone(&Local).format("%H:%M").to_string(),
26 day_header: None,
27 blocks: if outgoing.draft.is_blank() && outgoing.images.is_empty() {
28 Vec::new()
29 } else {
30 layout_blocks(&teams_core::html_to_spans(&outgoing.html()))
31 },
32 edited: false,
33 deleted: false,
34 reactions: Vec::new(),
35 images: outgoing
36 .images
37 .iter()
38 .filter_map(|image| match image {
39 OutgoingImage::Remote(remote) => Some(remote.image_ref()),
40 OutgoingImage::Inline(_) => None,
41 })
42 .collect(),
43 local_images: outgoing
44 .images
45 .iter()
46 .filter_map(|image| match image {
47 OutgoingImage::Inline(inline) => Some(LocalImage {
48 image: inline.image.clone(),
49 size: inline.dimensions,
50 }),
51 OutgoingImage::Remote(_) => None,
52 })
53 .collect(),
54 adaptive_cards: Vec::new(),
55 link_preview: outgoing.link_preview.clone(),
56 meeting_link: teams_core::meeting_link_in_html(&outgoing.html()),
57 files: outgoing
58 .files
59 .iter()
60 .map(|file| FileCard {
61 name: file.name.clone(),
62 kind: file.kind,
63 content_type: None,
64 size: Some(file.size),
65 open_url: file.reference.content_url.clone(),
66 })
67 .collect(),
68 subject: outgoing.subject.clone(),
69 new_marker: false,
70 reply_root: None,
71 delivery,
72 receipt: Receipt::Hidden,
73 own: true,
74 forwarded: false,
75 translation: None,
76 }
77}