BlueGit

ict rusty-teams

feat(kvt): organisatie-emoji-metadata en afbeeldingen (WIP, lokale back-up)

Derde snapshot van het werk zolang git.kvt.nl onbereikbaar is.

hephaestus

Authored 2026-11-28 · 2 days ago

Hash
43b862e01aaf12d60ff4850f47ea0b282115373d
Parent
4dda6e15
2 files changed +32 −15
crates/app-base/src/remote_image.rs +20 −12
@@ -8,7 +8,7 @@ const STICKER_SIZE: u32 = 250;
8 8 const GIF_ITEMTYPE: &str = "http://schema.skype.com/Giphy";
9 9 const STICKER_ITEMTYPE: &str = "http://schema.skype.com/Sticker";
10 10
11 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
11 #[derive(Debug, Clone, PartialEq, Eq)]
12 12 pub enum RemoteKind {
13 13 Gif,
14 14 Sticker,
@@ -64,17 +64,25 @@ impl RemoteImage {
64 64 }
65 65
66 66 pub fn html(&self) -> String {
67 let itemtype = match self.kind {
68 RemoteKind::Gif => GIF_ITEMTYPE,
69 RemoteKind::Sticker => STICKER_ITEMTYPE,
70 };
71 format!(
72 "<img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"{}\" itemtype=\"{itemtype}\">",
73 teams_core::escape_html(&self.url),
74 self.width,
75 self.height,
76 teams_core::escape_html(&self.title),
77 )
67 match &self.kind {
68 RemoteKind::CustomEmoji { object_id } => {
69 custom_emoji_html(&self.title, object_id, &self.url)
70 }
71 RemoteKind::Gif => format!(
72 "<img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"{}\" itemtype=\"{GIF_ITEMTYPE}\">",
73 teams_core::escape_html(&self.url),
74 self.width,
75 self.height,
76 teams_core::escape_html(&self.title),
77 ),
78 RemoteKind::Sticker => format!(
79 "<img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"{}\" itemtype=\"{STICKER_ITEMTYPE}\">",
80 teams_core::escape_html(&self.url),
81 self.width,
82 self.height,
83 teams_core::escape_html(&self.title),
84 ),
85 }
78 86 }
79 87
80 88 pub fn image_ref(&self) -> ImageRef {
@@ -8,7 +8,7 @@ const STICKER_SIZE: u32 = 250;
8const GIF_ITEMTYPE: &str = "http://schema.skype.com/Giphy";
8const GIF_ITEMTYPE: &str = "http://schema.skype.com/Giphy";
9const STICKER_ITEMTYPE: &str = "http://schema.skype.com/Sticker";
9const STICKER_ITEMTYPE: &str = "http://schema.skype.com/Sticker";
10
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum RemoteKind {
12pub enum RemoteKind {
13 Gif,
13 Gif,
14 Sticker,
14 Sticker,
@@ -64,17 +64,25 @@ impl RemoteImage {
64 }
64 }
65
65
66 pub fn html(&self) -> String {
66 pub fn html(&self) -> String {
67 let itemtype = match self.kind {
67 match &self.kind {
68 RemoteKind::Gif => GIF_ITEMTYPE,
68 RemoteKind::CustomEmoji { object_id } => {
69 RemoteKind::Sticker => STICKER_ITEMTYPE,
69 custom_emoji_html(&self.title, object_id, &self.url)
70 };
70 }
71 format!(
71 RemoteKind::Gif => format!(
72 "<img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"{}\" itemtype=\"{itemtype}\">",
72 "<img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"{}\" itemtype=\"{GIF_ITEMTYPE}\">",
73 teams_core::escape_html(&self.url),
73 teams_core::escape_html(&self.url),
74 self.width,
74 self.width,
75 self.height,
75 self.height,
76 teams_core::escape_html(&self.title),
76 teams_core::escape_html(&self.title),
77 )
77 ),
78 RemoteKind::Sticker => format!(
79 "<img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"{}\" itemtype=\"{STICKER_ITEMTYPE}\">",
80 teams_core::escape_html(&self.url),
81 self.width,
82 self.height,
83 teams_core::escape_html(&self.title),
84 ),
85 }
78 }
86 }
79
87
80 pub fn image_ref(&self) -> ImageRef {
88 pub fn image_ref(&self) -> ImageRef {
crates/chatsvc/src/custom_emojis.rs +12 −3
@@ -24,6 +24,8 @@ pub struct OrgEmoji {
24 24 pub document_id: String,
25 25 pub name: String,
26 26 pub keywords: Vec<String>,
27 #[serde(default, skip_serializing_if = "Option::is_none")]
28 pub source: Option<String>,
27 29 }
28 30
29 31 impl OrgEmoji {
@@ -32,6 +34,9 @@ impl OrgEmoji {
32 34 }
33 35
34 36 pub fn image_url(&self) -> String {
37 if let Some(source) = &self.source {
38 return source.clone();
39 }
35 40 CustomEmoji {
36 41 name: self.name.clone(),
37 42 object_id: self.document_id.clone(),
@@ -229,6 +234,7 @@ fn parse_emoticon(entry: &Value) -> ParsedEmoticon {
229 234 document_id: document_id.to_owned(),
230 235 name,
231 236 keywords,
237 source: None,
232 238 })
233 239 }
234 240
@@ -298,13 +304,15 @@ mod tests {
298 304 document_id: "0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8".into(),
299 305 name: "absolute-cinema".into(),
300 306 keywords: vec!["cinema".into()],
301 },
307 source: None,
308 },
302 309 OrgEmoji {
303 310 id: "em-gone".into(),
304 311 document_id: "0-weu-d1-deadbeefdeadbeefdeadbeefdeadbeef".into(),
305 312 name: "old-one".into(),
306 313 keywords: vec![],
307 },
314 source: None,
315 },
308 316 ];
309 317 let incoming = OrgEmojiCatalog {
310 318 emojis: vec![OrgEmoji {
@@ -312,7 +320,8 @@ mod tests {
312 320 document_id: "0-wuk-d2-f38257c0fba2d2981ec2a368c5cf1853".into(),
313 321 name: "tsignal".into(),
314 322 keywords: vec!["tsignal".into()],
315 }],
323 source: None,
324 }],
316 325 deleted_ids: vec!["em-gone".into()],
317 326 continuation: Some("43".into()),
318 327 };
@@ -24,6 +24,8 @@ pub struct OrgEmoji {
24 pub document_id: String,
24 pub document_id: String,
25 pub name: String,
25 pub name: String,
26 pub keywords: Vec<String>,
26 pub keywords: Vec<String>,
27 #[serde(default, skip_serializing_if = "Option::is_none")]
28 pub source: Option<String>,
27}
29}
28
30
29impl OrgEmoji {
31impl OrgEmoji {
@@ -32,6 +34,9 @@ impl OrgEmoji {
32 }
34 }
33
35
34 pub fn image_url(&self) -> String {
36 pub fn image_url(&self) -> String {
37 if let Some(source) = &self.source {
38 return source.clone();
39 }
35 CustomEmoji {
40 CustomEmoji {
36 name: self.name.clone(),
41 name: self.name.clone(),
37 object_id: self.document_id.clone(),
42 object_id: self.document_id.clone(),
@@ -229,6 +234,7 @@ fn parse_emoticon(entry: &Value) -> ParsedEmoticon {
229 document_id: document_id.to_owned(),
234 document_id: document_id.to_owned(),
230 name,
235 name,
231 keywords,
236 keywords,
237 source: None,
232 })
238 })
233}
239}
234
240
@@ -298,13 +304,15 @@ mod tests {
298 document_id: "0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8".into(),
304 document_id: "0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8".into(),
299 name: "absolute-cinema".into(),
305 name: "absolute-cinema".into(),
300 keywords: vec!["cinema".into()],
306 keywords: vec!["cinema".into()],
301 },
307 source: None,
308 },
302 OrgEmoji {
309 OrgEmoji {
303 id: "em-gone".into(),
310 id: "em-gone".into(),
304 document_id: "0-weu-d1-deadbeefdeadbeefdeadbeefdeadbeef".into(),
311 document_id: "0-weu-d1-deadbeefdeadbeefdeadbeefdeadbeef".into(),
305 name: "old-one".into(),
312 name: "old-one".into(),
306 keywords: vec![],
313 keywords: vec![],
307 },
314 source: None,
315 },
308 ];
316 ];
309 let incoming = OrgEmojiCatalog {
317 let incoming = OrgEmojiCatalog {
310 emojis: vec![OrgEmoji {
318 emojis: vec![OrgEmoji {
@@ -312,7 +320,8 @@ mod tests {
312 document_id: "0-wuk-d2-f38257c0fba2d2981ec2a368c5cf1853".into(),
320 document_id: "0-wuk-d2-f38257c0fba2d2981ec2a368c5cf1853".into(),
313 name: "tsignal".into(),
321 name: "tsignal".into(),
314 keywords: vec!["tsignal".into()],
322 keywords: vec!["tsignal".into()],
315 }],
323 source: None,
324 }],
316 deleted_ids: vec!["em-gone".into()],
325 deleted_ids: vec!["em-gone".into()],
317 continuation: Some("43".into()),
326 continuation: Some("43".into()),
318 };
327 };