BlueGit

ict rusty-teams

feat(kvt): organisatie-emoji in composer en bijlagenbalk (WIP, lokale back-up)

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

hephaestus

Authored 2026-11-28 · 2 days ago

Hash
d183cb8cd97b60941e832fe0b6eaa4f4537ffee5
Parent
bb4c02d6
2 files changed +40 −5
crates/app/src/views/attachment_tray.rs +36 −3
@@ -174,6 +174,19 @@ impl ItemKind {
174 174 fn is_object(&self) -> bool {
175 175 matches!(self, ItemKind::Image { .. } | ItemKind::Remote(_))
176 176 }
177
178 fn is_custom_emoji(&self) -> bool {
179 matches!(self, ItemKind::Remote(remote) if remote.is_custom_emoji())
180 }
181 }
182
183 impl AttachmentTray {
184 pub fn attachment_count(&self) -> usize {
185 self.items
186 .iter()
187 .filter(|item| !item.kind.is_custom_emoji())
188 .count()
189 }
177 190 }
178 191
179 192 impl TrayItem {
@@ -269,7 +282,7 @@ impl AttachmentTray {
269 282 /// `None` when the tray is full.
270 283 pub fn add_remote(&mut self, remote: RemoteImage) -> Option<u64> {
271 284 self.notice = None;
272 if self.items.len() >= MAX_ATTACHMENTS {
285 if !remote.is_custom_emoji() && self.attachment_count() >= MAX_ATTACHMENTS {
273 286 self.notice = Some(limit_notice(1));
274 287 return None;
275 288 }
@@ -303,7 +316,7 @@ impl AttachmentTray {
303 316 reference: FileReference,
304 317 ) -> Option<u64> {
305 318 self.notice = None;
306 if self.items.len() >= MAX_ATTACHMENTS {
319 if self.attachment_count() >= MAX_ATTACHMENTS {
307 320 self.notice = Some(limit_notice(1));
308 321 return None;
309 322 }
@@ -327,7 +340,7 @@ impl AttachmentTray {
327 340 self.notice = None;
328 341 let accepted = names
329 342 .len()
330 .min(MAX_ATTACHMENTS.saturating_sub(self.items.len()));
343 .min(MAX_ATTACHMENTS.saturating_sub(self.attachment_count()));
331 344 let ids = names[..accepted]
332 345 .iter()
333 346 .map(|name| self.push(name.clone(), 0, ItemKind::Reading))
@@ -1476,6 +1489,26 @@ mod tests {
1476 1489 assert!(tray.notice().is_some());
1477 1490 }
1478 1491
1492 fn org_emoji() -> RemoteImage {
1493 RemoteImage::custom_emoji(&teams_core::OrgEmoji {
1494 id: "em-1".into(),
1495 document_id: "0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8".into(),
1496 name: "ship-it".into(),
1497 keywords: vec![],
1498 source: None,
1499 })
1500 }
1501
1502 #[test]
1503 fn a_full_tray_still_accepts_a_custom_emoji() {
1504 let mut tray = AttachmentTray::default();
1505 for _ in 0..MAX_ATTACHMENTS {
1506 assert!(tray.add_remote(gif("Wave")).is_some());
1507 }
1508 assert!(tray.add_remote(org_emoji()).is_some());
1509 assert!(tray.add_remote(gif("Wave")).is_none());
1510 }
1511
1479 1512 #[test]
1480 1513 fn images_come_back_in_the_order_asked_for_and_only_when_known() {
1481 1514 let mut tray = AttachmentTray::default();
@@ -174,6 +174,19 @@ impl ItemKind {
174 fn is_object(&self) -> bool {
174 fn is_object(&self) -> bool {
175 matches!(self, ItemKind::Image { .. } | ItemKind::Remote(_))
175 matches!(self, ItemKind::Image { .. } | ItemKind::Remote(_))
176 }
176 }
177
178 fn is_custom_emoji(&self) -> bool {
179 matches!(self, ItemKind::Remote(remote) if remote.is_custom_emoji())
180 }
181}
182
183impl AttachmentTray {
184 pub fn attachment_count(&self) -> usize {
185 self.items
186 .iter()
187 .filter(|item| !item.kind.is_custom_emoji())
188 .count()
189 }
177}
190}
178
191
179impl TrayItem {
192impl TrayItem {
@@ -269,7 +282,7 @@ impl AttachmentTray {
269 /// `None` when the tray is full.
282 /// `None` when the tray is full.
270 pub fn add_remote(&mut self, remote: RemoteImage) -> Option<u64> {
283 pub fn add_remote(&mut self, remote: RemoteImage) -> Option<u64> {
271 self.notice = None;
284 self.notice = None;
272 if self.items.len() >= MAX_ATTACHMENTS {
285 if !remote.is_custom_emoji() && self.attachment_count() >= MAX_ATTACHMENTS {
273 self.notice = Some(limit_notice(1));
286 self.notice = Some(limit_notice(1));
274 return None;
287 return None;
275 }
288 }
@@ -303,7 +316,7 @@ impl AttachmentTray {
303 reference: FileReference,
316 reference: FileReference,
304 ) -> Option<u64> {
317 ) -> Option<u64> {
305 self.notice = None;
318 self.notice = None;
306 if self.items.len() >= MAX_ATTACHMENTS {
319 if self.attachment_count() >= MAX_ATTACHMENTS {
307 self.notice = Some(limit_notice(1));
320 self.notice = Some(limit_notice(1));
308 return None;
321 return None;
309 }
322 }
@@ -327,7 +340,7 @@ impl AttachmentTray {
327 self.notice = None;
340 self.notice = None;
328 let accepted = names
341 let accepted = names
329 .len()
342 .len()
330 .min(MAX_ATTACHMENTS.saturating_sub(self.items.len()));
343 .min(MAX_ATTACHMENTS.saturating_sub(self.attachment_count()));
331 let ids = names[..accepted]
344 let ids = names[..accepted]
332 .iter()
345 .iter()
333 .map(|name| self.push(name.clone(), 0, ItemKind::Reading))
346 .map(|name| self.push(name.clone(), 0, ItemKind::Reading))
@@ -1476,6 +1489,26 @@ mod tests {
1476 assert!(tray.notice().is_some());
1489 assert!(tray.notice().is_some());
1477 }
1490 }
1478
1491
1492 fn org_emoji() -> RemoteImage {
1493 RemoteImage::custom_emoji(&teams_core::OrgEmoji {
1494 id: "em-1".into(),
1495 document_id: "0-wcde-d3-5f5e4f463d6bb959b08614fd1d9680b8".into(),
1496 name: "ship-it".into(),
1497 keywords: vec![],
1498 source: None,
1499 })
1500 }
1501
1502 #[test]
1503 fn a_full_tray_still_accepts_a_custom_emoji() {
1504 let mut tray = AttachmentTray::default();
1505 for _ in 0..MAX_ATTACHMENTS {
1506 assert!(tray.add_remote(gif("Wave")).is_some());
1507 }
1508 assert!(tray.add_remote(org_emoji()).is_some());
1509 assert!(tray.add_remote(gif("Wave")).is_none());
1510 }
1511
1479 #[test]
1512 #[test]
1480 fn images_come_back_in_the_order_asked_for_and_only_when_known() {
1513 fn images_come_back_in_the_order_asked_for_and_only_when_known() {
1481 let mut tray = AttachmentTray::default();
1514 let mut tray = AttachmentTray::default();
crates/app/src/views/composer.rs +4 −2
@@ -2120,7 +2120,7 @@ impl Composer {
2120 2120
2121 2121 /// Images that no longer sit in the text give way to new attachments.
2122 2122 fn make_room(&mut self, needed: usize, cx: &App) {
2123 if self.tray.items().len() + needed > MAX_ATTACHMENTS {
2123 if self.tray.attachment_count() + needed > MAX_ATTACHMENTS {
2124 2124 let referenced: Vec<u64> = self
2125 2125 .input
2126 2126 .read(cx)
@@ -2187,7 +2187,9 @@ impl Composer {
2187 2187 window: &mut Window,
2188 2188 cx: &mut Context<Self>,
2189 2189 ) {
2190 self.make_room(1, cx);
2190 if !image.is_custom_emoji() {
2191 self.make_room(1, cx);
2192 }
2191 2193 if let Some(id) = self.tray.add_remote(image) {
2192 2194 self.insert_image_token(id, window, cx);
2193 2195 }
@@ -2120,7 +2120,7 @@ impl Composer {
2120
2120
2121 /// Images that no longer sit in the text give way to new attachments.
2121 /// Images that no longer sit in the text give way to new attachments.
2122 fn make_room(&mut self, needed: usize, cx: &App) {
2122 fn make_room(&mut self, needed: usize, cx: &App) {
2123 if self.tray.items().len() + needed > MAX_ATTACHMENTS {
2123 if self.tray.attachment_count() + needed > MAX_ATTACHMENTS {
2124 let referenced: Vec<u64> = self
2124 let referenced: Vec<u64> = self
2125 .input
2125 .input
2126 .read(cx)
2126 .read(cx)
@@ -2187,7 +2187,9 @@ impl Composer {
2187 window: &mut Window,
2187 window: &mut Window,
2188 cx: &mut Context<Self>,
2188 cx: &mut Context<Self>,
2189 ) {
2189 ) {
2190 self.make_room(1, cx);
2190 if !image.is_custom_emoji() {
2191 self.make_room(1, cx);
2192 }
2191 if let Some(id) = self.tray.add_remote(image) {
2193 if let Some(id) = self.tray.add_remote(image) {
2192 self.insert_image_token(id, window, cx);
2194 self.insert_image_token(id, window, cx);
2193 }
2195 }