Add read-only channel notes support
Fix some bugs where ChannelNotes and ChannelChat had old cached channel instances
This commit is contained in:
parent
3853009d92
commit
0eff7c6ca9
12 changed files with 186 additions and 219 deletions
|
@ -58,6 +58,7 @@ postage.workspace = true
|
|||
serde.workspace = true
|
||||
serde_derive.workspace = true
|
||||
time.workspace = true
|
||||
smallvec.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
call = { path = "../call", features = ["test-support"] }
|
||||
|
|
|
@ -15,13 +15,14 @@ use gpui::{
|
|||
ViewContext, ViewHandle,
|
||||
};
|
||||
use project::Project;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
any::{Any, TypeId},
|
||||
sync::Arc,
|
||||
};
|
||||
use util::ResultExt;
|
||||
use workspace::{
|
||||
item::{FollowableItem, Item, ItemHandle},
|
||||
item::{FollowableItem, Item, ItemEvent, ItemHandle},
|
||||
register_followable_item,
|
||||
searchable::SearchableItemHandle,
|
||||
ItemNavHistory, Pane, SaveIntent, ViewId, Workspace, WorkspaceId,
|
||||
|
@ -140,6 +141,12 @@ impl ChannelView {
|
|||
editor.set_collaboration_hub(Box::new(ChannelBufferCollaborationHub(
|
||||
channel_buffer.clone(),
|
||||
)));
|
||||
editor.set_read_only(
|
||||
!channel_buffer
|
||||
.read(cx)
|
||||
.channel(cx)
|
||||
.is_some_and(|c| c.can_edit_notes()),
|
||||
);
|
||||
editor
|
||||
});
|
||||
let _editor_event_subscription = cx.subscribe(&editor, |_, _, e, cx| cx.emit(e.clone()));
|
||||
|
@ -157,8 +164,8 @@ impl ChannelView {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn channel(&self, cx: &AppContext) -> Arc<Channel> {
|
||||
self.channel_buffer.read(cx).channel()
|
||||
pub fn channel(&self, cx: &AppContext) -> Option<Arc<Channel>> {
|
||||
self.channel_buffer.read(cx).channel(cx)
|
||||
}
|
||||
|
||||
fn handle_channel_buffer_event(
|
||||
|
@ -172,6 +179,13 @@ impl ChannelView {
|
|||
editor.set_read_only(true);
|
||||
cx.notify();
|
||||
}),
|
||||
ChannelBufferEvent::ChannelChanged => {
|
||||
self.editor.update(cx, |editor, cx| {
|
||||
editor.set_read_only(!self.channel(cx).is_some_and(|c| c.can_edit_notes()));
|
||||
cx.emit(editor::Event::TitleChanged);
|
||||
cx.notify()
|
||||
});
|
||||
}
|
||||
ChannelBufferEvent::BufferEdited => {
|
||||
if cx.is_self_focused() || self.editor.is_focused(cx) {
|
||||
self.acknowledge_buffer_version(cx);
|
||||
|
@ -179,7 +193,7 @@ impl ChannelView {
|
|||
self.channel_store.update(cx, |store, cx| {
|
||||
let channel_buffer = self.channel_buffer.read(cx);
|
||||
store.notes_changed(
|
||||
channel_buffer.channel().id,
|
||||
channel_buffer.channel_id,
|
||||
channel_buffer.epoch(),
|
||||
&channel_buffer.buffer().read(cx).version(),
|
||||
cx,
|
||||
|
@ -187,7 +201,7 @@ impl ChannelView {
|
|||
});
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
ChannelBufferEvent::CollaboratorsChanged => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +209,7 @@ impl ChannelView {
|
|||
self.channel_store.update(cx, |store, cx| {
|
||||
let channel_buffer = self.channel_buffer.read(cx);
|
||||
store.acknowledge_notes_version(
|
||||
channel_buffer.channel().id,
|
||||
channel_buffer.channel_id,
|
||||
channel_buffer.epoch(),
|
||||
&channel_buffer.buffer().read(cx).version(),
|
||||
cx,
|
||||
|
@ -250,11 +264,17 @@ impl Item for ChannelView {
|
|||
style: &theme::Tab,
|
||||
cx: &gpui::AppContext,
|
||||
) -> AnyElement<V> {
|
||||
let channel_name = &self.channel_buffer.read(cx).channel().name;
|
||||
let label = if self.channel_buffer.read(cx).is_connected() {
|
||||
format!("#{}", channel_name)
|
||||
let label = if let Some(channel) = self.channel(cx) {
|
||||
match (
|
||||
channel.can_edit_notes(),
|
||||
self.channel_buffer.read(cx).is_connected(),
|
||||
) {
|
||||
(true, true) => format!("#{}", channel.name),
|
||||
(false, true) => format!("#{} (read-only)", channel.name),
|
||||
(_, false) => format!("#{} (disconnected)", channel.name),
|
||||
}
|
||||
} else {
|
||||
format!("#{} (disconnected)", channel_name)
|
||||
format!("channel notes (disconnected)")
|
||||
};
|
||||
Label::new(label, style.label.to_owned()).into_any()
|
||||
}
|
||||
|
@ -298,6 +318,10 @@ impl Item for ChannelView {
|
|||
fn pixel_position_of_cursor(&self, cx: &AppContext) -> Option<Vector2F> {
|
||||
self.editor.read(cx).pixel_position_of_cursor(cx)
|
||||
}
|
||||
|
||||
fn to_item_events(event: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
|
||||
editor::Editor::to_item_events(event)
|
||||
}
|
||||
}
|
||||
|
||||
impl FollowableItem for ChannelView {
|
||||
|
@ -313,7 +337,7 @@ impl FollowableItem for ChannelView {
|
|||
|
||||
Some(proto::view::Variant::ChannelView(
|
||||
proto::view::ChannelView {
|
||||
channel_id: channel_buffer.channel().id,
|
||||
channel_id: channel_buffer.channel_id,
|
||||
editor: if let Some(proto::view::Variant::Editor(proto)) =
|
||||
self.editor.read(cx).to_state_proto(cx)
|
||||
{
|
||||
|
|
|
@ -267,11 +267,15 @@ impl ChatPanel {
|
|||
|
||||
fn set_active_chat(&mut self, chat: ModelHandle<ChannelChat>, cx: &mut ViewContext<Self>) {
|
||||
if self.active_chat.as_ref().map(|e| &e.0) != Some(&chat) {
|
||||
let id = chat.read(cx).channel().id;
|
||||
let id = chat.read(cx).channel_id;
|
||||
{
|
||||
let chat = chat.read(cx);
|
||||
self.message_list.reset(chat.message_count());
|
||||
let placeholder = format!("Message #{}", chat.channel().name);
|
||||
let placeholder = if let Some(channel) = chat.channel(cx) {
|
||||
format!("Message #{}", channel.name)
|
||||
} else {
|
||||
"Message Channel".to_string()
|
||||
};
|
||||
self.input_editor.update(cx, move |editor, cx| {
|
||||
editor.set_placeholder_text(placeholder, cx);
|
||||
});
|
||||
|
@ -360,7 +364,7 @@ impl ChatPanel {
|
|||
let is_admin = self
|
||||
.channel_store
|
||||
.read(cx)
|
||||
.is_channel_admin(active_chat.channel().id);
|
||||
.is_channel_admin(active_chat.channel_id);
|
||||
let last_message = active_chat.message(ix.saturating_sub(1));
|
||||
let this_message = active_chat.message(ix);
|
||||
let is_continuation = last_message.id != this_message.id
|
||||
|
@ -645,7 +649,7 @@ impl ChatPanel {
|
|||
cx: &mut ViewContext<ChatPanel>,
|
||||
) -> Task<Result<()>> {
|
||||
if let Some((chat, _)) = &self.active_chat {
|
||||
if chat.read(cx).channel().id == selected_channel_id {
|
||||
if chat.read(cx).channel_id == selected_channel_id {
|
||||
return Task::ready(Ok(()));
|
||||
}
|
||||
}
|
||||
|
@ -664,7 +668,7 @@ impl ChatPanel {
|
|||
|
||||
fn open_notes(&mut self, _: &OpenChannelNotes, cx: &mut ViewContext<Self>) {
|
||||
if let Some((chat, _)) = &self.active_chat {
|
||||
let channel_id = chat.read(cx).channel().id;
|
||||
let channel_id = chat.read(cx).channel_id;
|
||||
if let Some(workspace) = self.workspace.upgrade(cx) {
|
||||
ChannelView::open(channel_id, workspace, cx).detach();
|
||||
}
|
||||
|
@ -673,7 +677,7 @@ impl ChatPanel {
|
|||
|
||||
fn join_call(&mut self, _: &JoinCall, cx: &mut ViewContext<Self>) {
|
||||
if let Some((chat, _)) = &self.active_chat {
|
||||
let channel_id = chat.read(cx).channel().id;
|
||||
let channel_id = chat.read(cx).channel_id;
|
||||
ActiveCall::global(cx)
|
||||
.update(cx, |call, cx| call.join_channel(channel_id, cx))
|
||||
.detach_and_log_err(cx);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue