From 9e47882fb19b690bff9fa00214d77dcdcfbfcf29 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sat, 19 Sep 2026 18:34:39 +0700 Subject: [PATCH] remove pin --- crates/settings/src/lib.rs | 6 -- crates/workspace/src/sidebar/mod.rs | 105 +++------------------------ crates/workspace/src/sidebar/tree.rs | 6 +- 3 files changed, 10 insertions(+), 107 deletions(-) diff --git a/crates/settings/src/lib.rs b/crates/settings/src/lib.rs index b48c20e8..73ca64ae 100644 --- a/crates/settings/src/lib.rs +++ b/crates/settings/src/lib.rs @@ -46,7 +46,6 @@ setting_accessors! { pub nip4e: bool, pub trusted_relays: Vec, pub file_server: Url, - pub pinned_rooms: Vec, pub expanded_sections: Option>, } @@ -133,10 +132,6 @@ pub struct Settings { /// Server for blossom media attachments pub file_server: Url, - /// Pinned sidebar room ids, in pin order - #[serde(default)] - pub pinned_rooms: Vec, - /// Expanded sidebar tree sections; `None` means the default sections #[serde(default)] pub expanded_sections: Option>, @@ -152,7 +147,6 @@ impl Default for Settings { nip4e: false, trusted_relays: vec![], file_server: Url::parse(DEFAULT_FILE_SERVER).unwrap(), - pinned_rooms: vec![], expanded_sections: None, } } diff --git a/crates/workspace/src/sidebar/mod.rs b/crates/workspace/src/sidebar/mod.rs index a7b616eb..db5342b2 100644 --- a/crates/workspace/src/sidebar/mod.rs +++ b/crates/workspace/src/sidebar/mod.rs @@ -3,13 +3,13 @@ use std::ops::Range; use std::rc::Rc; use auto_update::AutoUpdater; -use chat::{ChatEvent, ChatRegistry, Room, RoomKind}; +use chat::{ChatEvent, ChatRegistry, RoomKind}; use common::TimestampExt; use community::{CommunityEvent, CommunityRegistry}; use gpui::prelude::FluentBuilder; use gpui::{ - AnyElement, App, Context, ElementId, Entity, EventEmitter, FocusHandle, Focusable, - InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription, + AnyElement, App, Context, ElementId, EventEmitter, FocusHandle, Focusable, InteractiveElement, + IntoElement, ParentElement, Render, SharedString, Styled, Subscription, UniformListScrollHandle, Window, div, px, retain_all, uniform_list, }; use person::PersonRegistry; @@ -21,7 +21,7 @@ use ui::avatar::Avatar; use ui::button::{Button, ButtonVariants}; use ui::dock::{ClosePanel, Panel, PanelEvent}; use ui::indicator::Indicator; -use ui::menu::{ContextMenu, DropdownMenu, PopupMenuItem}; +use ui::menu::{DropdownMenu, PopupMenuItem}; use ui::modal::ModalButtonProps; use ui::nav_item::NavItem; use ui::scroll::Scrollbar; @@ -45,8 +45,6 @@ pub struct Sidebar { new_requests: bool, /// Expanded tree sections expanded: BTreeSet, - /// Pinned room ids, in pin order - pinned_rooms: Vec, _subscriptions: SmallVec<[Subscription; 2]>, } @@ -84,7 +82,6 @@ impl Sidebar { scroll_handle: UniformListScrollHandle::new(), new_requests: false, expanded: load_expanded(cx), - pinned_rooms: AppSettings::get_pinned_rooms(cx), _subscriptions: subscriptions, } } @@ -103,14 +100,10 @@ impl Sidebar { } fn restore_state(&mut self, cx: &mut Context) { - let pinned_rooms = AppSettings::get_pinned_rooms(cx); let expanded = load_expanded(cx); - - if self.pinned_rooms == pinned_rooms && self.expanded == expanded { + if self.expanded == expanded { return; } - - self.pinned_rooms = pinned_rooms; self.expanded = expanded; cx.notify(); } @@ -124,56 +117,12 @@ impl Sidebar { AppSettings::update_expanded_sections(Some(keys), cx); } - fn pin_room(&mut self, room_id: u64, cx: &mut Context) { - if !self.pinned_rooms.contains(&room_id) { - self.pinned_rooms.push(room_id); - } - self.expanded.insert(TreeSection::Pins); - - AppSettings::update_pinned_rooms(self.pinned_rooms.clone(), cx); - self.save_expanded(cx); - cx.notify(); - } - - fn unpin_room(&mut self, room_id: u64, cx: &mut Context) { - self.pinned_rooms.retain(|id| *id != room_id); - - AppSettings::update_pinned_rooms(self.pinned_rooms.clone(), cx); - cx.notify(); - } - - fn is_pinned(&self, room_id: u64) -> bool { - self.pinned_rooms.contains(&room_id) - } - fn tree_rows(&self, cx: &App) -> Vec { let chat = ChatRegistry::global(cx); let chat = chat.read(cx); let mut rows = Vec::new(); - let pinned: Vec> = self - .pinned_rooms - .iter() - .filter_map(|room_id| chat.room(room_id, cx)) - .filter_map(|room| room.upgrade()) - .collect(); - - if !pinned.is_empty() { - rows.push(SidebarRow::Section { - section: TreeSection::Pins, - count: pinned.len(), - }); - - if self.is_expanded(TreeSection::Pins) { - rows.extend( - pinned - .into_iter() - .map(|room| SidebarRow::Room { room, pinned: true }), - ); - } - } - let registry = CommunityRegistry::global(cx); let communities = registry.read(cx).communities(); @@ -209,10 +158,7 @@ impl Sidebar { text: "No conversations yet".into(), }); } else { - rows.extend(messages.into_iter().map(|room| { - let pinned = self.is_pinned(room.read(cx).id); - SidebarRow::Room { room, pinned } - })); + rows.extend(messages.into_iter().map(|room| SidebarRow::Room { room })); } } @@ -252,9 +198,7 @@ impl Sidebar { })) .into_any_element() } - SidebarRow::Room { room, pinned } => { - let pinned = *pinned; - let room_id = room.read(cx).id; + SidebarRow::Room { room } => { let public_key = room.read(cx).display_member(cx).public_key(); let name = room.read(cx).display_name(cx); let picture = room.read(cx).display_image(cx); @@ -262,7 +206,6 @@ impl Sidebar { let kind = room.read(cx).kind; let created_at = room.read(cx).created_at.to_ago(); let room_clone = room.clone(); - let sidebar = cx.entity().downgrade(); let handler = cx.listener(move |_this, _event, window, cx| { ChatRegistry::global(cx).update(cx, |chat, cx| { @@ -288,7 +231,7 @@ impl Sidebar { } }); - let entry = TreeRow::new( + TreeRow::new( ElementId::NamedInteger("tree-row".into(), index as u64), TreeRowKind::Room, name, @@ -296,37 +239,7 @@ impl Sidebar { .avatar(seed) .picture(picture) .created_at(created_at) - .on_click(handler); - - ContextMenu::new( - ElementId::NamedInteger("room-context-menu".into(), index as u64), - entry, - move |this, _window, _cx| { - let sidebar = sidebar.clone(); - - if pinned { - this.item(PopupMenuItem::new("Unpin").on_click( - move |_event, _window, cx| { - if let Err(error) = sidebar.update(cx, |sidebar, cx| { - sidebar.unpin_room(room_id, cx); - }) { - log::error!("Failed to unpin room: {error}"); - } - }, - )) - } else { - this.item(PopupMenuItem::new("Pin").on_click( - move |_event, _window, cx| { - if let Err(error) = sidebar.update(cx, |sidebar, cx| { - sidebar.pin_room(room_id, cx); - }) { - log::error!("Failed to pin room: {error}"); - } - }, - )) - } - }, - ) + .on_click(handler) .into_any_element() } SidebarRow::Community { community } => { diff --git a/crates/workspace/src/sidebar/tree.rs b/crates/workspace/src/sidebar/tree.rs index 823722ac..eef4b17c 100644 --- a/crates/workspace/src/sidebar/tree.rs +++ b/crates/workspace/src/sidebar/tree.rs @@ -14,7 +14,6 @@ use ui::{Icon, IconName, Selectable, Sizable, StyledExt, h_flex}; #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum TreeSection { - Pins, Community, Messages, } @@ -22,7 +21,6 @@ pub enum TreeSection { impl TreeSection { pub fn label(self) -> &'static str { match self { - Self::Pins => "Pinned", Self::Community => "Community", Self::Messages => "Messages", } @@ -30,7 +28,6 @@ impl TreeSection { pub fn key(self) -> &'static str { match self { - Self::Pins => "pins", Self::Community => "community", Self::Messages => "messages", } @@ -38,7 +35,6 @@ impl TreeSection { pub fn from_key(key: &str) -> Option { match key { - "pins" => Some(Self::Pins), "community" => Some(Self::Community), "messages" => Some(Self::Messages), _ => None, @@ -48,7 +44,7 @@ impl TreeSection { pub enum SidebarRow { Section { section: TreeSection, count: usize }, - Room { room: Entity, pinned: bool }, + Room { room: Entity }, Community { community: Entity }, Hint { text: SharedString }, }