remove pin

This commit is contained in:
2026-09-19 18:34:39 +07:00
parent bd8bff4693
commit 9e47882fb1
3 changed files with 10 additions and 107 deletions
-6
View File
@@ -46,7 +46,6 @@ setting_accessors! {
pub nip4e: bool, pub nip4e: bool,
pub trusted_relays: Vec<String>, pub trusted_relays: Vec<String>,
pub file_server: Url, pub file_server: Url,
pub pinned_rooms: Vec<u64>,
pub expanded_sections: Option<Vec<String>>, pub expanded_sections: Option<Vec<String>>,
} }
@@ -133,10 +132,6 @@ pub struct Settings {
/// Server for blossom media attachments /// Server for blossom media attachments
pub file_server: Url, pub file_server: Url,
/// Pinned sidebar room ids, in pin order
#[serde(default)]
pub pinned_rooms: Vec<u64>,
/// Expanded sidebar tree sections; `None` means the default sections /// Expanded sidebar tree sections; `None` means the default sections
#[serde(default)] #[serde(default)]
pub expanded_sections: Option<Vec<String>>, pub expanded_sections: Option<Vec<String>>,
@@ -152,7 +147,6 @@ impl Default for Settings {
nip4e: false, nip4e: false,
trusted_relays: vec![], trusted_relays: vec![],
file_server: Url::parse(DEFAULT_FILE_SERVER).unwrap(), file_server: Url::parse(DEFAULT_FILE_SERVER).unwrap(),
pinned_rooms: vec![],
expanded_sections: None, expanded_sections: None,
} }
} }
+9 -96
View File
@@ -3,13 +3,13 @@ use std::ops::Range;
use std::rc::Rc; use std::rc::Rc;
use auto_update::AutoUpdater; use auto_update::AutoUpdater;
use chat::{ChatEvent, ChatRegistry, Room, RoomKind}; use chat::{ChatEvent, ChatRegistry, RoomKind};
use common::TimestampExt; use common::TimestampExt;
use community::{CommunityEvent, CommunityRegistry}; use community::{CommunityEvent, CommunityRegistry};
use gpui::prelude::FluentBuilder; use gpui::prelude::FluentBuilder;
use gpui::{ use gpui::{
AnyElement, App, Context, ElementId, Entity, EventEmitter, FocusHandle, Focusable, AnyElement, App, Context, ElementId, EventEmitter, FocusHandle, Focusable, InteractiveElement,
InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, Subscription, IntoElement, ParentElement, Render, SharedString, Styled, Subscription,
UniformListScrollHandle, Window, div, px, retain_all, uniform_list, UniformListScrollHandle, Window, div, px, retain_all, uniform_list,
}; };
use person::PersonRegistry; use person::PersonRegistry;
@@ -21,7 +21,7 @@ use ui::avatar::Avatar;
use ui::button::{Button, ButtonVariants}; use ui::button::{Button, ButtonVariants};
use ui::dock::{ClosePanel, Panel, PanelEvent}; use ui::dock::{ClosePanel, Panel, PanelEvent};
use ui::indicator::Indicator; use ui::indicator::Indicator;
use ui::menu::{ContextMenu, DropdownMenu, PopupMenuItem}; use ui::menu::{DropdownMenu, PopupMenuItem};
use ui::modal::ModalButtonProps; use ui::modal::ModalButtonProps;
use ui::nav_item::NavItem; use ui::nav_item::NavItem;
use ui::scroll::Scrollbar; use ui::scroll::Scrollbar;
@@ -45,8 +45,6 @@ pub struct Sidebar {
new_requests: bool, new_requests: bool,
/// Expanded tree sections /// Expanded tree sections
expanded: BTreeSet<TreeSection>, expanded: BTreeSet<TreeSection>,
/// Pinned room ids, in pin order
pinned_rooms: Vec<u64>,
_subscriptions: SmallVec<[Subscription; 2]>, _subscriptions: SmallVec<[Subscription; 2]>,
} }
@@ -84,7 +82,6 @@ impl Sidebar {
scroll_handle: UniformListScrollHandle::new(), scroll_handle: UniformListScrollHandle::new(),
new_requests: false, new_requests: false,
expanded: load_expanded(cx), expanded: load_expanded(cx),
pinned_rooms: AppSettings::get_pinned_rooms(cx),
_subscriptions: subscriptions, _subscriptions: subscriptions,
} }
} }
@@ -103,14 +100,10 @@ impl Sidebar {
} }
fn restore_state(&mut self, cx: &mut Context<Self>) { fn restore_state(&mut self, cx: &mut Context<Self>) {
let pinned_rooms = AppSettings::get_pinned_rooms(cx);
let expanded = load_expanded(cx); let expanded = load_expanded(cx);
if self.expanded == expanded {
if self.pinned_rooms == pinned_rooms && self.expanded == expanded {
return; return;
} }
self.pinned_rooms = pinned_rooms;
self.expanded = expanded; self.expanded = expanded;
cx.notify(); cx.notify();
} }
@@ -124,56 +117,12 @@ impl Sidebar {
AppSettings::update_expanded_sections(Some(keys), cx); AppSettings::update_expanded_sections(Some(keys), cx);
} }
fn pin_room(&mut self, room_id: u64, cx: &mut Context<Self>) {
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>) {
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<SidebarRow> { fn tree_rows(&self, cx: &App) -> Vec<SidebarRow> {
let chat = ChatRegistry::global(cx); let chat = ChatRegistry::global(cx);
let chat = chat.read(cx); let chat = chat.read(cx);
let mut rows = Vec::new(); let mut rows = Vec::new();
let pinned: Vec<Entity<Room>> = 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 registry = CommunityRegistry::global(cx);
let communities = registry.read(cx).communities(); let communities = registry.read(cx).communities();
@@ -209,10 +158,7 @@ impl Sidebar {
text: "No conversations yet".into(), text: "No conversations yet".into(),
}); });
} else { } else {
rows.extend(messages.into_iter().map(|room| { rows.extend(messages.into_iter().map(|room| SidebarRow::Room { room }));
let pinned = self.is_pinned(room.read(cx).id);
SidebarRow::Room { room, pinned }
}));
} }
} }
@@ -252,9 +198,7 @@ impl Sidebar {
})) }))
.into_any_element() .into_any_element()
} }
SidebarRow::Room { room, pinned } => { SidebarRow::Room { room } => {
let pinned = *pinned;
let room_id = room.read(cx).id;
let public_key = room.read(cx).display_member(cx).public_key(); let public_key = room.read(cx).display_member(cx).public_key();
let name = room.read(cx).display_name(cx); let name = room.read(cx).display_name(cx);
let picture = room.read(cx).display_image(cx); let picture = room.read(cx).display_image(cx);
@@ -262,7 +206,6 @@ impl Sidebar {
let kind = room.read(cx).kind; let kind = room.read(cx).kind;
let created_at = room.read(cx).created_at.to_ago(); let created_at = room.read(cx).created_at.to_ago();
let room_clone = room.clone(); let room_clone = room.clone();
let sidebar = cx.entity().downgrade();
let handler = cx.listener(move |_this, _event, window, cx| { let handler = cx.listener(move |_this, _event, window, cx| {
ChatRegistry::global(cx).update(cx, |chat, 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), ElementId::NamedInteger("tree-row".into(), index as u64),
TreeRowKind::Room, TreeRowKind::Room,
name, name,
@@ -296,37 +239,7 @@ impl Sidebar {
.avatar(seed) .avatar(seed)
.picture(picture) .picture(picture)
.created_at(created_at) .created_at(created_at)
.on_click(handler); .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}");
}
},
))
}
},
)
.into_any_element() .into_any_element()
} }
SidebarRow::Community { community } => { SidebarRow::Community { community } => {
+1 -5
View File
@@ -14,7 +14,6 @@ use ui::{Icon, IconName, Selectable, Sizable, StyledExt, h_flex};
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum TreeSection { pub enum TreeSection {
Pins,
Community, Community,
Messages, Messages,
} }
@@ -22,7 +21,6 @@ pub enum TreeSection {
impl TreeSection { impl TreeSection {
pub fn label(self) -> &'static str { pub fn label(self) -> &'static str {
match self { match self {
Self::Pins => "Pinned",
Self::Community => "Community", Self::Community => "Community",
Self::Messages => "Messages", Self::Messages => "Messages",
} }
@@ -30,7 +28,6 @@ impl TreeSection {
pub fn key(self) -> &'static str { pub fn key(self) -> &'static str {
match self { match self {
Self::Pins => "pins",
Self::Community => "community", Self::Community => "community",
Self::Messages => "messages", Self::Messages => "messages",
} }
@@ -38,7 +35,6 @@ impl TreeSection {
pub fn from_key(key: &str) -> Option<Self> { pub fn from_key(key: &str) -> Option<Self> {
match key { match key {
"pins" => Some(Self::Pins),
"community" => Some(Self::Community), "community" => Some(Self::Community),
"messages" => Some(Self::Messages), "messages" => Some(Self::Messages),
_ => None, _ => None,
@@ -48,7 +44,7 @@ impl TreeSection {
pub enum SidebarRow { pub enum SidebarRow {
Section { section: TreeSection, count: usize }, Section { section: TreeSection, count: usize },
Room { room: Entity<Room>, pinned: bool }, Room { room: Entity<Room> },
Community { community: Entity<Community> }, Community { community: Entity<Community> },
Hint { text: SharedString }, Hint { text: SharedString },
} }