BlueGit

ict rusty-teams

feat(channels): Manage channel in the channel menu

- channel "..." menu: Manage channel between the separator and Copy link (Teams order)
- deviation: opens the channel in Teams on the web, Teams opens its own Manage channel page
- not built: Get email address (MT GET beta/channels/{id}/email unverified, NotFound creates an address = write), Leave channel (MT DELETE, write not verifiable read-only, dialog text not captured)

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-04 · 3 weeks ago

Hash
d62843d5d6a832038596d584acda97a8ddc390a2
Parent
b7943a1b
2 files changed +52 −12
crates/app-state/src/channel_menu.rs +48 −12
@@ -15,6 +15,7 @@ pub enum ChannelMenuItem {
15 15 Unpin,
16 16 Show,
17 17 Hide,
18 ManageChannel,
18 19 CopyLink,
19 20 }
20 21
@@ -39,6 +40,7 @@ impl ChannelMenuItem {
39 40 ChannelMenuItem::Unpin => "Unpin",
40 41 ChannelMenuItem::Show => "Show",
41 42 ChannelMenuItem::Hide => "Hide",
43 ChannelMenuItem::ManageChannel => "Manage channel",
42 44 ChannelMenuItem::CopyLink => "Copy link",
43 45 }
44 46 }
@@ -54,6 +56,21 @@ impl TeamMenuItem {
54 56 }
55 57 }
56 58
59 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
60 enum LinkUse {
61 Copy,
62 OpenInBrowser,
63 }
64
65 impl LinkUse {
66 fn failure(self, reason: &str) -> String {
67 match self {
68 LinkUse::Copy => format!("Copy link failed: {reason}"),
69 LinkUse::OpenInBrowser => format!("Couldn't open Teams on the web: {reason}"),
70 }
71 }
72 }
73
57 74 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
58 75 pub struct ChannelMenuState {
59 76 pub pinned: bool,
@@ -80,6 +97,7 @@ pub fn channel_menu_entries(state: ChannelMenuState) -> Vec<MenuEntry<ChannelMen
80 97 ChannelMenuItem::Show
81 98 }),
82 99 MenuEntry::Separator,
100 MenuEntry::Item(ChannelMenuItem::ManageChannel),
83 101 MenuEntry::Item(ChannelMenuItem::CopyLink),
84 102 ]
85 103 }
@@ -260,6 +278,14 @@ impl AppState {
260 278 }
261 279
262 280 pub fn copy_channel_link(&mut self, channel_id: &str, cx: &mut Context<Self>) {
281 self.with_channel_link(channel_id, LinkUse::Copy, cx);
282 }
283
284 pub fn manage_channel_in_browser(&mut self, channel_id: &str, cx: &mut Context<Self>) {
285 self.with_channel_link(channel_id, LinkUse::OpenInBrowser, cx);
286 }
287
288 fn with_channel_link(&mut self, channel_id: &str, link_use: LinkUse, cx: &mut Context<Self>) {
263 289 let Some(engine) = self.engine.clone() else {
264 290 if self.mode.demo {
265 291 let link = teams_core::channel_link(&teams_core::ChannelAddress {
@@ -269,15 +295,19 @@ impl AppState {
269 295 channel_name: self.channel_name(channel_id).unwrap_or_default(),
270 296 membership_type: None,
271 297 });
272 self.copy_link(link, cx);
298 self.use_link(link, link_use, cx);
273 299 }
274 300 return;
275 301 };
276 302 let owned_id = channel_id.to_owned();
277 self.copy_link_from(async move { engine.channel_link(&owned_id).await }, cx);
303 self.link_from(async move { engine.channel_link(&owned_id).await }, link_use, cx);
278 304 }
279 305
280 306 pub fn copy_team_link(&mut self, team_id: &str, cx: &mut Context<Self>) {
307 self.with_team_link(team_id, LinkUse::Copy, cx);
308 }
309
310 fn with_team_link(&mut self, team_id: &str, link_use: LinkUse, cx: &mut Context<Self>) {
281 311 let Some(engine) = self.engine.clone() else {
282 312 if self.mode.demo {
283 313 let team_thread_id = self.store.team_thread_id(team_id).ok().flatten();
@@ -286,12 +316,12 @@ impl AppState {
286 316 team_id,
287 317 crate::demo::DEMO_TENANT_ID,
288 318 );
289 self.copy_link(link, cx);
319 self.use_link(link, link_use, cx);
290 320 }
291 321 return;
292 322 };
293 323 let owned_id = team_id.to_owned();
294 self.copy_link_from(async move { engine.team_link(&owned_id).await }, cx);
324 self.link_from(async move { engine.team_link(&owned_id).await }, link_use, cx);
295 325 }
296 326
297 327 fn channel_team_id(&self, channel_id: &str) -> Option<String> {
@@ -312,14 +342,20 @@ impl AppState {
312 342 .map(|channel| channel.name.clone())
313 343 }
314 344
315 fn copy_link(&mut self, link: String, cx: &mut Context<Self>) {
316 cx.write_to_clipboard(ClipboardItem::new_string(link));
317 self.raise_notice(COPIED_TO_CLIPBOARD.to_owned(), None, cx);
345 fn use_link(&mut self, link: String, link_use: LinkUse, cx: &mut Context<Self>) {
346 match link_use {
347 LinkUse::Copy => {
348 cx.write_to_clipboard(ClipboardItem::new_string(link));
349 self.raise_notice(COPIED_TO_CLIPBOARD.to_owned(), None, cx);
350 }
351 LinkUse::OpenInBrowser => cx.open_url(&link),
352 }
318 353 }
319 354
320 fn copy_link_from(
355 fn link_from(
321 356 &mut self,
322 357 call: impl Future<Output = teams_core::Result<String>> + Send + 'static,
358 link_use: LinkUse,
323 359 cx: &mut Context<Self>,
324 360 ) {
325 361 let receiver = crate::runtime::spawn(call);
@@ -330,8 +366,8 @@ impl AppState {
330 366 Err(_) => Err("cancelled".to_owned()),
331 367 };
332 368 this.update(cx, |state, cx| match outcome {
333 Ok(link) => state.copy_link(link, cx),
334 Err(reason) => state.raise_notice(format!("Copy link failed: {reason}"), None, cx),
369 Ok(link) => state.use_link(link, link_use, cx),
370 Err(reason) => state.raise_notice(link_use.failure(&reason), None, cx),
335 371 })
336 372 .ok();
337 373 })
@@ -392,7 +428,7 @@ mod tests {
392 428 });
393 429 assert_eq!(
394 430 labels(&shown, ChannelMenuItem::label),
395 ["Notifications", "Pin", "Hide", "-", "Copy link"]
431 ["Notifications", "Pin", "Hide", "-", "Manage channel", "Copy link"]
396 432 );
397 433 let hidden_pinned = channel_menu_entries(ChannelMenuState {
398 434 pinned: true,
@@ -400,7 +436,7 @@ mod tests {
400 436 });
401 437 assert_eq!(
402 438 labels(&hidden_pinned, ChannelMenuItem::label),
403 ["Notifications", "Unpin", "Show", "-", "Copy link"]
439 ["Notifications", "Unpin", "Show", "-", "Manage channel", "Copy link"]
404 440 );
405 441 }
406 442
@@ -15,6 +15,7 @@ pub enum ChannelMenuItem {
15 Unpin,
15 Unpin,
16 Show,
16 Show,
17 Hide,
17 Hide,
18 ManageChannel,
18 CopyLink,
19 CopyLink,
19}
20}
20
21
@@ -39,6 +40,7 @@ impl ChannelMenuItem {
39 ChannelMenuItem::Unpin => "Unpin",
40 ChannelMenuItem::Unpin => "Unpin",
40 ChannelMenuItem::Show => "Show",
41 ChannelMenuItem::Show => "Show",
41 ChannelMenuItem::Hide => "Hide",
42 ChannelMenuItem::Hide => "Hide",
43 ChannelMenuItem::ManageChannel => "Manage channel",
42 ChannelMenuItem::CopyLink => "Copy link",
44 ChannelMenuItem::CopyLink => "Copy link",
43 }
45 }
44 }
46 }
@@ -54,6 +56,21 @@ impl TeamMenuItem {
54 }
56 }
55}
57}
56
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq)]
60enum LinkUse {
61 Copy,
62 OpenInBrowser,
63}
64
65impl LinkUse {
66 fn failure(self, reason: &str) -> String {
67 match self {
68 LinkUse::Copy => format!("Copy link failed: {reason}"),
69 LinkUse::OpenInBrowser => format!("Couldn't open Teams on the web: {reason}"),
70 }
71 }
72}
73
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub struct ChannelMenuState {
75pub struct ChannelMenuState {
59 pub pinned: bool,
76 pub pinned: bool,
@@ -80,6 +97,7 @@ pub fn channel_menu_entries(state: ChannelMenuState) -> Vec<MenuEntry<ChannelMen
80 ChannelMenuItem::Show
97 ChannelMenuItem::Show
81 }),
98 }),
82 MenuEntry::Separator,
99 MenuEntry::Separator,
100 MenuEntry::Item(ChannelMenuItem::ManageChannel),
83 MenuEntry::Item(ChannelMenuItem::CopyLink),
101 MenuEntry::Item(ChannelMenuItem::CopyLink),
84 ]
102 ]
85}
103}
@@ -260,6 +278,14 @@ impl AppState {
260 }
278 }
261
279
262 pub fn copy_channel_link(&mut self, channel_id: &str, cx: &mut Context<Self>) {
280 pub fn copy_channel_link(&mut self, channel_id: &str, cx: &mut Context<Self>) {
281 self.with_channel_link(channel_id, LinkUse::Copy, cx);
282 }
283
284 pub fn manage_channel_in_browser(&mut self, channel_id: &str, cx: &mut Context<Self>) {
285 self.with_channel_link(channel_id, LinkUse::OpenInBrowser, cx);
286 }
287
288 fn with_channel_link(&mut self, channel_id: &str, link_use: LinkUse, cx: &mut Context<Self>) {
263 let Some(engine) = self.engine.clone() else {
289 let Some(engine) = self.engine.clone() else {
264 if self.mode.demo {
290 if self.mode.demo {
265 let link = teams_core::channel_link(&teams_core::ChannelAddress {
291 let link = teams_core::channel_link(&teams_core::ChannelAddress {
@@ -269,15 +295,19 @@ impl AppState {
269 channel_name: self.channel_name(channel_id).unwrap_or_default(),
295 channel_name: self.channel_name(channel_id).unwrap_or_default(),
270 membership_type: None,
296 membership_type: None,
271 });
297 });
272 self.copy_link(link, cx);
298 self.use_link(link, link_use, cx);
273 }
299 }
274 return;
300 return;
275 };
301 };
276 let owned_id = channel_id.to_owned();
302 let owned_id = channel_id.to_owned();
277 self.copy_link_from(async move { engine.channel_link(&owned_id).await }, cx);
303 self.link_from(async move { engine.channel_link(&owned_id).await }, link_use, cx);
278 }
304 }
279
305
280 pub fn copy_team_link(&mut self, team_id: &str, cx: &mut Context<Self>) {
306 pub fn copy_team_link(&mut self, team_id: &str, cx: &mut Context<Self>) {
307 self.with_team_link(team_id, LinkUse::Copy, cx);
308 }
309
310 fn with_team_link(&mut self, team_id: &str, link_use: LinkUse, cx: &mut Context<Self>) {
281 let Some(engine) = self.engine.clone() else {
311 let Some(engine) = self.engine.clone() else {
282 if self.mode.demo {
312 if self.mode.demo {
283 let team_thread_id = self.store.team_thread_id(team_id).ok().flatten();
313 let team_thread_id = self.store.team_thread_id(team_id).ok().flatten();
@@ -286,12 +316,12 @@ impl AppState {
286 team_id,
316 team_id,
287 crate::demo::DEMO_TENANT_ID,
317 crate::demo::DEMO_TENANT_ID,
288 );
318 );
289 self.copy_link(link, cx);
319 self.use_link(link, link_use, cx);
290 }
320 }
291 return;
321 return;
292 };
322 };
293 let owned_id = team_id.to_owned();
323 let owned_id = team_id.to_owned();
294 self.copy_link_from(async move { engine.team_link(&owned_id).await }, cx);
324 self.link_from(async move { engine.team_link(&owned_id).await }, link_use, cx);
295 }
325 }
296
326
297 fn channel_team_id(&self, channel_id: &str) -> Option<String> {
327 fn channel_team_id(&self, channel_id: &str) -> Option<String> {
@@ -312,14 +342,20 @@ impl AppState {
312 .map(|channel| channel.name.clone())
342 .map(|channel| channel.name.clone())
313 }
343 }
314
344
315 fn copy_link(&mut self, link: String, cx: &mut Context<Self>) {
345 fn use_link(&mut self, link: String, link_use: LinkUse, cx: &mut Context<Self>) {
316 cx.write_to_clipboard(ClipboardItem::new_string(link));
346 match link_use {
317 self.raise_notice(COPIED_TO_CLIPBOARD.to_owned(), None, cx);
347 LinkUse::Copy => {
348 cx.write_to_clipboard(ClipboardItem::new_string(link));
349 self.raise_notice(COPIED_TO_CLIPBOARD.to_owned(), None, cx);
350 }
351 LinkUse::OpenInBrowser => cx.open_url(&link),
352 }
318 }
353 }
319
354
320 fn copy_link_from(
355 fn link_from(
321 &mut self,
356 &mut self,
322 call: impl Future<Output = teams_core::Result<String>> + Send + 'static,
357 call: impl Future<Output = teams_core::Result<String>> + Send + 'static,
358 link_use: LinkUse,
323 cx: &mut Context<Self>,
359 cx: &mut Context<Self>,
324 ) {
360 ) {
325 let receiver = crate::runtime::spawn(call);
361 let receiver = crate::runtime::spawn(call);
@@ -330,8 +366,8 @@ impl AppState {
330 Err(_) => Err("cancelled".to_owned()),
366 Err(_) => Err("cancelled".to_owned()),
331 };
367 };
332 this.update(cx, |state, cx| match outcome {
368 this.update(cx, |state, cx| match outcome {
333 Ok(link) => state.copy_link(link, cx),
369 Ok(link) => state.use_link(link, link_use, cx),
334 Err(reason) => state.raise_notice(format!("Copy link failed: {reason}"), None, cx),
370 Err(reason) => state.raise_notice(link_use.failure(&reason), None, cx),
335 })
371 })
336 .ok();
372 .ok();
337 })
373 })
@@ -392,7 +428,7 @@ mod tests {
392 });
428 });
393 assert_eq!(
429 assert_eq!(
394 labels(&shown, ChannelMenuItem::label),
430 labels(&shown, ChannelMenuItem::label),
395 ["Notifications", "Pin", "Hide", "-", "Copy link"]
431 ["Notifications", "Pin", "Hide", "-", "Manage channel", "Copy link"]
396 );
432 );
397 let hidden_pinned = channel_menu_entries(ChannelMenuState {
433 let hidden_pinned = channel_menu_entries(ChannelMenuState {
398 pinned: true,
434 pinned: true,
@@ -400,7 +436,7 @@ mod tests {
400 });
436 });
401 assert_eq!(
437 assert_eq!(
402 labels(&hidden_pinned, ChannelMenuItem::label),
438 labels(&hidden_pinned, ChannelMenuItem::label),
403 ["Notifications", "Unpin", "Show", "-", "Copy link"]
439 ["Notifications", "Unpin", "Show", "-", "Manage channel", "Copy link"]
404 );
440 );
405 }
441 }
406
442
crates/app/src/views/sidebar.rs +4 −0
@@ -1931,6 +1931,9 @@ fn channel_menu(
1931 1931 ChannelMenuItem::Unpin => state.set_channel_pinned(&action_id, false, cx),
1932 1932 ChannelMenuItem::Show => state.set_channel_shown(&action_id, true, cx),
1933 1933 ChannelMenuItem::Hide => state.set_channel_shown(&action_id, false, cx),
1934 ChannelMenuItem::ManageChannel => {
1935 state.manage_channel_in_browser(&action_id, cx)
1936 }
1934 1937 ChannelMenuItem::CopyLink => state.copy_channel_link(&action_id, cx),
1935 1938 ChannelMenuItem::Notifications => {}
1936 1939 });
@@ -1947,6 +1950,7 @@ fn channel_menu_icon(item: ChannelMenuItem) -> IconName {
1947 1950 ChannelMenuItem::Unpin => IconName::PinOff,
1948 1951 ChannelMenuItem::Show => IconName::Eye,
1949 1952 ChannelMenuItem::Hide => IconName::EyeOff,
1953 ChannelMenuItem::ManageChannel => IconName::Settings,
1950 1954 ChannelMenuItem::CopyLink => IconName::Link,
1951 1955 }
1952 1956 }
@@ -1931,6 +1931,9 @@ fn channel_menu(
1931 ChannelMenuItem::Unpin => state.set_channel_pinned(&action_id, false, cx),
1931 ChannelMenuItem::Unpin => state.set_channel_pinned(&action_id, false, cx),
1932 ChannelMenuItem::Show => state.set_channel_shown(&action_id, true, cx),
1932 ChannelMenuItem::Show => state.set_channel_shown(&action_id, true, cx),
1933 ChannelMenuItem::Hide => state.set_channel_shown(&action_id, false, cx),
1933 ChannelMenuItem::Hide => state.set_channel_shown(&action_id, false, cx),
1934 ChannelMenuItem::ManageChannel => {
1935 state.manage_channel_in_browser(&action_id, cx)
1936 }
1934 ChannelMenuItem::CopyLink => state.copy_channel_link(&action_id, cx),
1937 ChannelMenuItem::CopyLink => state.copy_channel_link(&action_id, cx),
1935 ChannelMenuItem::Notifications => {}
1938 ChannelMenuItem::Notifications => {}
1936 });
1939 });
@@ -1947,6 +1950,7 @@ fn channel_menu_icon(item: ChannelMenuItem) -> IconName {
1947 ChannelMenuItem::Unpin => IconName::PinOff,
1950 ChannelMenuItem::Unpin => IconName::PinOff,
1948 ChannelMenuItem::Show => IconName::Eye,
1951 ChannelMenuItem::Show => IconName::Eye,
1949 ChannelMenuItem::Hide => IconName::EyeOff,
1952 ChannelMenuItem::Hide => IconName::EyeOff,
1953 ChannelMenuItem::ManageChannel => IconName::Settings,
1950 ChannelMenuItem::CopyLink => IconName::Link,
1954 ChannelMenuItem::CopyLink => IconName::Link,
1951 }
1955 }
1952}
1956}