mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
parent
8d1bca450f
commit
61a9a3a274
@ -1,4 +1,4 @@
|
|||||||
use crate::{channel_view::ChannelView, ChatPanelSettings};
|
use crate::{channel_view::ChannelView, is_channels_feature_enabled, ChatPanelSettings};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use call::ActiveCall;
|
use call::ActiveCall;
|
||||||
use channel::{ChannelChat, ChannelChatEvent, ChannelMessageId, ChannelStore};
|
use channel::{ChannelChat, ChannelChatEvent, ChannelMessageId, ChannelStore};
|
||||||
@ -612,6 +612,9 @@ impl Panel for ChatPanel {
|
|||||||
self.active = active;
|
self.active = active;
|
||||||
if active {
|
if active {
|
||||||
self.acknowledge_last_message(cx);
|
self.acknowledge_last_message(cx);
|
||||||
|
if !is_channels_feature_enabled(cx) {
|
||||||
|
cx.emit(Event::Dismissed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -620,6 +623,10 @@ impl Panel for ChatPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn icon(&self, cx: &WindowContext) -> Option<ui::IconName> {
|
fn icon(&self, cx: &WindowContext) -> Option<ui::IconName> {
|
||||||
|
if !is_channels_feature_enabled(cx) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
Some(ui::IconName::MessageBubbles).filter(|_| ChatPanelSettings::get_global(cx).button)
|
Some(ui::IconName::MessageBubbles).filter(|_| ChatPanelSettings::get_global(cx).button)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ use client::{Client, Contact, User, UserStore};
|
|||||||
use contact_finder::ContactFinder;
|
use contact_finder::ContactFinder;
|
||||||
use db::kvp::KEY_VALUE_STORE;
|
use db::kvp::KEY_VALUE_STORE;
|
||||||
use editor::{Editor, EditorElement, EditorStyle};
|
use editor::{Editor, EditorElement, EditorStyle};
|
||||||
|
use feature_flags::{ChannelsAlpha, FeatureFlagAppExt, FeatureFlagViewExt};
|
||||||
use fuzzy::{match_strings, StringMatchCandidate};
|
use fuzzy::{match_strings, StringMatchCandidate};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, canvas, div, fill, list, overlay, point, prelude::*, px, AnyElement, AppContext,
|
actions, canvas, div, fill, list, overlay, point, prelude::*, px, AnyElement, AppContext,
|
||||||
@ -277,6 +278,10 @@ impl CollabPanel {
|
|||||||
}));
|
}));
|
||||||
this.subscriptions
|
this.subscriptions
|
||||||
.push(cx.observe(&active_call, |this, _, cx| this.update_entries(true, cx)));
|
.push(cx.observe(&active_call, |this, _, cx| this.update_entries(true, cx)));
|
||||||
|
this.subscriptions
|
||||||
|
.push(cx.observe_flag::<ChannelsAlpha, _>(move |_, this, cx| {
|
||||||
|
this.update_entries(true, cx)
|
||||||
|
}));
|
||||||
this.subscriptions.push(cx.subscribe(
|
this.subscriptions.push(cx.subscribe(
|
||||||
&this.channel_store,
|
&this.channel_store,
|
||||||
|this, _channel_store, e, cx| match e {
|
|this, _channel_store, e, cx| match e {
|
||||||
@ -512,118 +517,115 @@ impl CollabPanel {
|
|||||||
|
|
||||||
let mut request_entries = Vec::new();
|
let mut request_entries = Vec::new();
|
||||||
|
|
||||||
self.entries.push(ListEntry::Header(Section::Channels));
|
if cx.has_flag::<ChannelsAlpha>() {
|
||||||
|
self.entries.push(ListEntry::Header(Section::Channels));
|
||||||
|
|
||||||
if channel_store.channel_count() > 0 || self.channel_editing_state.is_some() {
|
if channel_store.channel_count() > 0 || self.channel_editing_state.is_some() {
|
||||||
self.match_candidates.clear();
|
self.match_candidates.clear();
|
||||||
self.match_candidates
|
self.match_candidates
|
||||||
.extend(
|
.extend(channel_store.ordered_channels().enumerate().map(
|
||||||
channel_store
|
|(ix, (_, channel))| StringMatchCandidate {
|
||||||
.ordered_channels()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(ix, (_, channel))| StringMatchCandidate {
|
|
||||||
id: ix,
|
id: ix,
|
||||||
string: channel.name.clone().into(),
|
string: channel.name.clone().into(),
|
||||||
char_bag: channel.name.chars().collect(),
|
char_bag: channel.name.chars().collect(),
|
||||||
}),
|
},
|
||||||
);
|
));
|
||||||
let matches = executor.block(match_strings(
|
let matches = executor.block(match_strings(
|
||||||
&self.match_candidates,
|
&self.match_candidates,
|
||||||
&query,
|
&query,
|
||||||
true,
|
true,
|
||||||
usize::MAX,
|
usize::MAX,
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
executor.clone(),
|
executor.clone(),
|
||||||
));
|
));
|
||||||
if let Some(state) = &self.channel_editing_state {
|
if let Some(state) = &self.channel_editing_state {
|
||||||
if matches!(state, ChannelEditingState::Create { location: None, .. }) {
|
if matches!(state, ChannelEditingState::Create { location: None, .. }) {
|
||||||
self.entries.push(ListEntry::ChannelEditor { depth: 0 });
|
self.entries.push(ListEntry::ChannelEditor { depth: 0 });
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut collapse_depth = None;
|
|
||||||
for mat in matches {
|
|
||||||
let channel = channel_store.channel_at_index(mat.candidate_id).unwrap();
|
|
||||||
let depth = channel.parent_path.len();
|
|
||||||
|
|
||||||
if collapse_depth.is_none() && self.is_channel_collapsed(channel.id) {
|
|
||||||
collapse_depth = Some(depth);
|
|
||||||
} else if let Some(collapsed_depth) = collapse_depth {
|
|
||||||
if depth > collapsed_depth {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if self.is_channel_collapsed(channel.id) {
|
}
|
||||||
|
let mut collapse_depth = None;
|
||||||
|
for mat in matches {
|
||||||
|
let channel = channel_store.channel_at_index(mat.candidate_id).unwrap();
|
||||||
|
let depth = channel.parent_path.len();
|
||||||
|
|
||||||
|
if collapse_depth.is_none() && self.is_channel_collapsed(channel.id) {
|
||||||
collapse_depth = Some(depth);
|
collapse_depth = Some(depth);
|
||||||
} else {
|
} else if let Some(collapsed_depth) = collapse_depth {
|
||||||
collapse_depth = None;
|
if depth > collapsed_depth {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if self.is_channel_collapsed(channel.id) {
|
||||||
|
collapse_depth = Some(depth);
|
||||||
|
} else {
|
||||||
|
collapse_depth = None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let has_children = channel_store
|
let has_children = channel_store
|
||||||
.channel_at_index(mat.candidate_id + 1)
|
.channel_at_index(mat.candidate_id + 1)
|
||||||
.map_or(false, |next_channel| {
|
.map_or(false, |next_channel| {
|
||||||
next_channel.parent_path.ends_with(&[channel.id])
|
next_channel.parent_path.ends_with(&[channel.id])
|
||||||
});
|
});
|
||||||
|
|
||||||
match &self.channel_editing_state {
|
match &self.channel_editing_state {
|
||||||
Some(ChannelEditingState::Create {
|
Some(ChannelEditingState::Create {
|
||||||
location: parent_id,
|
location: parent_id,
|
||||||
..
|
..
|
||||||
}) if *parent_id == Some(channel.id) => {
|
}) if *parent_id == Some(channel.id) => {
|
||||||
self.entries.push(ListEntry::Channel {
|
self.entries.push(ListEntry::Channel {
|
||||||
channel: channel.clone(),
|
channel: channel.clone(),
|
||||||
depth,
|
depth,
|
||||||
has_children: false,
|
has_children: false,
|
||||||
});
|
});
|
||||||
self.entries
|
self.entries
|
||||||
.push(ListEntry::ChannelEditor { depth: depth + 1 });
|
.push(ListEntry::ChannelEditor { depth: depth + 1 });
|
||||||
}
|
}
|
||||||
Some(ChannelEditingState::Rename {
|
Some(ChannelEditingState::Rename {
|
||||||
location: parent_id,
|
location: parent_id,
|
||||||
..
|
..
|
||||||
}) if parent_id == &channel.id => {
|
}) if parent_id == &channel.id => {
|
||||||
self.entries.push(ListEntry::ChannelEditor { depth });
|
self.entries.push(ListEntry::ChannelEditor { depth });
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
self.entries.push(ListEntry::Channel {
|
self.entries.push(ListEntry::Channel {
|
||||||
channel: channel.clone(),
|
channel: channel.clone(),
|
||||||
depth,
|
depth,
|
||||||
has_children,
|
has_children,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let channel_invites = channel_store.channel_invitations();
|
let channel_invites = channel_store.channel_invitations();
|
||||||
if !channel_invites.is_empty() {
|
if !channel_invites.is_empty() {
|
||||||
self.match_candidates.clear();
|
self.match_candidates.clear();
|
||||||
self.match_candidates
|
self.match_candidates
|
||||||
.extend(channel_invites.iter().enumerate().map(|(ix, channel)| {
|
.extend(channel_invites.iter().enumerate().map(|(ix, channel)| {
|
||||||
StringMatchCandidate {
|
StringMatchCandidate {
|
||||||
id: ix,
|
id: ix,
|
||||||
string: channel.name.clone().into(),
|
string: channel.name.clone().into(),
|
||||||
char_bag: channel.name.chars().collect(),
|
char_bag: channel.name.chars().collect(),
|
||||||
}
|
}
|
||||||
|
}));
|
||||||
|
let matches = executor.block(match_strings(
|
||||||
|
&self.match_candidates,
|
||||||
|
&query,
|
||||||
|
true,
|
||||||
|
usize::MAX,
|
||||||
|
&Default::default(),
|
||||||
|
executor.clone(),
|
||||||
|
));
|
||||||
|
request_entries.extend(matches.iter().map(|mat| {
|
||||||
|
ListEntry::ChannelInvite(channel_invites[mat.candidate_id].clone())
|
||||||
}));
|
}));
|
||||||
let matches = executor.block(match_strings(
|
|
||||||
&self.match_candidates,
|
|
||||||
&query,
|
|
||||||
true,
|
|
||||||
usize::MAX,
|
|
||||||
&Default::default(),
|
|
||||||
executor.clone(),
|
|
||||||
));
|
|
||||||
request_entries.extend(
|
|
||||||
matches
|
|
||||||
.iter()
|
|
||||||
.map(|mat| ListEntry::ChannelInvite(channel_invites[mat.candidate_id].clone())),
|
|
||||||
);
|
|
||||||
|
|
||||||
if !request_entries.is_empty() {
|
if !request_entries.is_empty() {
|
||||||
self.entries
|
self.entries
|
||||||
.push(ListEntry::Header(Section::ChannelInvites));
|
.push(ListEntry::Header(Section::ChannelInvites));
|
||||||
if !self.collapsed_sections.contains(&Section::ChannelInvites) {
|
if !self.collapsed_sections.contains(&Section::ChannelInvites) {
|
||||||
self.entries.append(&mut request_entries);
|
self.entries.append(&mut request_entries);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ use std::{rc::Rc, sync::Arc};
|
|||||||
use call::{report_call_event_for_room, ActiveCall, Room};
|
use call::{report_call_event_for_room, ActiveCall, Room};
|
||||||
pub use collab_panel::CollabPanel;
|
pub use collab_panel::CollabPanel;
|
||||||
pub use collab_titlebar_item::CollabTitlebarItem;
|
pub use collab_titlebar_item::CollabTitlebarItem;
|
||||||
|
use feature_flags::{ChannelsAlpha, FeatureFlagAppExt};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, point, AppContext, GlobalPixels, Pixels, PlatformDisplay, Size, Task, WindowBounds,
|
actions, point, AppContext, GlobalPixels, Pixels, PlatformDisplay, Size, Task, WindowBounds,
|
||||||
WindowKind, WindowOptions,
|
WindowKind, WindowOptions,
|
||||||
@ -158,3 +159,7 @@ fn notification_window_options(
|
|||||||
// .with_style(container)
|
// .with_style(container)
|
||||||
// .into_any()
|
// .into_any()
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
fn is_channels_feature_enabled(cx: &gpui::WindowContext<'_>) -> bool {
|
||||||
|
cx.is_staff() || cx.has_flag::<ChannelsAlpha>()
|
||||||
|
}
|
||||||
|
@ -16,6 +16,12 @@ pub trait FeatureFlag {
|
|||||||
const NAME: &'static str;
|
const NAME: &'static str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub enum ChannelsAlpha {}
|
||||||
|
|
||||||
|
impl FeatureFlag for ChannelsAlpha {
|
||||||
|
const NAME: &'static str = "channels_alpha";
|
||||||
|
}
|
||||||
|
|
||||||
pub trait FeatureFlagViewExt<V: 'static> {
|
pub trait FeatureFlagViewExt<V: 'static> {
|
||||||
fn observe_flag<T: FeatureFlag, F>(&mut self, callback: F) -> Subscription
|
fn observe_flag<T: FeatureFlag, F>(&mut self, callback: F) -> Subscription
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user