BlueGit

ict rusty-teams

Files

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

pending_rows.rs

pending_rows.rs 2.3 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 card: false,
26 time: created_at.with_timezone(&Local).format("%H:%M").to_string(),
27 day_header: None,
28 blocks: if outgoing.draft.is_blank() && outgoing.images.is_empty() {
29 Vec::new()
30 } else {
31 layout_blocks(&teams_core::html_to_spans(&outgoing.html()))
32 },
33 edited: false,
34 deleted: false,
35 reactions: Vec::new(),
36 images: outgoing
37 .images
38 .iter()
39 .filter_map(|image| match image {
40 OutgoingImage::Remote(remote) => Some(remote.image_ref()),
41 OutgoingImage::Inline(_) => None,
42 })
43 .collect(),
44 local_images: outgoing
45 .images
46 .iter()
47 .filter_map(|image| match image {
48 OutgoingImage::Inline(inline) => Some(LocalImage {
49 image: inline.image.clone(),
50 size: inline.dimensions,
51 }),
52 OutgoingImage::Remote(_) => None,
53 })
54 .collect(),
55 adaptive_cards: Vec::new(),
56 link_preview: outgoing.link_preview.clone(),
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 reply_count: None,
69 new_marker: false,
70 reply_faces: Vec::new(),
71 last_reply_time: None,
72 open_thread: None,
73 is_reply: false,
74 delivery,
75 receipt: Receipt::Hidden,
76 own: true,
77 }
78}