BlueGit

ict rusty-teams

feat(sidebar): team pictures from Teams, letter tiles like Teams

- team pictures load from Graph /teams/{id}/photo through the avatar cache (team:{id})
- teams without a picture get the lettered tile Teams serves itself
- fallback letters follow Teams: first and last word, split at space and underscore, case kept
- used in the channel list, pinned channels, channel header and switcher

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-07 · 3 weeks ago

Hash
b8b465f84e279f7178f9ef1914c97e8f8dc32573
Parent
af8e6479
10 files changed +124 −18
crates/app-base/src/format.rs +23 −0
@@ -81,6 +81,19 @@ pub fn initials(name: &str) -> String {
81 81 letters.into_iter().flat_map(char::to_uppercase).collect()
82 82 }
83 83
84 /// Teams letters a team tile from the first and last word, split at spaces and underscores, in their own case.
85 pub fn team_initials(name: &str) -> String {
86 let words: Vec<&str> = name
87 .split([' ', '_'])
88 .filter(|word| word.chars().next().is_some_and(char::is_alphanumeric))
89 .collect();
90 match words.as_slice() {
91 [] => "?".to_owned(),
92 [single] => single.chars().take(1).collect(),
93 [first, .., last] => first.chars().take(1).chain(last.chars().take(1)).collect(),
94 }
95 }
96
84 97 pub fn first_name(name: &str) -> &str {
85 98 name.split_whitespace().next().unwrap_or(name)
86 99 }
@@ -223,6 +236,16 @@ mod tests {
223 236
224 237 use super::*;
225 238
239 #[test]
240 fn team_tiles_letter_first_and_last_word_like_teams() {
241 assert_eq!(team_initials("e_IT-Support"), "eI");
242 assert_eq!(team_initials("e_ComponentLibrary"), "eC");
243 assert_eq!(team_initials("e_Human Resources"), "eR");
244 assert_eq!(team_initials("e_NLP / AI"), "eA");
245 assert_eq!(team_initials("Platform"), "P");
246 assert_eq!(team_initials(""), "?");
247 }
248
226 249 #[test]
227 250 fn the_clock_follows_the_display_language() {
228 251 set_date_locale(Some("en-US"));
@@ -81,6 +81,19 @@ pub fn initials(name: &str) -> String {
81 letters.into_iter().flat_map(char::to_uppercase).collect()
81 letters.into_iter().flat_map(char::to_uppercase).collect()
82}
82}
83
83
84/// Teams letters a team tile from the first and last word, split at spaces and underscores, in their own case.
85pub fn team_initials(name: &str) -> String {
86 let words: Vec<&str> = name
87 .split([' ', '_'])
88 .filter(|word| word.chars().next().is_some_and(char::is_alphanumeric))
89 .collect();
90 match words.as_slice() {
91 [] => "?".to_owned(),
92 [single] => single.chars().take(1).collect(),
93 [first, .., last] => first.chars().take(1).chain(last.chars().take(1)).collect(),
94 }
95}
96
84pub fn first_name(name: &str) -> &str {
97pub fn first_name(name: &str) -> &str {
85 name.split_whitespace().next().unwrap_or(name)
98 name.split_whitespace().next().unwrap_or(name)
86}
99}
@@ -223,6 +236,16 @@ mod tests {
223
236
224 use super::*;
237 use super::*;
225
238
239 #[test]
240 fn team_tiles_letter_first_and_last_word_like_teams() {
241 assert_eq!(team_initials("e_IT-Support"), "eI");
242 assert_eq!(team_initials("e_ComponentLibrary"), "eC");
243 assert_eq!(team_initials("e_Human Resources"), "eR");
244 assert_eq!(team_initials("e_NLP / AI"), "eA");
245 assert_eq!(team_initials("Platform"), "P");
246 assert_eq!(team_initials(""), "?");
247 }
248
226 #[test]
249 #[test]
227 fn the_clock_follows_the_display_language() {
250 fn the_clock_follows_the_display_language() {
228 set_date_locale(Some("en-US"));
251 set_date_locale(Some("en-US"));
crates/app/src/views/avatar.rs +13 −1
@@ -331,7 +331,19 @@ pub fn square_avatar(name: &str, key: &str, size: f32, radius: f32) -> Div {
331 331 .text_color(theme::text())
332 332 .text_size(px((size * 0.4).round()))
333 333 .font_weight(FontWeight::SEMIBOLD)
334 .child(format::initials(name))
334 .child(format::team_initials(name))
335 }
336
337 pub fn team_avatar(photo: Option<&AvatarState>, name: &str, key: &str, size: f32, radius: f32) -> AnyElement {
338 match photo {
339 Some(AvatarState::Ready(photo)) => div()
340 .size(px(size))
341 .flex_none()
342 .rounded(px(radius))
343 .child(photo_disc(photo, size, radius))
344 .into_any_element(),
345 _ => square_avatar(name, key, size, radius).into_any_element(),
346 }
335 347 }
336 348
337 349 pub fn member_stack(
@@ -331,7 +331,19 @@ pub fn square_avatar(name: &str, key: &str, size: f32, radius: f32) -> Div {
331 .text_color(theme::text())
331 .text_color(theme::text())
332 .text_size(px((size * 0.4).round()))
332 .text_size(px((size * 0.4).round()))
333 .font_weight(FontWeight::SEMIBOLD)
333 .font_weight(FontWeight::SEMIBOLD)
334 .child(format::initials(name))
334 .child(format::team_initials(name))
335}
336
337pub fn team_avatar(photo: Option<&AvatarState>, name: &str, key: &str, size: f32, radius: f32) -> AnyElement {
338 match photo {
339 Some(AvatarState::Ready(photo)) => div()
340 .size(px(size))
341 .flex_none()
342 .rounded(px(radius))
343 .child(photo_disc(photo, size, radius))
344 .into_any_element(),
345 _ => square_avatar(name, key, size, radius).into_any_element(),
346 }
335}
347}
336
348
337pub fn member_stack(
349pub fn member_stack(
crates/app/src/views/conversation.rs +6 −2
@@ -49,7 +49,7 @@ mod shared;
49 49 use super::add_people_dialog::open_add_people;
50 50 use super::attachments::FileActions;
51 51 use super::avatar::{
52 bot_tile, member_stack, person_avatar, spec_avatar, square_avatar, with_presence,
52 bot_tile, member_stack, person_avatar, spec_avatar, team_avatar, with_presence,
53 53 };
54 54 use super::call_controls::header_call_controls;
55 55 use super::channel_tabs::{ChannelPane, HEADER_TITLE_MAX_WIDTH};
@@ -3700,7 +3700,11 @@ impl ConversationView {
3700 3700 .map_or((current.title.as_str(), current.title.as_str()), |entry| {
3701 3701 (entry.team.name.as_str(), entry.team.id.as_str())
3702 3702 });
3703 lead = Some(square_avatar(name, key, 36., 9.).into_any_element());
3703 let photo = team.and_then(|entry| {
3704 app.directory
3705 .avatar(&teams_core::team_avatar_key(&entry.team.id))
3706 });
3707 lead = Some(team_avatar(photo, name, key, 36., 9.));
3704 3708 }
3705 3709 }
3706 3710 let mut header = h_flex()
@@ -49,7 +49,7 @@ mod shared;
49use super::add_people_dialog::open_add_people;
49use super::add_people_dialog::open_add_people;
50use super::attachments::FileActions;
50use super::attachments::FileActions;
51use super::avatar::{
51use super::avatar::{
52 bot_tile, member_stack, person_avatar, spec_avatar, square_avatar, with_presence,
52 bot_tile, member_stack, person_avatar, spec_avatar, team_avatar, with_presence,
53};
53};
54use super::call_controls::header_call_controls;
54use super::call_controls::header_call_controls;
55use super::channel_tabs::{ChannelPane, HEADER_TITLE_MAX_WIDTH};
55use super::channel_tabs::{ChannelPane, HEADER_TITLE_MAX_WIDTH};
@@ -3700,7 +3700,11 @@ impl ConversationView {
3700 .map_or((current.title.as_str(), current.title.as_str()), |entry| {
3700 .map_or((current.title.as_str(), current.title.as_str()), |entry| {
3701 (entry.team.name.as_str(), entry.team.id.as_str())
3701 (entry.team.name.as_str(), entry.team.id.as_str())
3702 });
3702 });
3703 lead = Some(square_avatar(name, key, 36., 9.).into_any_element());
3703 let photo = team.and_then(|entry| {
3704 app.directory
3705 .avatar(&teams_core::team_avatar_key(&entry.team.id))
3706 });
3707 lead = Some(team_avatar(photo, name, key, 36., 9.));
3704 }
3708 }
3705 }
3709 }
3706 let mut header = h_flex()
3710 let mut header = h_flex()
crates/app/src/views/sidebar.rs +37 −10
@@ -1,5 +1,5 @@
1 1 use std::cell::Cell;
2 use std::collections::HashSet;
2 use std::collections::{HashMap, HashSet};
3 3 use std::time::Duration;
4 4
5 5 use chrono::{Local, Offset, Utc};
@@ -15,10 +15,10 @@ use store::{
15 15 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,
16 16 Store,
17 17 };
18 use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat};
18 use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat, team_avatar_key};
19 19
20 20 use super::activity_panel::ActivityPanel;
21 use super::avatar::{spec_avatar, square_avatar, with_presence};
21 use super::avatar::{spec_avatar, team_avatar, with_presence};
22 22 use super::calls_tab::calls_body;
23 23 use super::chat_pop_out;
24 24 use super::saved_panel::SavedPanel;
@@ -33,7 +33,7 @@ use crate::channel_menu::{
33 33 };
34 34 use crate::chat_actions::TITLE_LIMIT;
35 35 use crate::chat_filter::{ChatFilter, filtered_sections, has_no_matches};
36 use crate::data::{Directory, is_pending_folder};
36 use crate::data::{AvatarState, Directory, is_pending_folder};
37 37 use crate::format;
38 38 use crate::local_previews::LocalPreview;
39 39 use crate::notice::truncated;
@@ -1473,6 +1473,7 @@ impl SidebarView {
1473 1473 entry: &SidebarTeam,
1474 1474 channel: &ChannelRecord,
1475 1475 selected: bool,
1476 team_photo: Option<&AvatarState>,
1476 1477 ) -> AnyElement {
1477 1478 let team = &entry.team;
1478 1479 let unread = channel_shows_unread(entry, channel);
@@ -1495,7 +1496,7 @@ impl SidebarView {
1495 1496 .cursor_pointer()
1496 1497 .when(selected, |row| row.bg(theme::surface_raised()))
1497 1498 .when(!selected, |row| row.hover(|row| row.bg(theme::row_hover())))
1498 .child(square_avatar(&team.name, &team.id, 28., 7.))
1499 .child(team_avatar(team_photo, &team.name, &team.id, 28., 7.))
1499 1500 .child(
1500 1501 v_flex()
1501 1502 .flex_1()
@@ -1580,6 +1581,7 @@ impl SidebarView {
1580 1581 entry: &SidebarTeam,
1581 1582 hoisted_only: bool,
1582 1583 selected: Option<&Selection>,
1584 team_photo: Option<&AvatarState>,
1583 1585 cx: &mut Context<Self>,
1584 1586 ) -> Div {
1585 1587 let team_id = entry.team.id.clone();
@@ -1610,7 +1612,8 @@ impl SidebarView {
1610 1612 14.,
1611 1613 theme::text_muted(),
1612 1614 ))
1613 .child(square_avatar(
1615 .child(team_avatar(
1616 team_photo,
1614 1617 &entry.team.name,
1615 1618 &entry.team.id,
1616 1619 TEAM_ICON_SIZE,
@@ -1823,14 +1826,29 @@ impl SidebarView {
1823 1826 }
1824 1827
1825 1828 fn channels_body(&self, cx: &mut Context<Self>) -> AnyElement {
1826 let (sidebar, pinned_ids, selected) = {
1829 let (sidebar, pinned_ids, selected, team_photos) = {
1827 1830 let state = self.state.read(cx);
1831 let team_photos: HashMap<String, AvatarState> = state
1832 .sidebar
1833 .teams
1834 .iter()
1835 .filter_map(|entry| {
1836 let photo = state.directory.avatar(&team_avatar_key(&entry.team.id))?;
1837 Some((entry.team.id.clone(), photo.clone()))
1838 })
1839 .collect();
1828 1840 (
1829 1841 state.sidebar.clone(),
1830 1842 state.directory.pinned_channels.clone(),
1831 1843 state.selection.clone().filter(|_| !state.new_chat),
1844 team_photos,
1832 1845 )
1833 1846 };
1847 let team_keys = sidebar
1848 .teams
1849 .iter()
1850 .map(|entry| team_avatar_key(&entry.team.id))
1851 .collect();
1834 1852 let mut list = v_flex().w_full().pb(px(12.));
1835 1853 let pinned: Vec<(&SidebarTeam, &ChannelRecord)> = pinned_ids
1836 1854 .iter()
@@ -1848,7 +1866,13 @@ impl SidebarView {
1848 1866 list = list.child(self.plain_header(PINNED_LABEL));
1849 1867 for (entry, channel) in pinned {
1850 1868 let is_selected = selected == Some(Selection::Channel(channel.id.clone()));
1851 list = list.child(self.channel_row(&channel.id, entry, channel, is_selected));
1869 list = list.child(self.channel_row(
1870 &channel.id,
1871 entry,
1872 channel,
1873 is_selected,
1874 team_photos.get(&entry.team.id),
1875 ));
1852 1876 }
1853 1877 }
1854 1878 list = list.child(self.plain_header(TEAMS_LABEL));
@@ -1859,7 +1883,8 @@ impl SidebarView {
1859 1883 .iter()
1860 1884 .filter(|entry| !entry.hidden || team_hoisted(entry))
1861 1885 {
1862 list = self.team_block(list, entry, entry.hidden, selected.as_ref(), cx);
1886 let team_photo = team_photos.get(&entry.team.id);
1887 list = self.team_block(list, entry, entry.hidden, selected.as_ref(), team_photo, cx);
1863 1888 }
1864 1889 if !hidden_teams.is_empty() {
1865 1890 let holds_selection = hidden_teams
@@ -1878,10 +1903,12 @@ impl SidebarView {
1878 1903 ));
1879 1904 if open {
1880 1905 for entry in hidden_teams {
1881 list = self.team_block(list, entry, false, selected.as_ref(), cx);
1906 let team_photo = team_photos.get(&entry.team.id);
1907 list = self.team_block(list, entry, false, selected.as_ref(), team_photo, cx);
1882 1908 }
1883 1909 }
1884 1910 }
1911 self.request_lazy_data(team_keys, Vec::new(), cx);
1885 1912 let scroll_area = div()
1886 1913 .id("channels-scroll")
1887 1914 .flex_1()
@@ -1,5 +1,5 @@
1use std::cell::Cell;
1use std::cell::Cell;
2use std::collections::HashSet;
2use std::collections::{HashMap, HashSet};
3use std::time::Duration;
3use std::time::Duration;
4
4
5use chrono::{Local, Offset, Utc};
5use chrono::{Local, Offset, Utc};
@@ -15,10 +15,10 @@ use store::{
15 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,
15 ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,
16 Store,
16 Store,
17};
17};
18use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat};
18use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat, team_avatar_key};
19
19
20use super::activity_panel::ActivityPanel;
20use super::activity_panel::ActivityPanel;
21use super::avatar::{spec_avatar, square_avatar, with_presence};
21use super::avatar::{spec_avatar, team_avatar, with_presence};
22use super::calls_tab::calls_body;
22use super::calls_tab::calls_body;
23use super::chat_pop_out;
23use super::chat_pop_out;
24use super::saved_panel::SavedPanel;
24use super::saved_panel::SavedPanel;
@@ -33,7 +33,7 @@ use crate::channel_menu::{
33};
33};
34use crate::chat_actions::TITLE_LIMIT;
34use crate::chat_actions::TITLE_LIMIT;
35use crate::chat_filter::{ChatFilter, filtered_sections, has_no_matches};
35use crate::chat_filter::{ChatFilter, filtered_sections, has_no_matches};
36use crate::data::{Directory, is_pending_folder};
36use crate::data::{AvatarState, Directory, is_pending_folder};
37use crate::format;
37use crate::format;
38use crate::local_previews::LocalPreview;
38use crate::local_previews::LocalPreview;
39use crate::notice::truncated;
39use crate::notice::truncated;
@@ -1473,6 +1473,7 @@ impl SidebarView {
1473 entry: &SidebarTeam,
1473 entry: &SidebarTeam,
1474 channel: &ChannelRecord,
1474 channel: &ChannelRecord,
1475 selected: bool,
1475 selected: bool,
1476 team_photo: Option<&AvatarState>,
1476 ) -> AnyElement {
1477 ) -> AnyElement {
1477 let team = &entry.team;
1478 let team = &entry.team;
1478 let unread = channel_shows_unread(entry, channel);
1479 let unread = channel_shows_unread(entry, channel);
@@ -1495,7 +1496,7 @@ impl SidebarView {
1495 .cursor_pointer()
1496 .cursor_pointer()
1496 .when(selected, |row| row.bg(theme::surface_raised()))
1497 .when(selected, |row| row.bg(theme::surface_raised()))
1497 .when(!selected, |row| row.hover(|row| row.bg(theme::row_hover())))
1498 .when(!selected, |row| row.hover(|row| row.bg(theme::row_hover())))
1498 .child(square_avatar(&team.name, &team.id, 28., 7.))
1499 .child(team_avatar(team_photo, &team.name, &team.id, 28., 7.))
1499 .child(
1500 .child(
1500 v_flex()
1501 v_flex()
1501 .flex_1()
1502 .flex_1()
@@ -1580,6 +1581,7 @@ impl SidebarView {
1580 entry: &SidebarTeam,
1581 entry: &SidebarTeam,
1581 hoisted_only: bool,
1582 hoisted_only: bool,
1582 selected: Option<&Selection>,
1583 selected: Option<&Selection>,
1584 team_photo: Option<&AvatarState>,
1583 cx: &mut Context<Self>,
1585 cx: &mut Context<Self>,
1584 ) -> Div {
1586 ) -> Div {
1585 let team_id = entry.team.id.clone();
1587 let team_id = entry.team.id.clone();
@@ -1610,7 +1612,8 @@ impl SidebarView {
1610 14.,
1612 14.,
1611 theme::text_muted(),
1613 theme::text_muted(),
1612 ))
1614 ))
1613 .child(square_avatar(
1615 .child(team_avatar(
1616 team_photo,
1614 &entry.team.name,
1617 &entry.team.name,
1615 &entry.team.id,
1618 &entry.team.id,
1616 TEAM_ICON_SIZE,
1619 TEAM_ICON_SIZE,
@@ -1823,14 +1826,29 @@ impl SidebarView {
1823 }
1826 }
1824
1827
1825 fn channels_body(&self, cx: &mut Context<Self>) -> AnyElement {
1828 fn channels_body(&self, cx: &mut Context<Self>) -> AnyElement {
1826 let (sidebar, pinned_ids, selected) = {
1829 let (sidebar, pinned_ids, selected, team_photos) = {
1827 let state = self.state.read(cx);
1830 let state = self.state.read(cx);
1831 let team_photos: HashMap<String, AvatarState> = state
1832 .sidebar
1833 .teams
1834 .iter()
1835 .filter_map(|entry| {
1836 let photo = state.directory.avatar(&team_avatar_key(&entry.team.id))?;
1837 Some((entry.team.id.clone(), photo.clone()))
1838 })
1839 .collect();
1828 (
1840 (
1829 state.sidebar.clone(),
1841 state.sidebar.clone(),
1830 state.directory.pinned_channels.clone(),
1842 state.directory.pinned_channels.clone(),
1831 state.selection.clone().filter(|_| !state.new_chat),
1843 state.selection.clone().filter(|_| !state.new_chat),
1844 team_photos,
1832 )
1845 )
1833 };
1846 };
1847 let team_keys = sidebar
1848 .teams
1849 .iter()
1850 .map(|entry| team_avatar_key(&entry.team.id))
1851 .collect();
1834 let mut list = v_flex().w_full().pb(px(12.));
1852 let mut list = v_flex().w_full().pb(px(12.));
1835 let pinned: Vec<(&SidebarTeam, &ChannelRecord)> = pinned_ids
1853 let pinned: Vec<(&SidebarTeam, &ChannelRecord)> = pinned_ids
1836 .iter()
1854 .iter()
@@ -1848,7 +1866,13 @@ impl SidebarView {
1848 list = list.child(self.plain_header(PINNED_LABEL));
1866 list = list.child(self.plain_header(PINNED_LABEL));
1849 for (entry, channel) in pinned {
1867 for (entry, channel) in pinned {
1850 let is_selected = selected == Some(Selection::Channel(channel.id.clone()));
1868 let is_selected = selected == Some(Selection::Channel(channel.id.clone()));
1851 list = list.child(self.channel_row(&channel.id, entry, channel, is_selected));
1869 list = list.child(self.channel_row(
1870 &channel.id,
1871 entry,
1872 channel,
1873 is_selected,
1874 team_photos.get(&entry.team.id),
1875 ));
1852 }
1876 }
1853 }
1877 }
1854 list = list.child(self.plain_header(TEAMS_LABEL));
1878 list = list.child(self.plain_header(TEAMS_LABEL));
@@ -1859,7 +1883,8 @@ impl SidebarView {
1859 .iter()
1883 .iter()
1860 .filter(|entry| !entry.hidden || team_hoisted(entry))
1884 .filter(|entry| !entry.hidden || team_hoisted(entry))
1861 {
1885 {
1862 list = self.team_block(list, entry, entry.hidden, selected.as_ref(), cx);
1886 let team_photo = team_photos.get(&entry.team.id);
1887 list = self.team_block(list, entry, entry.hidden, selected.as_ref(), team_photo, cx);
1863 }
1888 }
1864 if !hidden_teams.is_empty() {
1889 if !hidden_teams.is_empty() {
1865 let holds_selection = hidden_teams
1890 let holds_selection = hidden_teams
@@ -1878,10 +1903,12 @@ impl SidebarView {
1878 ));
1903 ));
1879 if open {
1904 if open {
1880 for entry in hidden_teams {
1905 for entry in hidden_teams {
1881 list = self.team_block(list, entry, false, selected.as_ref(), cx);
1906 let team_photo = team_photos.get(&entry.team.id);
1907 list = self.team_block(list, entry, false, selected.as_ref(), team_photo, cx);
1882 }
1908 }
1883 }
1909 }
1884 }
1910 }
1911 self.request_lazy_data(team_keys, Vec::new(), cx);
1885 let scroll_area = div()
1912 let scroll_area = div()
1886 .id("channels-scroll")
1913 .id("channels-scroll")
1887 .flex_1()
1914 .flex_1()
crates/app/src/views/switcher.rs +3 −2
@@ -13,7 +13,7 @@ use gpui_kit::*;
13 13 use store::SearchHit;
14 14 use teams_core::{HIGHLIGHT_END, HIGHLIGHT_START};
15 15
16 use super::avatar::{person_avatar, spec_avatar, square_avatar};
16 use super::avatar::{person_avatar, spec_avatar, team_avatar};
17 17 use super::widgets::icon;
18 18 use crate::app_state::{AppState, Selection, chat_title};
19 19 use crate::data::{Directory, is_one_on_one};
@@ -173,7 +173,8 @@ pub fn candidate_avatar(
173 173 match avatar {
174 174 CandidateAvatar::Chat(spec) => spec_avatar(directory, spec, size, ring),
175 175 CandidateAvatar::Team { name, key } => {
176 square_avatar(name, key, size, size / 4.).into_any_element()
176 let photo = directory.avatar(&teams_core::team_avatar_key(key));
177 team_avatar(photo, name, key, size, size / 4.)
177 178 }
178 179 }
179 180 }
@@ -13,7 +13,7 @@ use gpui_kit::*;
13use store::SearchHit;
13use store::SearchHit;
14use teams_core::{HIGHLIGHT_END, HIGHLIGHT_START};
14use teams_core::{HIGHLIGHT_END, HIGHLIGHT_START};
15
15
16use super::avatar::{person_avatar, spec_avatar, square_avatar};
16use super::avatar::{person_avatar, spec_avatar, team_avatar};
17use super::widgets::icon;
17use super::widgets::icon;
18use crate::app_state::{AppState, Selection, chat_title};
18use crate::app_state::{AppState, Selection, chat_title};
19use crate::data::{Directory, is_one_on_one};
19use crate::data::{Directory, is_one_on_one};
@@ -173,7 +173,8 @@ pub fn candidate_avatar(
173 match avatar {
173 match avatar {
174 CandidateAvatar::Chat(spec) => spec_avatar(directory, spec, size, ring),
174 CandidateAvatar::Chat(spec) => spec_avatar(directory, spec, size, ring),
175 CandidateAvatar::Team { name, key } => {
175 CandidateAvatar::Team { name, key } => {
176 square_avatar(name, key, size, size / 4.).into_any_element()
176 let photo = directory.avatar(&teams_core::team_avatar_key(key));
177 team_avatar(photo, name, key, size, size / 4.)
177 }
178 }
178 }
179 }
179}
180}
crates/core/src/avatars.rs +21 −2
@@ -9,6 +9,12 @@ use crate::remote::Remote;
9 9 const AVATAR_MAX_AGE_DAYS: i64 = 7;
10 10 const AVATAR_BATCH: usize = 60;
11 11 const PHOTO_RENDITION_SINCE: &str = "2026-10-17T17:00:00Z";
12 const TEAM_AVATAR_PREFIX: &str = "team:";
13
14 /// Team pictures share the avatar cache under this key; Teams serves a lettered tile for teams without one.
15 pub fn team_avatar_key(team_id: &str) -> String {
16 format!("{TEAM_AVATAR_PREFIX}{team_id}")
17 }
12 18
13 19 fn avatar_cutoff(now: DateTime<Utc>) -> DateTime<Utc> {
14 20 let since = DateTime::parse_from_rfc3339(PHOTO_RENDITION_SINCE)
@@ -66,8 +72,21 @@ impl<R: Remote> SyncEngine<R> {
66 72 }
67 73 }
68 74 }
69 for chunk in people.chunks(AVATAR_BATCH) {
70 let photos = match self.remote.user_photos(chunk).await {
75 let (teams, people): (Vec<String>, Vec<String>) = people
76 .into_iter()
77 .partition(|key| key.starts_with(TEAM_AVATAR_PREFIX));
78 for chunk in teams.chunks(AVATAR_BATCH).chain(people.chunks(AVATAR_BATCH)) {
79 let photos = match chunk.first() {
80 Some(key) if key.starts_with(TEAM_AVATAR_PREFIX) => {
81 let team_ids: Vec<String> = chunk
82 .iter()
83 .map(|key| key.trim_start_matches(TEAM_AVATAR_PREFIX).to_owned())
84 .collect();
85 self.remote.team_photos(&team_ids).await
86 }
87 _ => self.remote.user_photos(chunk).await,
88 };
89 let photos = match photos {
71 90 Ok(photos) => photos,
72 91 Err(error) => {
73 92 first_error.get_or_insert(error);
@@ -9,6 +9,12 @@ use crate::remote::Remote;
9const AVATAR_MAX_AGE_DAYS: i64 = 7;
9const AVATAR_MAX_AGE_DAYS: i64 = 7;
10const AVATAR_BATCH: usize = 60;
10const AVATAR_BATCH: usize = 60;
11const PHOTO_RENDITION_SINCE: &str = "2026-10-17T17:00:00Z";
11const PHOTO_RENDITION_SINCE: &str = "2026-10-17T17:00:00Z";
12const TEAM_AVATAR_PREFIX: &str = "team:";
13
14/// Team pictures share the avatar cache under this key; Teams serves a lettered tile for teams without one.
15pub fn team_avatar_key(team_id: &str) -> String {
16 format!("{TEAM_AVATAR_PREFIX}{team_id}")
17}
12
18
13fn avatar_cutoff(now: DateTime<Utc>) -> DateTime<Utc> {
19fn avatar_cutoff(now: DateTime<Utc>) -> DateTime<Utc> {
14 let since = DateTime::parse_from_rfc3339(PHOTO_RENDITION_SINCE)
20 let since = DateTime::parse_from_rfc3339(PHOTO_RENDITION_SINCE)
@@ -66,8 +72,21 @@ impl<R: Remote> SyncEngine<R> {
66 }
72 }
67 }
73 }
68 }
74 }
69 for chunk in people.chunks(AVATAR_BATCH) {
75 let (teams, people): (Vec<String>, Vec<String>) = people
70 let photos = match self.remote.user_photos(chunk).await {
76 .into_iter()
77 .partition(|key| key.starts_with(TEAM_AVATAR_PREFIX));
78 for chunk in teams.chunks(AVATAR_BATCH).chain(people.chunks(AVATAR_BATCH)) {
79 let photos = match chunk.first() {
80 Some(key) if key.starts_with(TEAM_AVATAR_PREFIX) => {
81 let team_ids: Vec<String> = chunk
82 .iter()
83 .map(|key| key.trim_start_matches(TEAM_AVATAR_PREFIX).to_owned())
84 .collect();
85 self.remote.team_photos(&team_ids).await
86 }
87 _ => self.remote.user_photos(chunk).await,
88 };
89 let photos = match photos {
71 Ok(photos) => photos,
90 Ok(photos) => photos,
72 Err(error) => {
91 Err(error) => {
73 first_error.get_or_insert(error);
92 first_error.get_or_insert(error);
crates/core/src/lib.rs +1 −1
@@ -83,7 +83,7 @@ pub use adaptive_card::{
83 83 InvokePayload, SubmitAction, TextColor, TextSize, ToggleTarget, VerticalAlignment,
84 84 card_content_text, split_overflow, task_value,
85 85 };
86 pub use avatars::Avatar;
86 pub use avatars::{Avatar, team_avatar_key};
87 87 pub use call_event::{
88 88 CallEvent, CallPhase, CallType, Recording, call_event, format_duration, parse_duration_seconds,
89 89 };
@@ -83,7 +83,7 @@ pub use adaptive_card::{
83 InvokePayload, SubmitAction, TextColor, TextSize, ToggleTarget, VerticalAlignment,
83 InvokePayload, SubmitAction, TextColor, TextSize, ToggleTarget, VerticalAlignment,
84 card_content_text, split_overflow, task_value,
84 card_content_text, split_overflow, task_value,
85};
85};
86pub use avatars::Avatar;
86pub use avatars::{Avatar, team_avatar_key};
87pub use call_event::{
87pub use call_event::{
88 CallEvent, CallPhase, CallType, Recording, call_event, format_duration, parse_duration_seconds,
88 CallEvent, CallPhase, CallType, Recording, call_event, format_duration, parse_duration_seconds,
89};
89};
crates/core/src/remote.rs +12 −0
@@ -281,6 +281,10 @@ pub trait Remote {
281 281 Err(Error::Unsupported("profile photos"))
282 282 }
283 283
284 async fn team_photos(&self, _team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
285 Err(Error::Unsupported("team pictures"))
286 }
287
284 288 async fn presences(&self, _user_ids: &[String]) -> Result<Vec<Presence>> {
285 289 Err(Error::Unsupported("presence"))
286 290 }
@@ -1081,6 +1085,14 @@ impl Remote for Graph {
1081 1085 .collect())
1082 1086 }
1083 1087
1088 async fn team_photos(&self, team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
1089 let photos = Graph::team_photos(self, team_ids).await?;
1090 Ok(photos
1091 .into_iter()
1092 .map(|photo| photo.map_err(Into::into))
1093 .collect())
1094 }
1095
1084 1096 async fn presences(&self, user_ids: &[String]) -> Result<Vec<Presence>> {
1085 1097 let found = PresenceLookup::new(self.session())
1086 1098 .presences(user_ids)
@@ -281,6 +281,10 @@ pub trait Remote {
281 Err(Error::Unsupported("profile photos"))
281 Err(Error::Unsupported("profile photos"))
282 }
282 }
283
283
284 async fn team_photos(&self, _team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
285 Err(Error::Unsupported("team pictures"))
286 }
287
284 async fn presences(&self, _user_ids: &[String]) -> Result<Vec<Presence>> {
288 async fn presences(&self, _user_ids: &[String]) -> Result<Vec<Presence>> {
285 Err(Error::Unsupported("presence"))
289 Err(Error::Unsupported("presence"))
286 }
290 }
@@ -1081,6 +1085,14 @@ impl Remote for Graph {
1081 .collect())
1085 .collect())
1082 }
1086 }
1083
1087
1088 async fn team_photos(&self, team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
1089 let photos = Graph::team_photos(self, team_ids).await?;
1090 Ok(photos
1091 .into_iter()
1092 .map(|photo| photo.map_err(Into::into))
1093 .collect())
1094 }
1095
1084 async fn presences(&self, user_ids: &[String]) -> Result<Vec<Presence>> {
1096 async fn presences(&self, user_ids: &[String]) -> Result<Vec<Presence>> {
1085 let found = PresenceLookup::new(self.session())
1097 let found = PresenceLookup::new(self.session())
1086 .presences(user_ids)
1098 .presences(user_ids)
crates/graph/src/people.rs +4 −0
@@ -44,6 +44,10 @@ impl Graph {
44 44 Ok(photos)
45 45 }
46 46
47 pub async fn team_photos(&self, team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
48 self.photo_batch(team_ids, urls::team_photo).await
49 }
50
47 51 async fn photo_batch(
48 52 &self,
49 53 user_ids: &[String],
@@ -44,6 +44,10 @@ impl Graph {
44 Ok(photos)
44 Ok(photos)
45 }
45 }
46
46
47 pub async fn team_photos(&self, team_ids: &[String]) -> Result<Vec<Result<Option<Photo>>>> {
48 self.photo_batch(team_ids, urls::team_photo).await
49 }
50
47 async fn photo_batch(
51 async fn photo_batch(
48 &self,
52 &self,
49 user_ids: &[String],
53 user_ids: &[String],
crates/graph/src/urls.rs +4 −0
@@ -29,6 +29,10 @@ pub fn user_photo_original(user_id: &str) -> String {
29 29 format!("{GRAPH}/v1.0/users/{}/photo/$value", segment(user_id))
30 30 }
31 31
32 pub fn team_photo(team_id: &str) -> String {
33 format!("{GRAPH}/v1.0/teams/{}/photo/$value", segment(team_id))
34 }
35
32 36 pub fn user_profile(user_id: &str) -> String {
33 37 format!(
34 38 "{GRAPH}/v1.0/users/{}?$select=id,displayName,jobTitle,department,companyName,\
@@ -29,6 +29,10 @@ pub fn user_photo_original(user_id: &str) -> String {
29 format!("{GRAPH}/v1.0/users/{}/photo/$value", segment(user_id))
29 format!("{GRAPH}/v1.0/users/{}/photo/$value", segment(user_id))
30}
30}
31
31
32pub fn team_photo(team_id: &str) -> String {
33 format!("{GRAPH}/v1.0/teams/{}/photo/$value", segment(team_id))
34}
35
32pub fn user_profile(user_id: &str) -> String {
36pub fn user_profile(user_id: &str) -> String {
33 format!(
37 format!(
34 "{GRAPH}/v1.0/users/{}?$select=id,displayName,jobTitle,department,companyName,\
38 "{GRAPH}/v1.0/users/{}?$select=id,displayName,jobTitle,department,companyName,\