remove pin
This commit is contained in:
@@ -46,7 +46,6 @@ setting_accessors! {
|
||||
pub nip4e: bool,
|
||||
pub trusted_relays: Vec<String>,
|
||||
pub file_server: Url,
|
||||
pub pinned_rooms: Vec<u64>,
|
||||
pub expanded_sections: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
@@ -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<u64>,
|
||||
|
||||
/// Expanded sidebar tree sections; `None` means the default sections
|
||||
#[serde(default)]
|
||||
pub expanded_sections: Option<Vec<String>>,
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<TreeSection>,
|
||||
/// Pinned room ids, in pin order
|
||||
pinned_rooms: Vec<u64>,
|
||||
_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<Self>) {
|
||||
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<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> {
|
||||
let chat = ChatRegistry::global(cx);
|
||||
let chat = chat.read(cx);
|
||||
|
||||
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 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 } => {
|
||||
|
||||
@@ -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<Self> {
|
||||
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<Room>, pinned: bool },
|
||||
Room { room: Entity<Room> },
|
||||
Community { community: Entity<Community> },
|
||||
Hint { text: SharedString },
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user