BlueGit

ict rusty-teams

feat(parity): Chat and Teams rail items reopen their own last conversation

- switching rail apps restores the last chat or channel like Teams
- without a remembered one, Chat opens the newest chat and Teams the first visible channel

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-08 · 3 weeks ago

Hash
7a908a34bc67cae35eb3e8f47bca54ae8dc08e17
Parent
7f0f3b90
3 files changed +126 −3
crates/app/src/views/last_views.rs added +81 −0
@@ -0,0 +1,81 @@
1 use super::sidebar::SidebarTab;
2 use crate::app_state::Selection;
3
4 #[derive(Debug, Default, Clone, PartialEq, Eq)]
5 pub struct LastViews {
6 chat: Option<String>,
7 channel: Option<String>,
8 }
9
10 impl LastViews {
11 pub fn remember(&mut self, selection: &Selection) {
12 match selection {
13 Selection::Chat(chat_id) => self.chat = Some(chat_id.clone()),
14 Selection::Channel(channel_id) => self.channel = Some(channel_id.clone()),
15 }
16 }
17
18 pub fn restore(
19 &self,
20 tab: SidebarTab,
21 current: Option<&Selection>,
22 first_chat_id: Option<&str>,
23 first_channel_id: Option<&str>,
24 ) -> Option<Selection> {
25 match (tab, current) {
26 (SidebarTab::Chats, Some(Selection::Chat(_))) => None,
27 (SidebarTab::Channels, Some(Selection::Channel(_))) => None,
28 (SidebarTab::Chats, _) => self
29 .chat
30 .clone()
31 .or_else(|| first_chat_id.map(str::to_owned))
32 .map(Selection::Chat),
33 (SidebarTab::Channels, _) => self
34 .channel
35 .clone()
36 .or_else(|| first_channel_id.map(str::to_owned))
37 .map(Selection::Channel),
38 _ => None,
39 }
40 }
41 }
42
43 #[cfg(test)]
44 mod tests {
45 use super::*;
46
47 #[test]
48 fn each_app_gets_back_its_own_conversation() {
49 let mut last = LastViews::default();
50 let chat = Selection::Chat("19:chat".to_owned());
51 let channel = Selection::Channel("19:channel".to_owned());
52 last.remember(&chat);
53 last.remember(&channel);
54 assert_eq!(
55 last.restore(SidebarTab::Chats, Some(&channel), Some("19:first"), None),
56 Some(chat.clone())
57 );
58 assert_eq!(
59 last.restore(SidebarTab::Channels, Some(&chat), None, Some("19:general")),
60 Some(channel.clone())
61 );
62 assert_eq!(last.restore(SidebarTab::Chats, Some(&chat), None, None), None);
63 assert_eq!(last.restore(SidebarTab::Calendar, Some(&channel), None, None), None);
64 }
65
66 #[test]
67 fn each_app_falls_back_to_its_first_conversation() {
68 let last = LastViews::default();
69 let channel = Selection::Channel("19:channel".to_owned());
70 assert_eq!(
71 last.restore(SidebarTab::Chats, Some(&channel), Some("19:first"), None),
72 Some(Selection::Chat("19:first".to_owned()))
73 );
74 let chat = Selection::Chat("19:chat".to_owned());
75 assert_eq!(
76 last.restore(SidebarTab::Channels, Some(&chat), None, Some("19:general")),
77 Some(Selection::Channel("19:general".to_owned()))
78 );
79 assert_eq!(last.restore(SidebarTab::Channels, Some(&chat), None, None), None);
80 }
81 }
@@ -0,0 +1,81 @@
1use super::sidebar::SidebarTab;
2use crate::app_state::Selection;
3
4#[derive(Debug, Default, Clone, PartialEq, Eq)]
5pub struct LastViews {
6 chat: Option<String>,
7 channel: Option<String>,
8}
9
10impl LastViews {
11 pub fn remember(&mut self, selection: &Selection) {
12 match selection {
13 Selection::Chat(chat_id) => self.chat = Some(chat_id.clone()),
14 Selection::Channel(channel_id) => self.channel = Some(channel_id.clone()),
15 }
16 }
17
18 pub fn restore(
19 &self,
20 tab: SidebarTab,
21 current: Option<&Selection>,
22 first_chat_id: Option<&str>,
23 first_channel_id: Option<&str>,
24 ) -> Option<Selection> {
25 match (tab, current) {
26 (SidebarTab::Chats, Some(Selection::Chat(_))) => None,
27 (SidebarTab::Channels, Some(Selection::Channel(_))) => None,
28 (SidebarTab::Chats, _) => self
29 .chat
30 .clone()
31 .or_else(|| first_chat_id.map(str::to_owned))
32 .map(Selection::Chat),
33 (SidebarTab::Channels, _) => self
34 .channel
35 .clone()
36 .or_else(|| first_channel_id.map(str::to_owned))
37 .map(Selection::Channel),
38 _ => None,
39 }
40 }
41}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn each_app_gets_back_its_own_conversation() {
49 let mut last = LastViews::default();
50 let chat = Selection::Chat("19:chat".to_owned());
51 let channel = Selection::Channel("19:channel".to_owned());
52 last.remember(&chat);
53 last.remember(&channel);
54 assert_eq!(
55 last.restore(SidebarTab::Chats, Some(&channel), Some("19:first"), None),
56 Some(chat.clone())
57 );
58 assert_eq!(
59 last.restore(SidebarTab::Channels, Some(&chat), None, Some("19:general")),
60 Some(channel.clone())
61 );
62 assert_eq!(last.restore(SidebarTab::Chats, Some(&chat), None, None), None);
63 assert_eq!(last.restore(SidebarTab::Calendar, Some(&channel), None, None), None);
64 }
65
66 #[test]
67 fn each_app_falls_back_to_its_first_conversation() {
68 let last = LastViews::default();
69 let channel = Selection::Channel("19:channel".to_owned());
70 assert_eq!(
71 last.restore(SidebarTab::Chats, Some(&channel), Some("19:first"), None),
72 Some(Selection::Chat("19:first".to_owned()))
73 );
74 let chat = Selection::Chat("19:chat".to_owned());
75 assert_eq!(
76 last.restore(SidebarTab::Channels, Some(&chat), None, Some("19:general")),
77 Some(Selection::Channel("19:general".to_owned()))
78 );
79 assert_eq!(last.restore(SidebarTab::Channels, Some(&chat), None, None), None);
80 }
81}
crates/app/src/views/mod.rs +1 −0
@@ -81,6 +81,7 @@ pub mod skin_tone_choices;
81 81 pub mod shell;
82 82 pub mod shortcuts;
83 83 pub mod shortcuts_dialog;
84 mod last_views;
84 85 pub mod sidebar;
85 86 pub mod status_menu;
86 87 pub mod status_message_dialog;
@@ -81,6 +81,7 @@ pub mod skin_tone_choices;
81pub mod shell;
81pub mod shell;
82pub mod shortcuts;
82pub mod shortcuts;
83pub mod shortcuts_dialog;
83pub mod shortcuts_dialog;
84mod last_views;
84pub mod sidebar;
85pub mod sidebar;
85pub mod status_menu;
86pub mod status_menu;
86pub mod status_message_dialog;
87pub mod status_message_dialog;
crates/app/src/views/sidebar.rs +44 −3
@@ -30,6 +30,7 @@ use super::create_channel_dialog::open_create_channel_dialog;
30 30 use super::section_dialog::{SectionNameTarget, open_section_name_dialog};
31 31 use super::widgets::{count_badge, icon, menu_icon, page_header, symbol, unread_marker};
32 32 use crate::agents::AgentsPanel;
33 use super::last_views::LastViews;
33 34 use crate::app_state::{AppEvent, AppState, Selection};
34 35 use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};
35 36 use crate::channel_menu::{
@@ -695,6 +696,7 @@ pub struct SidebarView {
695 696 more_filters_open: bool,
696 697 filter_input: Option<Entity<InputState>>,
697 698 filter_subscription: Option<Subscription>,
699 last_views: LastViews,
698 700 _activity_observation: Subscription,
699 701 _subscription: Subscription,
700 702 _state_observation: Subscription,
@@ -753,6 +755,9 @@ impl SidebarView {
753 755 ) -> Self {
754 756 let subscription = cx.subscribe(&state, |this, state, event: &AppEvent, cx| {
755 757 if matches!(event, AppEvent::Selection) {
758 if let Some(selection) = &state.read(cx).selection {
759 this.last_views.remember(selection);
760 }
756 761 if state.read(cx).new_chat {
757 762 this.tab = SidebarTab::Chats;
758 763 }
@@ -829,6 +834,7 @@ impl SidebarView {
829 834 more_filters_open: false,
830 835 filter_input: None,
831 836 filter_subscription: None,
837 last_views: LastViews::default(),
832 838 _activity_observation: activity_observation,
833 839 _subscription: subscription,
834 840 _state_observation: state_observation,
@@ -876,6 +882,7 @@ impl SidebarView {
876 882 let changed = self.tab != tab;
877 883 self.tab = tab;
878 884 if changed {
885 self.restore_last_view(tab, cx);
879 886 cx.emit(SidebarEvent::TabChanged);
880 887 }
881 888 match tab {
@@ -894,6 +901,27 @@ impl SidebarView {
894 901 cx.notify();
895 902 }
896 903
904 fn restore_last_view(&mut self, tab: SidebarTab, cx: &mut Context<Self>) {
905 let first_channel_id = self.first_channel_id(cx);
906 let state = self.state.read(cx);
907 if let Some(current) = &state.selection {
908 self.last_views.remember(current);
909 }
910 let first_chat_id = state.sidebar.chats.first().map(|chat| chat.id.as_str());
911 if let Some(selection) =
912 self.last_views
913 .restore(
914 tab,
915 state.selection.as_ref(),
916 first_chat_id,
917 first_channel_id.as_deref(),
918 )
919 {
920 self.state
921 .update(cx, |state, cx| state.select(selection, cx));
922 }
923 }
924
897 925 pub fn select_adjacent(&mut self, step: Step, cx: &mut Context<Self>) {
898 926 let selection = match self.tab {
899 927 SidebarTab::Chats => self
@@ -920,15 +948,28 @@ impl SidebarView {
920 948 Some(Selection::Channel(channel_id)) => Some(channel_id.as_str()),
921 949 _ => None,
922 950 };
923 let input = ChannelOrderInput {
951 let input = self.channel_order_input(state, selected_channel);
952 step_id(&visible_channel_ids(&input), selected_channel, step)
953 }
954
955 fn first_channel_id(&self, cx: &App) -> Option<String> {
956 let input = self.channel_order_input(self.state.read(cx), None);
957 visible_channel_ids(&input).first().map(|id| (*id).to_owned())
958 }
959
960 fn channel_order_input<'a>(
961 &'a self,
962 state: &'a AppState,
963 selected_channel: Option<&'a str>,
964 ) -> ChannelOrderInput<'a> {
965 ChannelOrderInput {
924 966 teams: &state.sidebar.teams,
925 967 pinned_ids: &state.directory.pinned_channels,
926 968 collapsed_teams: &self.collapsed_teams,
927 969 revealed_channel_teams: &self.revealed_channel_teams,
928 970 hidden_teams_open: self.hidden_teams_open,
929 971 selected_channel,
930 };
931 step_id(&visible_channel_ids(&input), selected_channel, step)
972 }
932 973 }
933 974
934 975 fn expand_team_of_selection(&mut self, cx: &mut Context<Self>) {
@@ -30,6 +30,7 @@ use super::create_channel_dialog::open_create_channel_dialog;
30use super::section_dialog::{SectionNameTarget, open_section_name_dialog};
30use super::section_dialog::{SectionNameTarget, open_section_name_dialog};
31use super::widgets::{count_badge, icon, menu_icon, page_header, symbol, unread_marker};
31use super::widgets::{count_badge, icon, menu_icon, page_header, symbol, unread_marker};
32use crate::agents::AgentsPanel;
32use crate::agents::AgentsPanel;
33use super::last_views::LastViews;
33use crate::app_state::{AppEvent, AppState, Selection};
34use crate::app_state::{AppEvent, AppState, Selection};
34use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};
35use crate::presence_follow::{NOTIFY_WHEN_AVAILABLE, TURN_OFF_NOTIFICATIONS};
35use crate::channel_menu::{
36use crate::channel_menu::{
@@ -695,6 +696,7 @@ pub struct SidebarView {
695 more_filters_open: bool,
696 more_filters_open: bool,
696 filter_input: Option<Entity<InputState>>,
697 filter_input: Option<Entity<InputState>>,
697 filter_subscription: Option<Subscription>,
698 filter_subscription: Option<Subscription>,
699 last_views: LastViews,
698 _activity_observation: Subscription,
700 _activity_observation: Subscription,
699 _subscription: Subscription,
701 _subscription: Subscription,
700 _state_observation: Subscription,
702 _state_observation: Subscription,
@@ -753,6 +755,9 @@ impl SidebarView {
753 ) -> Self {
755 ) -> Self {
754 let subscription = cx.subscribe(&state, |this, state, event: &AppEvent, cx| {
756 let subscription = cx.subscribe(&state, |this, state, event: &AppEvent, cx| {
755 if matches!(event, AppEvent::Selection) {
757 if matches!(event, AppEvent::Selection) {
758 if let Some(selection) = &state.read(cx).selection {
759 this.last_views.remember(selection);
760 }
756 if state.read(cx).new_chat {
761 if state.read(cx).new_chat {
757 this.tab = SidebarTab::Chats;
762 this.tab = SidebarTab::Chats;
758 }
763 }
@@ -829,6 +834,7 @@ impl SidebarView {
829 more_filters_open: false,
834 more_filters_open: false,
830 filter_input: None,
835 filter_input: None,
831 filter_subscription: None,
836 filter_subscription: None,
837 last_views: LastViews::default(),
832 _activity_observation: activity_observation,
838 _activity_observation: activity_observation,
833 _subscription: subscription,
839 _subscription: subscription,
834 _state_observation: state_observation,
840 _state_observation: state_observation,
@@ -876,6 +882,7 @@ impl SidebarView {
876 let changed = self.tab != tab;
882 let changed = self.tab != tab;
877 self.tab = tab;
883 self.tab = tab;
878 if changed {
884 if changed {
885 self.restore_last_view(tab, cx);
879 cx.emit(SidebarEvent::TabChanged);
886 cx.emit(SidebarEvent::TabChanged);
880 }
887 }
881 match tab {
888 match tab {
@@ -894,6 +901,27 @@ impl SidebarView {
894 cx.notify();
901 cx.notify();
895 }
902 }
896
903
904 fn restore_last_view(&mut self, tab: SidebarTab, cx: &mut Context<Self>) {
905 let first_channel_id = self.first_channel_id(cx);
906 let state = self.state.read(cx);
907 if let Some(current) = &state.selection {
908 self.last_views.remember(current);
909 }
910 let first_chat_id = state.sidebar.chats.first().map(|chat| chat.id.as_str());
911 if let Some(selection) =
912 self.last_views
913 .restore(
914 tab,
915 state.selection.as_ref(),
916 first_chat_id,
917 first_channel_id.as_deref(),
918 )
919 {
920 self.state
921 .update(cx, |state, cx| state.select(selection, cx));
922 }
923 }
924
897 pub fn select_adjacent(&mut self, step: Step, cx: &mut Context<Self>) {
925 pub fn select_adjacent(&mut self, step: Step, cx: &mut Context<Self>) {
898 let selection = match self.tab {
926 let selection = match self.tab {
899 SidebarTab::Chats => self
927 SidebarTab::Chats => self
@@ -920,15 +948,28 @@ impl SidebarView {
920 Some(Selection::Channel(channel_id)) => Some(channel_id.as_str()),
948 Some(Selection::Channel(channel_id)) => Some(channel_id.as_str()),
921 _ => None,
949 _ => None,
922 };
950 };
923 let input = ChannelOrderInput {
951 let input = self.channel_order_input(state, selected_channel);
952 step_id(&visible_channel_ids(&input), selected_channel, step)
953 }
954
955 fn first_channel_id(&self, cx: &App) -> Option<String> {
956 let input = self.channel_order_input(self.state.read(cx), None);
957 visible_channel_ids(&input).first().map(|id| (*id).to_owned())
958 }
959
960 fn channel_order_input<'a>(
961 &'a self,
962 state: &'a AppState,
963 selected_channel: Option<&'a str>,
964 ) -> ChannelOrderInput<'a> {
965 ChannelOrderInput {
924 teams: &state.sidebar.teams,
966 teams: &state.sidebar.teams,
925 pinned_ids: &state.directory.pinned_channels,
967 pinned_ids: &state.directory.pinned_channels,
926 collapsed_teams: &self.collapsed_teams,
968 collapsed_teams: &self.collapsed_teams,
927 revealed_channel_teams: &self.revealed_channel_teams,
969 revealed_channel_teams: &self.revealed_channel_teams,
928 hidden_teams_open: self.hidden_teams_open,
970 hidden_teams_open: self.hidden_teams_open,
929 selected_channel,
971 selected_channel,
930 };
972 }
931 step_id(&visible_channel_ids(&input), selected_channel, step)
932 }
973 }
933
974
934 fn expand_team_of_selection(&mut self, cx: &mut Context<Self>) {
975 fn expand_team_of_selection(&mut self, cx: &mut Context<Self>) {