BlueGit

ict rusty-teams

feat(channels): confirm post pins and show shared files in channel details

- confirm dialogs "Pin in channel" / "Unpin this message?" before channel post pin changes
- toasts "Post pinned" / "Post unpinned", errors "We couldn't pin the post." / "We couldn't unpin the post."
- details pane: Shared section after Pinned with the newest 3 files, See all opens the Shared tab
- layout_guard: section order and equal side insets

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
ed1cd3b1c09a64b278c68b4c6f84802ece0d4ad3
Parent
9ee3d02f
6 files changed +329 −34
crates/app-state/src/message_actions.rs +34 −15
@@ -6,6 +6,7 @@ use store::MessageRecord;
6 6 use teams_core::{PinnedMessage, SavedMessage};
7 7
8 8 use crate::app_state::{AppEvent, AppState, Selection, selection_for};
9 use crate::channel_menu::{post_pin_failure, post_pin_notice};
9 10 use crate::format;
10 11 use crate::image_view_gallery::ViewerRequest;
11 12 use crate::notice::short_error;
@@ -229,6 +230,7 @@ impl AppState {
229 230 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
230 231 return;
231 232 };
233 let channel = self.channel_name(chat_id).is_some();
232 234 let previous = self.pinned_messages(chat_id).to_vec();
233 235 let parent_id = previous
234 236 .iter()
@@ -251,6 +253,9 @@ impl AppState {
251 253 }
252 254 self.store_pins(chat_id, updated, cx);
253 255 let Some(engine) = engine_or_demo else {
256 if channel {
257 self.raise_notice(post_pin_notice(pinned).to_owned(), None, cx);
258 }
254 259 return;
255 260 };
256 261 let (owned_chat, owned_message, revert_chat) = (
@@ -258,21 +263,35 @@ impl AppState {
258 263 message_id.to_owned(),
259 264 chat_id.to_owned(),
260 265 );
261 self.run_chat_action(
262 if pinned { "Pin" } else { "Unpin" },
263 async move {
264 if pinned {
265 engine.pin_message(&owned_chat, &owned_message).await
266 } else {
267 engine
268 .unpin_message(&owned_chat, &owned_message, parent_id.as_deref())
269 .await
270 }
271 },
272 move |state, cx| state.store_pins(&revert_chat, previous, cx),
273 |_, _| {},
274 cx,
275 );
266 let call = async move {
267 if pinned {
268 engine.pin_message(&owned_chat, &owned_message).await
269 } else {
270 engine
271 .unpin_message(&owned_chat, &owned_message, parent_id.as_deref())
272 .await
273 }
274 };
275 let revert = move |state: &mut Self, cx: &mut Context<Self>| {
276 state.store_pins(&revert_chat, previous, cx)
277 };
278 if channel {
279 self.run_channel_action(
280 post_pin_failure(pinned),
281 call,
282 revert,
283 Some(post_pin_notice(pinned)),
284 cx,
285 );
286 } else {
287 self.run_chat_action(
288 if pinned { "Pin" } else { "Unpin" },
289 call,
290 revert,
291 |_, _| {},
292 cx,
293 );
294 }
276 295 }
277 296
278 297 pub fn copy_message_link(
@@ -6,6 +6,7 @@ use store::MessageRecord;
6use teams_core::{PinnedMessage, SavedMessage};
6use teams_core::{PinnedMessage, SavedMessage};
7
7
8use crate::app_state::{AppEvent, AppState, Selection, selection_for};
8use crate::app_state::{AppEvent, AppState, Selection, selection_for};
9use crate::channel_menu::{post_pin_failure, post_pin_notice};
9use crate::format;
10use crate::format;
10use crate::image_view_gallery::ViewerRequest;
11use crate::image_view_gallery::ViewerRequest;
11use crate::notice::short_error;
12use crate::notice::short_error;
@@ -229,6 +230,7 @@ impl AppState {
229 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
230 let Some(engine_or_demo) = self.chat_action_engine(cx) else {
230 return;
231 return;
231 };
232 };
233 let channel = self.channel_name(chat_id).is_some();
232 let previous = self.pinned_messages(chat_id).to_vec();
234 let previous = self.pinned_messages(chat_id).to_vec();
233 let parent_id = previous
235 let parent_id = previous
234 .iter()
236 .iter()
@@ -251,6 +253,9 @@ impl AppState {
251 }
253 }
252 self.store_pins(chat_id, updated, cx);
254 self.store_pins(chat_id, updated, cx);
253 let Some(engine) = engine_or_demo else {
255 let Some(engine) = engine_or_demo else {
256 if channel {
257 self.raise_notice(post_pin_notice(pinned).to_owned(), None, cx);
258 }
254 return;
259 return;
255 };
260 };
256 let (owned_chat, owned_message, revert_chat) = (
261 let (owned_chat, owned_message, revert_chat) = (
@@ -258,21 +263,35 @@ impl AppState {
258 message_id.to_owned(),
263 message_id.to_owned(),
259 chat_id.to_owned(),
264 chat_id.to_owned(),
260 );
265 );
261 self.run_chat_action(
266 let call = async move {
262 if pinned { "Pin" } else { "Unpin" },
267 if pinned {
263 async move {
268 engine.pin_message(&owned_chat, &owned_message).await
264 if pinned {
269 } else {
265 engine.pin_message(&owned_chat, &owned_message).await
270 engine
266 } else {
271 .unpin_message(&owned_chat, &owned_message, parent_id.as_deref())
267 engine
272 .await
268 .unpin_message(&owned_chat, &owned_message, parent_id.as_deref())
273 }
269 .await
274 };
270 }
275 let revert = move |state: &mut Self, cx: &mut Context<Self>| {
271 },
276 state.store_pins(&revert_chat, previous, cx)
272 move |state, cx| state.store_pins(&revert_chat, previous, cx),
277 };
273 |_, _| {},
278 if channel {
274 cx,
279 self.run_channel_action(
275 );
280 post_pin_failure(pinned),
281 call,
282 revert,
283 Some(post_pin_notice(pinned)),
284 cx,
285 );
286 } else {
287 self.run_chat_action(
288 if pinned { "Pin" } else { "Unpin" },
289 call,
290 revert,
291 |_, _| {},
292 cx,
293 );
294 }
276 }
295 }
277
296
278 pub fn copy_message_link(
297 pub fn copy_message_link(
crates/app/src/layout_guard.rs +43 −1
@@ -180,7 +180,10 @@ mod frames {
180 180 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
181 181 COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,
182 182 };
183 use crate::views::conversation::{CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_TAG};
183 use crate::views::conversation::{
184 CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
185 CHANNEL_DETAILS_TAG,
186 };
184 187 use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG};
185 188 use crate::views::message_row::BUBBLE_TAGS;
186 189 use crate::views::pin_banner::PIN_BANNER_TAG;
@@ -1509,6 +1512,45 @@ mod frames {
1509 1512 );
1510 1513 }
1511 1514
1515 #[gpui_kit::test]
1516 fn the_channel_details_sections_follow_teams_order_with_equal_insets(cx: &mut TestAppContext) {
1517 let (handle, state) = mount(cx);
1518 let mut visual = VisualTestContext::from_window(handle, cx);
1519 visual.simulate_resize(size(px(1280.), px(800.)));
1520 visual.update(|_, cx| {
1521 state.update(cx, |state, cx| {
1522 state.select(Selection::Channel(PINNED_CHANNEL.to_owned()), cx)
1523 })
1524 });
1525 collect(&mut visual, Some(CHANNEL_DETAILS_BUTTON));
1526 let button = visual
1527 .debug_bounds(CHANNEL_DETAILS_BUTTON)
1528 .expect("channel details button");
1529 visual.simulate_click(button.center(), Default::default());
1530 collect(&mut visual, Some(CHANNEL_DETAILS_SHARED_TAG));
1531 let pane = visual
1532 .debug_bounds(CHANNEL_DETAILS_TAG)
1533 .expect("details pane");
1534 let pinned = visual
1535 .debug_bounds(CHANNEL_DETAILS_PINNED_TAG)
1536 .expect("pinned section");
1537 let shared = visual
1538 .debug_bounds(CHANNEL_DETAILS_SHARED_TAG)
1539 .expect("shared section");
1540 assert!(
1541 pinned.bottom() <= shared.top(),
1542 "pinned {pinned:?} must come before shared {shared:?}"
1543 );
1544 for (name, section) in [("pinned", pinned), ("shared", shared)] {
1545 let left = f32::from(section.left() - pane.left());
1546 let right = f32::from(pane.right() - section.right());
1547 assert!(
1548 (left - right).abs() < INSET_TOLERANCE && left > 0.,
1549 "{name} section insets left {left} right {right} must match"
1550 );
1551 }
1552 }
1553
1512 1554 fn composer_button_insets(visual: &mut VisualTestContext) -> [f32; 6] {
1513 1555 collect(visual, Some(COMPOSER_SEND_TAG));
1514 1556 let mut bounds_of = |path: &'static str| {
@@ -180,7 +180,10 @@ mod frames {
180 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
180 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
181 COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,
181 COMPOSER_FORMAT_TAG, COMPOSER_LEADING_TAG, COMPOSER_SEND_TAG,
182 };
182 };
183 use crate::views::conversation::{CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_TAG};
183 use crate::views::conversation::{
184 CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
185 CHANNEL_DETAILS_TAG,
186 };
184 use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG};
187 use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG};
185 use crate::views::message_row::BUBBLE_TAGS;
188 use crate::views::message_row::BUBBLE_TAGS;
186 use crate::views::pin_banner::PIN_BANNER_TAG;
189 use crate::views::pin_banner::PIN_BANNER_TAG;
@@ -1509,6 +1512,45 @@ mod frames {
1509 );
1512 );
1510 }
1513 }
1511
1514
1515 #[gpui_kit::test]
1516 fn the_channel_details_sections_follow_teams_order_with_equal_insets(cx: &mut TestAppContext) {
1517 let (handle, state) = mount(cx);
1518 let mut visual = VisualTestContext::from_window(handle, cx);
1519 visual.simulate_resize(size(px(1280.), px(800.)));
1520 visual.update(|_, cx| {
1521 state.update(cx, |state, cx| {
1522 state.select(Selection::Channel(PINNED_CHANNEL.to_owned()), cx)
1523 })
1524 });
1525 collect(&mut visual, Some(CHANNEL_DETAILS_BUTTON));
1526 let button = visual
1527 .debug_bounds(CHANNEL_DETAILS_BUTTON)
1528 .expect("channel details button");
1529 visual.simulate_click(button.center(), Default::default());
1530 collect(&mut visual, Some(CHANNEL_DETAILS_SHARED_TAG));
1531 let pane = visual
1532 .debug_bounds(CHANNEL_DETAILS_TAG)
1533 .expect("details pane");
1534 let pinned = visual
1535 .debug_bounds(CHANNEL_DETAILS_PINNED_TAG)
1536 .expect("pinned section");
1537 let shared = visual
1538 .debug_bounds(CHANNEL_DETAILS_SHARED_TAG)
1539 .expect("shared section");
1540 assert!(
1541 pinned.bottom() <= shared.top(),
1542 "pinned {pinned:?} must come before shared {shared:?}"
1543 );
1544 for (name, section) in [("pinned", pinned), ("shared", shared)] {
1545 let left = f32::from(section.left() - pane.left());
1546 let right = f32::from(pane.right() - section.right());
1547 assert!(
1548 (left - right).abs() < INSET_TOLERANCE && left > 0.,
1549 "{name} section insets left {left} right {right} must match"
1550 );
1551 }
1552 }
1553
1512 fn composer_button_insets(visual: &mut VisualTestContext) -> [f32; 6] {
1554 fn composer_button_insets(visual: &mut VisualTestContext) -> [f32; 6] {
1513 collect(visual, Some(COMPOSER_SEND_TAG));
1555 collect(visual, Some(COMPOSER_SEND_TAG));
1514 let mut bounds_of = |path: &'static str| {
1556 let mut bounds_of = |path: &'static str| {
crates/app/src/views/conversation.rs +7 −3
@@ -22,7 +22,10 @@ use teams_core::{
22 22 };
23 23
24 24 mod channel_details;
25 pub use channel_details::{CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_TAG};
25 pub use channel_details::{
26 CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
27 CHANNEL_DETAILS_TAG,
28 };
26 29 mod deletes;
27 30 mod detached;
28 31 mod feed;
@@ -639,7 +642,7 @@ impl ConversationView {
639 642 .as_ref()
640 643 .is_some_and(|current| current.selection.conversation_id() == conversation_id);
641 644 if is_current {
642 if self.shared_active() || self.recap_active() {
645 if self.shared_active() || self.recap_active() || self.channel_details_open {
643 646 self.refresh_shared_items(cx);
644 647 }
645 648 self.rebuild(false, cx);
@@ -3047,7 +3050,8 @@ impl ConversationView {
3047 3050 translate_label,
3048 3051 save: Some(action(|this, key, _, cx| this.toggle_saved(key, cx))),
3049 3052 saved,
3050 toggle_pinned: pinnable.then(|| action(|this, key, _, cx| this.toggle_pinned(key, cx))),
3053 toggle_pinned: pinnable
3054 .then(|| action(|this, key, window, cx| this.toggle_pinned(key, window, cx))),
3051 3055 pinned,
3052 3056 edit: own.then(|| action(|this, key, window, cx| this.begin_edit(key, window, cx))),
3053 3057 delete: own.then(|| action(|this, key, _, cx| this.delete(key, cx))),
@@ -22,7 +22,10 @@ use teams_core::{
22};
22};
23
23
24mod channel_details;
24mod channel_details;
25pub use channel_details::{CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_TAG};
25pub use channel_details::{
26 CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
27 CHANNEL_DETAILS_TAG,
28};
26mod deletes;
29mod deletes;
27mod detached;
30mod detached;
28mod feed;
31mod feed;
@@ -639,7 +642,7 @@ impl ConversationView {
639 .as_ref()
642 .as_ref()
640 .is_some_and(|current| current.selection.conversation_id() == conversation_id);
643 .is_some_and(|current| current.selection.conversation_id() == conversation_id);
641 if is_current {
644 if is_current {
642 if self.shared_active() || self.recap_active() {
645 if self.shared_active() || self.recap_active() || self.channel_details_open {
643 self.refresh_shared_items(cx);
646 self.refresh_shared_items(cx);
644 }
647 }
645 self.rebuild(false, cx);
648 self.rebuild(false, cx);
@@ -3047,7 +3050,8 @@ impl ConversationView {
3047 translate_label,
3050 translate_label,
3048 save: Some(action(|this, key, _, cx| this.toggle_saved(key, cx))),
3051 save: Some(action(|this, key, _, cx| this.toggle_saved(key, cx))),
3049 saved,
3052 saved,
3050 toggle_pinned: pinnable.then(|| action(|this, key, _, cx| this.toggle_pinned(key, cx))),
3053 toggle_pinned: pinnable
3054 .then(|| action(|this, key, window, cx| this.toggle_pinned(key, window, cx))),
3051 pinned,
3055 pinned,
3052 edit: own.then(|| action(|this, key, window, cx| this.begin_edit(key, window, cx))),
3056 edit: own.then(|| action(|this, key, window, cx| this.begin_edit(key, window, cx))),
3053 delete: own.then(|| action(|this, key, _, cx| this.delete(key, cx))),
3057 delete: own.then(|| action(|this, key, _, cx| this.delete(key, cx))),
crates/app/src/views/conversation/channel_details.rs +189 −12
@@ -5,19 +5,26 @@ use gpui_kit::component::{h_flex, v_flex};
5 5 use gpui_kit::prelude::FluentBuilder as _;
6 6 use gpui_kit::*;
7 7 use store::MessageRecord;
8 use teams_core::FileKind;
8 9
9 use super::ConversationView;
10 use super::{ChannelPane, ConversationView};
10 11 use crate::app_state::Selection;
12 use crate::channel_files::{SharedContent, SharedItem};
11 13 use crate::format;
12 14 use crate::rows::reply_excerpt;
13 15 use crate::theme;
16 use crate::views::attachments::file_badge;
14 17 use crate::views::avatar::person_avatar;
15 18
16 19 pub const CHANNEL_DETAILS_TAG: &str = "shell/islands/main/channel-details";
17 20 pub const CHANNEL_DETAILS_BUTTON: &str = "shell/islands/main/channel-details-button";
21 pub const CHANNEL_DETAILS_PINNED_TAG: &str = "shell/islands/main/channel-details/pinned";
22 pub const CHANNEL_DETAILS_SHARED_TAG: &str = "shell/islands/main/channel-details/shared";
18 23 const OPEN_LABEL: &str = "Open channel details";
19 24 const CLOSE_LABEL: &str = "Close channel details";
20 25 const PINNED_TITLE: &str = "Pinned";
26 const SHARED_TITLE: &str = "Shared";
27 const SEE_ALL_SHARED_ARIA: &str = "See all shared files";
21 28 const SEE_ALL_LABEL: &str = "See all";
22 29 const SEE_ALL_ARIA: &str = "See all pinned posts";
23 30 const BACK_LABEL: &str = "Back";
@@ -28,6 +35,7 @@ const HEADER_HEIGHT: f32 = 48.;
28 35 const BUTTON_SIZE: f32 = 32.;
29 36 const ITEM_AVATAR: f32 = 24.;
30 37 const COLLAPSED_PIN_COUNT: usize = 3;
38 const SHARED_FILE_COUNT: usize = 3;
31 39
32 40 pub(super) struct PinnedPostItem {
33 41 pub message_id: String,
@@ -67,6 +75,40 @@ pub(super) fn pinned_post_item(message_id: &str, record: Option<&MessageRecord>)
67 75 }
68 76 }
69 77
78 pub(super) struct SharedFileRow {
79 pub message_id: String,
80 pub name: String,
81 pub kind: FileKind,
82 pub byline: String,
83 }
84
85 pub(super) fn shared_file_rows(items: &[SharedItem]) -> (Vec<SharedFileRow>, bool) {
86 let offset = Local::now().offset().fix();
87 let today = Utc::now().with_timezone(&offset).date_naive();
88 let mut files = items.iter().filter_map(|item| match &item.content {
89 SharedContent::File(card) => Some((item, card)),
90 SharedContent::Link(_) => None,
91 });
92 let rows = files
93 .by_ref()
94 .take(SHARED_FILE_COUNT)
95 .map(|(item, card)| {
96 let date = format::list_time_label(item.created_at, today, offset);
97 SharedFileRow {
98 message_id: item.message_id.clone(),
99 name: card.name.clone(),
100 kind: card.kind,
101 byline: [item.author.as_str(), date.as_str()]
102 .into_iter()
103 .filter(|part| !part.is_empty())
104 .collect::<Vec<_>>()
105 .join(", "),
106 }
107 })
108 .collect();
109 (rows, files.next().is_some())
110 }
111
70 112 pub(super) fn shown_pin_count(total: usize, expanded: bool) -> usize {
71 113 if expanded {
72 114 total
@@ -101,6 +143,9 @@ impl ConversationView {
101 143 .on_click(cx.listener(|this, _, _, cx| {
102 144 this.channel_details_open = !this.channel_details_open;
103 145 this.pinned_posts_expanded = false;
146 if this.channel_details_open {
147 this.refresh_shared_items(cx);
148 }
104 149 cx.notify();
105 150 }))
106 151 .into_any_element(),
@@ -141,21 +186,18 @@ impl ConversationView {
141 186 .pb(px(PANE_PADDING))
142 187 .gap(px(4.));
143 188 if !items.is_empty() {
189 let mut section = v_flex()
190 .w_full()
191 .gap(px(4.))
192 .debug_selector(|| CHANNEL_DETAILS_PINNED_TAG.into());
144 193 if !expanded {
145 body = body.child(
146 div()
147 .py(px(8.))
148 .text_size(px(14.))
149 .font_weight(FontWeight::SEMIBOLD)
150 .text_color(theme::text())
151 .child(PINNED_TITLE),
152 );
194 section = section.child(section_title(PINNED_TITLE));
153 195 }
154 196 for item in items.iter().take(shown) {
155 body = body.child(self.pinned_post_row(&channel_id, item, directory, cx));
197 section = section.child(self.pinned_post_row(&channel_id, item, directory, cx));
156 198 }
157 199 if has_more {
158 body = body.child(
200 section = section.child(
159 201 Button::new("channel-details-see-all-pins")
160 202 .ghost()
161 203 .label(SEE_ALL_LABEL)
@@ -166,6 +208,30 @@ impl ConversationView {
166 208 })),
167 209 );
168 210 }
211 body = body.child(section);
212 }
213 let (shared_rows, more_shared) = shared_file_rows(&self.shared.items);
214 if !expanded && !shared_rows.is_empty() {
215 let mut section = v_flex()
216 .w_full()
217 .gap(px(4.))
218 .debug_selector(|| CHANNEL_DETAILS_SHARED_TAG.into())
219 .child(section_title(SHARED_TITLE));
220 for row in &shared_rows {
221 section = section.child(self.shared_file_row(&channel_id, row, cx));
222 }
223 if more_shared {
224 section = section.child(
225 Button::new("channel-details-see-all-shared")
226 .ghost()
227 .label(SEE_ALL_LABEL)
228 .tooltip(SEE_ALL_SHARED_ARIA)
229 .on_click(cx.listener(|this, _, _, cx| {
230 this.select_pane(ChannelPane::Shared, cx);
231 })),
232 );
233 }
234 body = body.child(section);
169 235 }
170 236 let header = if expanded {
171 237 h_flex()
@@ -288,6 +354,65 @@ impl ConversationView {
288 354 }
289 355 }
290 356
357 impl ConversationView {
358 fn shared_file_row(
359 &self,
360 channel_id: &str,
361 row: &SharedFileRow,
362 cx: &Context<Self>,
363 ) -> AnyElement {
364 let (channel_id, message_id) = (channel_id.to_owned(), row.message_id.clone());
365 h_flex()
366 .id(SharedString::from(format!(
367 "shared-file-{}-{}",
368 row.message_id, row.name
369 )))
370 .w_full()
371 .p(px(8.))
372 .gap(px(10.))
373 .items_start()
374 .rounded(px(8.))
375 .cursor_pointer()
376 .hover(|item| item.bg(theme::row_hover()))
377 .child(file_badge(row.kind, ITEM_AVATAR))
378 .child(
379 v_flex()
380 .flex_1()
381 .min_w_0()
382 .gap(px(2.))
383 .child(
384 div()
385 .truncate()
386 .text_size(px(13.))
387 .text_color(theme::text())
388 .child(row.name.clone()),
389 )
390 .when(!row.byline.is_empty(), |column| {
391 column.child(
392 div()
393 .truncate()
394 .text_size(px(12.))
395 .text_color(theme::text_muted())
396 .child(row.byline.clone()),
397 )
398 }),
399 )
400 .on_click(cx.listener(move |this, _, _, cx| {
401 this.jump_to_message(&channel_id, &message_id, cx);
402 }))
403 .into_any_element()
404 }
405 }
406
407 fn section_title(text: &'static str) -> Div {
408 div()
409 .py(px(8.))
410 .text_size(px(14.))
411 .font_weight(FontWeight::SEMIBOLD)
412 .text_color(theme::text())
413 .child(text)
414 }
415
291 416 fn header_title(text: String) -> Div {
292 417 div()
293 418 .flex_1()
@@ -304,7 +429,10 @@ mod tests {
304 429 use chrono::{TimeZone, Utc};
305 430 use store::MessageRecord;
306 431
307 use super::{FALLBACK_PREVIEW, pinned_post_item, shown_pin_count};
432 use teams_core::{FileCard, FileKind};
433
434 use super::{FALLBACK_PREVIEW, pinned_post_item, shared_file_rows, shown_pin_count};
435 use crate::channel_files::{SharedContent, SharedItem};
308 436
309 437 fn record(subject: Option<&str>) -> MessageRecord {
310 438 MessageRecord {
@@ -347,4 +475,53 @@ mod tests {
347 475 assert_eq!(shown_pin_count(2, false), 2);
348 476 assert_eq!(shown_pin_count(5, true), 5);
349 477 }
478
479 fn shared(content: SharedContent, message_id: &str) -> SharedItem {
480 SharedItem {
481 content,
482 author: "Ada Lovelace".into(),
483 post_label: String::new(),
484 message_id: message_id.into(),
485 created_at: Utc.with_ymd_and_hms(2024, 3, 4, 9, 30, 0).unwrap(),
486 }
487 }
488
489 fn file(name: &str) -> SharedContent {
490 SharedContent::File(FileCard {
491 name: name.into(),
492 kind: FileKind::from_name(name),
493 content_type: None,
494 size: None,
495 open_url: format!("https://example.invalid/{name}"),
496 })
497 }
498
499 #[test]
500 fn shared_section_lists_the_newest_files_and_skips_links() {
501 let items = vec![
502 shared(SharedContent::Link("https://example.invalid".into()), "1"),
503 shared(file("plan.docx"), "2"),
504 shared(file("budget.xlsx"), "3"),
505 ];
506 let (rows, more) = shared_file_rows(&items);
507 let names: Vec<&str> = rows.iter().map(|row| row.name.as_str()).collect();
508 assert_eq!(names, ["plan.docx", "budget.xlsx"]);
509 assert!(!more);
510 assert_eq!(rows[0].message_id, "2");
511 assert!(
512 rows[0].byline.starts_with("Ada Lovelace, "),
513 "{}",
514 rows[0].byline
515 );
516 }
517
518 #[test]
519 fn shared_section_offers_see_all_after_three_files() {
520 let items: Vec<SharedItem> = (0..4)
521 .map(|index| shared(file(&format!("file-{index}.pdf")), &index.to_string()))
522 .collect();
523 let (rows, more) = shared_file_rows(&items);
524 assert_eq!(rows.len(), 3);
525 assert!(more);
526 }
350 527 }
@@ -5,19 +5,26 @@ use gpui_kit::component::{h_flex, v_flex};
5use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::prelude::FluentBuilder as _;
6use gpui_kit::*;
6use gpui_kit::*;
7use store::MessageRecord;
7use store::MessageRecord;
8use teams_core::FileKind;
8
9
9use super::ConversationView;
10use super::{ChannelPane, ConversationView};
10use crate::app_state::Selection;
11use crate::app_state::Selection;
12use crate::channel_files::{SharedContent, SharedItem};
11use crate::format;
13use crate::format;
12use crate::rows::reply_excerpt;
14use crate::rows::reply_excerpt;
13use crate::theme;
15use crate::theme;
16use crate::views::attachments::file_badge;
14use crate::views::avatar::person_avatar;
17use crate::views::avatar::person_avatar;
15
18
16pub const CHANNEL_DETAILS_TAG: &str = "shell/islands/main/channel-details";
19pub const CHANNEL_DETAILS_TAG: &str = "shell/islands/main/channel-details";
17pub const CHANNEL_DETAILS_BUTTON: &str = "shell/islands/main/channel-details-button";
20pub const CHANNEL_DETAILS_BUTTON: &str = "shell/islands/main/channel-details-button";
21pub const CHANNEL_DETAILS_PINNED_TAG: &str = "shell/islands/main/channel-details/pinned";
22pub const CHANNEL_DETAILS_SHARED_TAG: &str = "shell/islands/main/channel-details/shared";
18const OPEN_LABEL: &str = "Open channel details";
23const OPEN_LABEL: &str = "Open channel details";
19const CLOSE_LABEL: &str = "Close channel details";
24const CLOSE_LABEL: &str = "Close channel details";
20const PINNED_TITLE: &str = "Pinned";
25const PINNED_TITLE: &str = "Pinned";
26const SHARED_TITLE: &str = "Shared";
27const SEE_ALL_SHARED_ARIA: &str = "See all shared files";
21const SEE_ALL_LABEL: &str = "See all";
28const SEE_ALL_LABEL: &str = "See all";
22const SEE_ALL_ARIA: &str = "See all pinned posts";
29const SEE_ALL_ARIA: &str = "See all pinned posts";
23const BACK_LABEL: &str = "Back";
30const BACK_LABEL: &str = "Back";
@@ -28,6 +35,7 @@ const HEADER_HEIGHT: f32 = 48.;
28const BUTTON_SIZE: f32 = 32.;
35const BUTTON_SIZE: f32 = 32.;
29const ITEM_AVATAR: f32 = 24.;
36const ITEM_AVATAR: f32 = 24.;
30const COLLAPSED_PIN_COUNT: usize = 3;
37const COLLAPSED_PIN_COUNT: usize = 3;
38const SHARED_FILE_COUNT: usize = 3;
31
39
32pub(super) struct PinnedPostItem {
40pub(super) struct PinnedPostItem {
33 pub message_id: String,
41 pub message_id: String,
@@ -67,6 +75,40 @@ pub(super) fn pinned_post_item(message_id: &str, record: Option<&MessageRecord>)
67 }
75 }
68}
76}
69
77
78pub(super) struct SharedFileRow {
79 pub message_id: String,
80 pub name: String,
81 pub kind: FileKind,
82 pub byline: String,
83}
84
85pub(super) fn shared_file_rows(items: &[SharedItem]) -> (Vec<SharedFileRow>, bool) {
86 let offset = Local::now().offset().fix();
87 let today = Utc::now().with_timezone(&offset).date_naive();
88 let mut files = items.iter().filter_map(|item| match &item.content {
89 SharedContent::File(card) => Some((item, card)),
90 SharedContent::Link(_) => None,
91 });
92 let rows = files
93 .by_ref()
94 .take(SHARED_FILE_COUNT)
95 .map(|(item, card)| {
96 let date = format::list_time_label(item.created_at, today, offset);
97 SharedFileRow {
98 message_id: item.message_id.clone(),
99 name: card.name.clone(),
100 kind: card.kind,
101 byline: [item.author.as_str(), date.as_str()]
102 .into_iter()
103 .filter(|part| !part.is_empty())
104 .collect::<Vec<_>>()
105 .join(", "),
106 }
107 })
108 .collect();
109 (rows, files.next().is_some())
110}
111
70pub(super) fn shown_pin_count(total: usize, expanded: bool) -> usize {
112pub(super) fn shown_pin_count(total: usize, expanded: bool) -> usize {
71 if expanded {
113 if expanded {
72 total
114 total
@@ -101,6 +143,9 @@ impl ConversationView {
101 .on_click(cx.listener(|this, _, _, cx| {
143 .on_click(cx.listener(|this, _, _, cx| {
102 this.channel_details_open = !this.channel_details_open;
144 this.channel_details_open = !this.channel_details_open;
103 this.pinned_posts_expanded = false;
145 this.pinned_posts_expanded = false;
146 if this.channel_details_open {
147 this.refresh_shared_items(cx);
148 }
104 cx.notify();
149 cx.notify();
105 }))
150 }))
106 .into_any_element(),
151 .into_any_element(),
@@ -141,21 +186,18 @@ impl ConversationView {
141 .pb(px(PANE_PADDING))
186 .pb(px(PANE_PADDING))
142 .gap(px(4.));
187 .gap(px(4.));
143 if !items.is_empty() {
188 if !items.is_empty() {
189 let mut section = v_flex()
190 .w_full()
191 .gap(px(4.))
192 .debug_selector(|| CHANNEL_DETAILS_PINNED_TAG.into());
144 if !expanded {
193 if !expanded {
145 body = body.child(
194 section = section.child(section_title(PINNED_TITLE));
146 div()
147 .py(px(8.))
148 .text_size(px(14.))
149 .font_weight(FontWeight::SEMIBOLD)
150 .text_color(theme::text())
151 .child(PINNED_TITLE),
152 );
153 }
195 }
154 for item in items.iter().take(shown) {
196 for item in items.iter().take(shown) {
155 body = body.child(self.pinned_post_row(&channel_id, item, directory, cx));
197 section = section.child(self.pinned_post_row(&channel_id, item, directory, cx));
156 }
198 }
157 if has_more {
199 if has_more {
158 body = body.child(
200 section = section.child(
159 Button::new("channel-details-see-all-pins")
201 Button::new("channel-details-see-all-pins")
160 .ghost()
202 .ghost()
161 .label(SEE_ALL_LABEL)
203 .label(SEE_ALL_LABEL)
@@ -166,6 +208,30 @@ impl ConversationView {
166 })),
208 })),
167 );
209 );
168 }
210 }
211 body = body.child(section);
212 }
213 let (shared_rows, more_shared) = shared_file_rows(&self.shared.items);
214 if !expanded && !shared_rows.is_empty() {
215 let mut section = v_flex()
216 .w_full()
217 .gap(px(4.))
218 .debug_selector(|| CHANNEL_DETAILS_SHARED_TAG.into())
219 .child(section_title(SHARED_TITLE));
220 for row in &shared_rows {
221 section = section.child(self.shared_file_row(&channel_id, row, cx));
222 }
223 if more_shared {
224 section = section.child(
225 Button::new("channel-details-see-all-shared")
226 .ghost()
227 .label(SEE_ALL_LABEL)
228 .tooltip(SEE_ALL_SHARED_ARIA)
229 .on_click(cx.listener(|this, _, _, cx| {
230 this.select_pane(ChannelPane::Shared, cx);
231 })),
232 );
233 }
234 body = body.child(section);
169 }
235 }
170 let header = if expanded {
236 let header = if expanded {
171 h_flex()
237 h_flex()
@@ -288,6 +354,65 @@ impl ConversationView {
288 }
354 }
289}
355}
290
356
357impl ConversationView {
358 fn shared_file_row(
359 &self,
360 channel_id: &str,
361 row: &SharedFileRow,
362 cx: &Context<Self>,
363 ) -> AnyElement {
364 let (channel_id, message_id) = (channel_id.to_owned(), row.message_id.clone());
365 h_flex()
366 .id(SharedString::from(format!(
367 "shared-file-{}-{}",
368 row.message_id, row.name
369 )))
370 .w_full()
371 .p(px(8.))
372 .gap(px(10.))
373 .items_start()
374 .rounded(px(8.))
375 .cursor_pointer()
376 .hover(|item| item.bg(theme::row_hover()))
377 .child(file_badge(row.kind, ITEM_AVATAR))
378 .child(
379 v_flex()
380 .flex_1()
381 .min_w_0()
382 .gap(px(2.))
383 .child(
384 div()
385 .truncate()
386 .text_size(px(13.))
387 .text_color(theme::text())
388 .child(row.name.clone()),
389 )
390 .when(!row.byline.is_empty(), |column| {
391 column.child(
392 div()
393 .truncate()
394 .text_size(px(12.))
395 .text_color(theme::text_muted())
396 .child(row.byline.clone()),
397 )
398 }),
399 )
400 .on_click(cx.listener(move |this, _, _, cx| {
401 this.jump_to_message(&channel_id, &message_id, cx);
402 }))
403 .into_any_element()
404 }
405}
406
407fn section_title(text: &'static str) -> Div {
408 div()
409 .py(px(8.))
410 .text_size(px(14.))
411 .font_weight(FontWeight::SEMIBOLD)
412 .text_color(theme::text())
413 .child(text)
414}
415
291fn header_title(text: String) -> Div {
416fn header_title(text: String) -> Div {
292 div()
417 div()
293 .flex_1()
418 .flex_1()
@@ -304,7 +429,10 @@ mod tests {
304 use chrono::{TimeZone, Utc};
429 use chrono::{TimeZone, Utc};
305 use store::MessageRecord;
430 use store::MessageRecord;
306
431
307 use super::{FALLBACK_PREVIEW, pinned_post_item, shown_pin_count};
432 use teams_core::{FileCard, FileKind};
433
434 use super::{FALLBACK_PREVIEW, pinned_post_item, shared_file_rows, shown_pin_count};
435 use crate::channel_files::{SharedContent, SharedItem};
308
436
309 fn record(subject: Option<&str>) -> MessageRecord {
437 fn record(subject: Option<&str>) -> MessageRecord {
310 MessageRecord {
438 MessageRecord {
@@ -347,4 +475,53 @@ mod tests {
347 assert_eq!(shown_pin_count(2, false), 2);
475 assert_eq!(shown_pin_count(2, false), 2);
348 assert_eq!(shown_pin_count(5, true), 5);
476 assert_eq!(shown_pin_count(5, true), 5);
349 }
477 }
478
479 fn shared(content: SharedContent, message_id: &str) -> SharedItem {
480 SharedItem {
481 content,
482 author: "Ada Lovelace".into(),
483 post_label: String::new(),
484 message_id: message_id.into(),
485 created_at: Utc.with_ymd_and_hms(2024, 3, 4, 9, 30, 0).unwrap(),
486 }
487 }
488
489 fn file(name: &str) -> SharedContent {
490 SharedContent::File(FileCard {
491 name: name.into(),
492 kind: FileKind::from_name(name),
493 content_type: None,
494 size: None,
495 open_url: format!("https://example.invalid/{name}"),
496 })
497 }
498
499 #[test]
500 fn shared_section_lists_the_newest_files_and_skips_links() {
501 let items = vec![
502 shared(SharedContent::Link("https://example.invalid".into()), "1"),
503 shared(file("plan.docx"), "2"),
504 shared(file("budget.xlsx"), "3"),
505 ];
506 let (rows, more) = shared_file_rows(&items);
507 let names: Vec<&str> = rows.iter().map(|row| row.name.as_str()).collect();
508 assert_eq!(names, ["plan.docx", "budget.xlsx"]);
509 assert!(!more);
510 assert_eq!(rows[0].message_id, "2");
511 assert!(
512 rows[0].byline.starts_with("Ada Lovelace, "),
513 "{}",
514 rows[0].byline
515 );
516 }
517
518 #[test]
519 fn shared_section_offers_see_all_after_three_files() {
520 let items: Vec<SharedItem> = (0..4)
521 .map(|index| shared(file(&format!("file-{index}.pdf")), &index.to_string()))
522 .collect();
523 let (rows, more) = shared_file_rows(&items);
524 assert_eq!(rows.len(), 3);
525 assert!(more);
526 }
350}
527}
crates/app/src/views/conversation/pins.rs +53 −3
@@ -5,7 +5,12 @@ use gpui_kit::*;
5 5 use store::MessageRecord;
6 6
7 7 use super::ConversationView;
8 use crate::app_state::Selection;
8 use gpui_kit::component::WindowExt as _;
9 use gpui_kit::component::button::{Button, ButtonVariants as _};
10 use gpui_kit::component::dialog::DialogFooter;
11
12 use crate::app_state::{AppState, Selection};
13 use crate::channel_menu::post_pin_dialog;
9 14 use crate::rows::reply_excerpt;
10 15 use crate::runtime;
11 16 use crate::views::message_actions::Action;
@@ -25,6 +30,40 @@ impl PinPreview {
25 30 }
26 31 }
27 32
33 fn confirm_post_pin(
34 state: &Entity<AppState>,
35 channel_id: &str,
36 message_id: &str,
37 pin: bool,
38 window: &mut Window,
39 cx: &mut App,
40 ) {
41 let dialog = post_pin_dialog(pin);
42 let (state, channel_id, message_id) =
43 (state.clone(), channel_id.to_owned(), message_id.to_owned());
44 window.open_alert_dialog(cx, move |alert, _, _| {
45 let (state, channel_id, message_id) =
46 (state.clone(), channel_id.clone(), message_id.clone());
47 let cancel = Button::new("post-pin-cancel")
48 .label("Cancel")
49 .on_click(|_, window, cx| window.close_dialog(cx));
50 let confirm = Button::new("post-pin-confirm")
51 .label(dialog.confirm)
52 .primary()
53 .on_click(move |_, window, cx| {
54 state.update(cx, |state, cx| {
55 state.set_pinned(&channel_id, &message_id, pin, cx)
56 });
57 window.close_dialog(cx);
58 });
59 alert
60 .title(dialog.title)
61 .description(dialog.body)
62 .footer(DialogFooter::new().child(cancel).child(confirm))
63 .on_ok(|_, _, _| false)
64 });
65 }
66
28 67 impl ConversationView {
29 68 pub(super) fn chat_id(&self) -> Option<String> {
30 69 match self.current.as_ref()?.selection {
@@ -222,12 +261,23 @@ impl ConversationView {
222 261 }
223 262 }
224 263
225 pub(super) fn toggle_pinned(&mut self, message_id: &str, cx: &mut Context<Self>) {
226 if let Some(conversation_id) = self.pin_conversation_id() {
264 pub(super) fn toggle_pinned(
265 &mut self,
266 message_id: &str,
267 window: &mut Window,
268 cx: &mut Context<Self>,
269 ) {
270 let Some(conversation_id) = self.pin_conversation_id() else {
271 return;
272 };
273 if self.chat_id().is_some() {
227 274 self.app.update(cx, |state, cx| {
228 275 state.toggle_pinned(&conversation_id, message_id, cx)
229 276 });
277 return;
230 278 }
279 let pin = !self.app.read(cx).is_pinned(&conversation_id, message_id);
280 confirm_post_pin(&self.app, &conversation_id, message_id, pin, window, cx);
231 281 }
232 282
233 283 pub(super) fn mark_unread_from(&mut self, message_id: &str, cx: &mut Context<Self>) {
@@ -5,7 +5,12 @@ use gpui_kit::*;
5use store::MessageRecord;
5use store::MessageRecord;
6
6
7use super::ConversationView;
7use super::ConversationView;
8use crate::app_state::Selection;
8use gpui_kit::component::WindowExt as _;
9use gpui_kit::component::button::{Button, ButtonVariants as _};
10use gpui_kit::component::dialog::DialogFooter;
11
12use crate::app_state::{AppState, Selection};
13use crate::channel_menu::post_pin_dialog;
9use crate::rows::reply_excerpt;
14use crate::rows::reply_excerpt;
10use crate::runtime;
15use crate::runtime;
11use crate::views::message_actions::Action;
16use crate::views::message_actions::Action;
@@ -25,6 +30,40 @@ impl PinPreview {
25 }
30 }
26}
31}
27
32
33fn confirm_post_pin(
34 state: &Entity<AppState>,
35 channel_id: &str,
36 message_id: &str,
37 pin: bool,
38 window: &mut Window,
39 cx: &mut App,
40) {
41 let dialog = post_pin_dialog(pin);
42 let (state, channel_id, message_id) =
43 (state.clone(), channel_id.to_owned(), message_id.to_owned());
44 window.open_alert_dialog(cx, move |alert, _, _| {
45 let (state, channel_id, message_id) =
46 (state.clone(), channel_id.clone(), message_id.clone());
47 let cancel = Button::new("post-pin-cancel")
48 .label("Cancel")
49 .on_click(|_, window, cx| window.close_dialog(cx));
50 let confirm = Button::new("post-pin-confirm")
51 .label(dialog.confirm)
52 .primary()
53 .on_click(move |_, window, cx| {
54 state.update(cx, |state, cx| {
55 state.set_pinned(&channel_id, &message_id, pin, cx)
56 });
57 window.close_dialog(cx);
58 });
59 alert
60 .title(dialog.title)
61 .description(dialog.body)
62 .footer(DialogFooter::new().child(cancel).child(confirm))
63 .on_ok(|_, _, _| false)
64 });
65}
66
28impl ConversationView {
67impl ConversationView {
29 pub(super) fn chat_id(&self) -> Option<String> {
68 pub(super) fn chat_id(&self) -> Option<String> {
30 match self.current.as_ref()?.selection {
69 match self.current.as_ref()?.selection {
@@ -222,12 +261,23 @@ impl ConversationView {
222 }
261 }
223 }
262 }
224
263
225 pub(super) fn toggle_pinned(&mut self, message_id: &str, cx: &mut Context<Self>) {
264 pub(super) fn toggle_pinned(
226 if let Some(conversation_id) = self.pin_conversation_id() {
265 &mut self,
266 message_id: &str,
267 window: &mut Window,
268 cx: &mut Context<Self>,
269 ) {
270 let Some(conversation_id) = self.pin_conversation_id() else {
271 return;
272 };
273 if self.chat_id().is_some() {
227 self.app.update(cx, |state, cx| {
274 self.app.update(cx, |state, cx| {
228 state.toggle_pinned(&conversation_id, message_id, cx)
275 state.toggle_pinned(&conversation_id, message_id, cx)
229 });
276 });
277 return;
230 }
278 }
279 let pin = !self.app.read(cx).is_pinned(&conversation_id, message_id);
280 confirm_post_pin(&self.app, &conversation_id, message_id, pin, window, cx);
231 }
281 }
232
282
233 pub(super) fn mark_unread_from(&mut self, message_id: &str, cx: &mut Context<Self>) {
283 pub(super) fn mark_unread_from(&mut self, message_id: &str, cx: &mut Context<Self>) {
crates/app/src/views/conversation/shared.rs +3 −0
@@ -77,6 +77,9 @@ impl ConversationView {
77 77 generation: self.shared.generation + 1,
78 78 ..SharedState::default()
79 79 };
80 if self.channel_details_open {
81 self.refresh_shared_items(cx);
82 }
80 83 self.reload_channel_tabs(cx);
81 84 }
82 85
@@ -77,6 +77,9 @@ impl ConversationView {
77 generation: self.shared.generation + 1,
77 generation: self.shared.generation + 1,
78 ..SharedState::default()
78 ..SharedState::default()
79 };
79 };
80 if self.channel_details_open {
81 self.refresh_shared_items(cx);
82 }
80 self.reload_channel_tabs(cx);
83 self.reload_channel_tabs(cx);
81 }
84 }
82
85