feat(chat-list): filter chats like the new Teams chat list
- Funnel toggle in the Chats header opens "Filter by person or chat name" - Pills Unread, @Mentions, Chats, plus Meeting chats and Muted behind More filters - Teams rules: state pills AND, category pills OR, conflicting pills disabled - Sections kept, empty ones dropped, selected chat stays, "We didn't find any matches." - Ctrl+Shift+F, Ctrl+Alt+U/C/B/Q/Z shortcuts, demo chat mention, layout_guard screen Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -0,0 +1,376 @@
1
use std::collections::HashSet;
2
3
use store::ChatRecord;
4
5
use crate::activity::{Entry, Kind};
6
use crate::app_state::chat_title;
7
use crate::sidebar_model::{MUTED_ID, OTHERS_ID, Section, SectionInput, build_sections};
8
9
pub const FILTER_PLACEHOLDER: &str = "Filter by person or chat name";
10
pub const NO_MATCHES: &str = "We didn't find any matches.";
11
pub const CLEAR_FILTERS: &str = "Clear filters";
12
pub const CLEAR_FILTER_TEXT: &str = "Clear filter text";
13
pub const SHOW_FILTER_TEXT: &str = "Show filter text box";
14
pub const CLOSE_FILTER_TEXT: &str = "Close filter text box";
15
pub const MORE_FILTERS: &str = "More filters";
16
pub const FEWER_FILTERS: &str = "Fewer filters";
17
const MEETING_KIND: &str = "meeting";
18
19
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
20
pub enum ChatFilterPill {
21
Unread,
22
Mentions,
23
Chats,
24
Meetings,
25
Muted,
26
}
27
28
impl ChatFilterPill {
29
pub const PRIMARY: [ChatFilterPill; 3] = [
30
ChatFilterPill::Unread,
31
ChatFilterPill::Mentions,
32
ChatFilterPill::Chats,
33
];
34
pub const OVERFLOW: [ChatFilterPill; 2] = [ChatFilterPill::Meetings, ChatFilterPill::Muted];
35
36
pub fn label(self) -> &'static str {
37
match self {
38
ChatFilterPill::Unread => "Unread",
39
ChatFilterPill::Mentions => "@Mentions",
40
ChatFilterPill::Chats => "Chats",
41
ChatFilterPill::Meetings => "Meeting chats",
42
ChatFilterPill::Muted => "Muted",
43
}
44
}
45
46
fn is_category(self) -> bool {
47
matches!(self, ChatFilterPill::Chats | ChatFilterPill::Meetings)
48
}
49
50
fn excludes(self) -> Option<ChatFilterPill> {
51
match self {
52
ChatFilterPill::Mentions => Some(ChatFilterPill::Muted),
53
ChatFilterPill::Muted => Some(ChatFilterPill::Mentions),
54
ChatFilterPill::Chats => Some(ChatFilterPill::Meetings),
55
ChatFilterPill::Meetings => Some(ChatFilterPill::Chats),
56
ChatFilterPill::Unread => None,
57
}
58
}
59
60
fn admits(self, chat: &ChatRecord, mentioned: &HashSet<String>) -> bool {
61
let meeting = chat.kind.eq_ignore_ascii_case(MEETING_KIND);
62
match self {
63
ChatFilterPill::Unread => chat.unread,
64
ChatFilterPill::Mentions => mentioned.contains(&chat.id),
65
ChatFilterPill::Chats => !meeting,
66
ChatFilterPill::Meetings => meeting,
67
ChatFilterPill::Muted => chat.muted,
68
}
69
}
70
}
71
72
#[derive(Debug, Clone, Default, PartialEq, Eq)]
73
pub struct ChatFilter {
74
pub text: String,
75
pub pills: Vec<ChatFilterPill>,
76
}
77
78
impl ChatFilter {
79
pub fn is_active(&self) -> bool {
80
!self.text.trim().is_empty() || !self.pills.is_empty()
81
}
82
83
pub fn has(&self, pill: ChatFilterPill) -> bool {
84
self.pills.contains(&pill)
85
}
86
87
pub fn is_disabled(&self, pill: ChatFilterPill) -> bool {
88
!self.has(pill)
89
&& self
90
.pills
91
.iter()
92
.any(|active| active.excludes() == Some(pill))
93
}
94
95
pub fn toggle(&mut self, pill: ChatFilterPill) -> bool {
96
if self.has(pill) {
97
self.pills.retain(|active| *active != pill);
98
return true;
99
}
100
if self.is_disabled(pill) {
101
return false;
102
}
103
self.pills.push(pill);
104
true
105
}
106
107
pub fn clear(&mut self) {
108
self.text.clear();
109
self.pills.clear();
110
}
111
112
pub fn admits(&self, chat: &ChatRecord, mentioned: &HashSet<String>) -> bool {
113
if !name_matches(&self.text, &chat_title(chat)) {
114
return false;
115
}
116
let states_hold = self
117
.pills
118
.iter()
119
.filter(|pill| !pill.is_category())
120
.all(|pill| pill.admits(chat, mentioned));
121
let mut categories = self
122
.pills
123
.iter()
124
.filter(|pill| pill.is_category())
125
.peekable();
126
let category_holds =
127
categories.peek().is_none() || categories.any(|pill| pill.admits(chat, mentioned));
128
states_hold && category_holds
129
}
130
}
131
132
pub fn mentioned_conversations<'a>(entries: impl Iterator<Item = &'a Entry>) -> HashSet<String> {
133
entries
134
.filter(|entry| entry.kind == Kind::Mention)
135
.map(|entry| entry.conversation_id.clone())
136
.collect()
137
}
138
139
fn words(text: &str) -> Vec<String> {
140
text.to_lowercase()
141
.split(|character: char| character.is_whitespace() || character == ',')
142
.filter(|word| !word.is_empty())
143
.map(str::to_owned)
144
.collect()
145
}
146
147
pub fn name_matches(query: &str, title: &str) -> bool {
148
let query = query.trim().to_lowercase();
149
if query.is_empty() {
150
return true;
151
}
152
let title_lower = title.to_lowercase();
153
if title_lower.contains(&query) {
154
return true;
155
}
156
let title_words = words(&title_lower);
157
words(&query).iter().all(|word| {
158
title_words
159
.iter()
160
.any(|title_word| title_word.starts_with(word.as_str()))
161
})
162
}
163
164
pub fn filtered_sections(
165
input: &SectionInput<'_>,
166
filter: &ChatFilter,
167
mentioned: &HashSet<String>,
168
selected_id: Option<&str>,
169
) -> Vec<Section> {
170
let chats: Vec<ChatRecord> = input
171
.chats
172
.iter()
173
.filter(|chat| Some(chat.id.as_str()) == selected_id || filter.admits(chat, mentioned))
174
.cloned()
175
.collect();
176
let every_list: HashSet<String> = input
177
.directory
178
.folders
179
.iter()
180
.map(|folder| folder.id.clone())
181
.chain([MUTED_ID.to_owned(), OTHERS_ID.to_owned()])
182
.collect();
183
let unpaged = SectionInput {
184
chats: &chats,
185
expanded_lists: &every_list,
186
..*input
187
};
188
build_sections(&unpaged)
189
.into_iter()
190
.filter(|section| !section.items.is_empty())
191
.map(|section| Section {
192
hidden_count: 0,
193
list_expanded: false,
194
show_empty_hint: false,
195
..section
196
})
197
.collect()
198
}
199
200
pub fn has_no_matches(sections: &[Section], selected_id: Option<&str>) -> bool {
201
sections
202
.iter()
203
.flat_map(|section| §ion.items)
204
.all(|item| Some(item.id.as_str()) == selected_id)
205
}
206
207
#[cfg(test)]
208
mod tests {
209
use chrono::{FixedOffset, TimeZone, Utc};
210
211
use super::*;
212
use crate::data::{Directory, FolderInfo, FolderKind};
213
use crate::typing::TypingState;
214
use teams_core::ChatSection;
215
216
fn chat(id: &str, title: &str, kind: &str) -> ChatRecord {
217
ChatRecord {
218
id: id.into(),
219
kind: kind.into(),
220
title: title.into(),
221
..Default::default()
222
}
223
}
224
225
fn admitted(filter: &ChatFilter, chats: &[ChatRecord], mentioned: &[&str]) -> Vec<String> {
226
let mentioned: HashSet<String> = mentioned.iter().map(|id| (*id).to_owned()).collect();
227
chats
228
.iter()
229
.filter(|chat| filter.admits(chat, &mentioned))
230
.map(|chat| chat.id.clone())
231
.collect()
232
}
233
234
#[test]
235
fn name_filter_matches_a_substring_or_every_word_prefix_like_teams() {
236
assert!(name_matches("", "Anything"));
237
assert!(name_matches("lind", "Mara Lindqvist"));
238
assert!(name_matches("ma li", "Mara Lindqvist"));
239
assert!(name_matches("LI, MA", "Mara Lindqvist"));
240
assert!(!name_matches("ma xo", "Mara Lindqvist"));
241
}
242
243
#[test]
244
fn state_pills_must_all_hold_and_category_pills_need_one() {
245
let chats = [
246
ChatRecord {
247
unread: true,
248
..chat("unread", "Unread chat", "group")
249
},
250
ChatRecord {
251
unread: true,
252
..chat("meeting", "Standup", "meeting")
253
},
254
ChatRecord {
255
muted: true,
256
..chat("muted", "Muted chat", "group")
257
},
258
chat("plain", "Plain chat", "oneOnOne"),
259
];
260
let mut filter = ChatFilter::default();
261
assert_eq!(admitted(&filter, &chats, &[]).len(), 4);
262
filter.toggle(ChatFilterPill::Unread);
263
assert_eq!(admitted(&filter, &chats, &[]), ["unread", "meeting"]);
264
filter.toggle(ChatFilterPill::Meetings);
265
assert_eq!(admitted(&filter, &chats, &[]), ["meeting"]);
266
filter.toggle(ChatFilterPill::Unread);
267
filter.toggle(ChatFilterPill::Meetings);
268
filter.toggle(ChatFilterPill::Chats);
269
assert_eq!(admitted(&filter, &chats, &[]), ["unread", "muted", "plain"]);
270
filter.toggle(ChatFilterPill::Mentions);
271
assert_eq!(admitted(&filter, &chats, &["plain"]), ["plain"]);
272
}
273
274
#[test]
275
fn exclusive_pills_disable_each_other() {
276
let mut filter = ChatFilter::default();
277
assert!(filter.toggle(ChatFilterPill::Chats));
278
assert!(filter.is_disabled(ChatFilterPill::Meetings));
279
assert!(!filter.toggle(ChatFilterPill::Meetings));
280
assert!(filter.toggle(ChatFilterPill::Muted));
281
assert!(filter.is_disabled(ChatFilterPill::Mentions));
282
assert!(!filter.is_disabled(ChatFilterPill::Unread));
283
assert!(filter.toggle(ChatFilterPill::Chats));
284
assert!(!filter.is_disabled(ChatFilterPill::Meetings));
285
filter.text = "x".into();
286
assert!(filter.is_active());
287
filter.clear();
288
assert!(!filter.is_active());
289
}
290
291
#[test]
292
fn text_combines_with_pills() {
293
let chats = [
294
ChatRecord {
295
unread: true,
296
..chat("a", "Release crew", "group")
297
},
298
chat("b", "Release notes", "group"),
299
];
300
let filter = ChatFilter {
301
text: "rel".into(),
302
pills: vec![ChatFilterPill::Unread],
303
};
304
assert_eq!(admitted(&filter, &chats, &[]), ["a"]);
305
}
306
307
static NO_TYPING: std::sync::LazyLock<TypingState> =
308
std::sync::LazyLock::new(TypingState::default);
309
310
#[test]
311
fn filtered_sections_keep_sections_drop_empty_ones_and_unpage_muted() {
312
let mut chats = vec![
313
chat("fav", "Favorite release", "group"),
314
chat("other", "Other release", "group"),
315
chat("quiet", "Quiet", "group"),
316
];
317
chats.extend((0..7).map(|index| ChatRecord {
318
muted: true,
319
..chat(
320
&format!("m{index}"),
321
&format!("Muted release {index}"),
322
"group",
323
)
324
}));
325
let mut directory = Directory {
326
folders: vec![
327
FolderInfo {
328
id: "favorites".into(),
329
name: "Favorites".into(),
330
kind: FolderKind::Favorites,
331
expanded: None,
332
conversation_ids: vec!["fav".into()],
333
},
334
FolderInfo {
335
id: "empty".into(),
336
name: "Empty".into(),
337
kind: FolderKind::UserCreated,
338
expanded: None,
339
conversation_ids: Vec::new(),
340
},
341
],
342
..Default::default()
343
};
344
directory.section_settings.set(ChatSection::Muted, true);
345
let collapsed = HashSet::new();
346
let expanded = HashSet::new();
347
let input = SectionInput {
348
chats: &chats,
349
directory: &directory,
350
collapsed: &collapsed,
351
expanded_lists: &expanded,
352
typing: &NO_TYPING,
353
now: Utc.with_ymd_and_hms(2026, 10, 17, 12, 0, 0).unwrap(),
354
offset: FixedOffset::east_opt(0).unwrap(),
355
};
356
let filter = ChatFilter {
357
text: "release".into(),
358
pills: Vec::new(),
359
};
360
let sections = filtered_sections(&input, &filter, &HashSet::new(), None);
361
let names: Vec<(&str, usize)> = sections
362
.iter()
363
.map(|section| (section.id.as_str(), section.items.len()))
364
.collect();
365
assert_eq!(names, [("favorites", 1), (OTHERS_ID, 1), (MUTED_ID, 7)]);
366
assert!(sections.iter().all(|section| section.hidden_count == 0
367
&& !section.list_expanded
368
&& !section.show_empty_hint));
369
let with_selection = filtered_sections(&input, &filter, &HashSet::new(), Some("quiet"));
370
assert!(
371
with_selection
372
.iter()
373
.any(|section| section.items.iter().any(|item| item.id == "quiet"))
374
);
375
}
376
}
@@ -0,0 +1,376 @@1
use std::collections::HashSet;2
3
use store::ChatRecord;4
5
use crate::activity::{Entry, Kind};6
use crate::app_state::chat_title;7
use crate::sidebar_model::{MUTED_ID, OTHERS_ID, Section, SectionInput, build_sections};8
9
pub const FILTER_PLACEHOLDER: &str = "Filter by person or chat name";10
pub const NO_MATCHES: &str = "We didn't find any matches.";11
pub const CLEAR_FILTERS: &str = "Clear filters";12
pub const CLEAR_FILTER_TEXT: &str = "Clear filter text";13
pub const SHOW_FILTER_TEXT: &str = "Show filter text box";14
pub const CLOSE_FILTER_TEXT: &str = "Close filter text box";15
pub const MORE_FILTERS: &str = "More filters";16
pub const FEWER_FILTERS: &str = "Fewer filters";17
const MEETING_KIND: &str = "meeting";18
19
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]20
pub enum ChatFilterPill {21
Unread,22
Mentions,23
Chats,24
Meetings,25
Muted,26
}27
28
impl ChatFilterPill {29
pub const PRIMARY: [ChatFilterPill; 3] = [30
ChatFilterPill::Unread,31
ChatFilterPill::Mentions,32
ChatFilterPill::Chats,33
];34
pub const OVERFLOW: [ChatFilterPill; 2] = [ChatFilterPill::Meetings, ChatFilterPill::Muted];35
36
pub fn label(self) -> &'static str {37
match self {38
ChatFilterPill::Unread => "Unread",39
ChatFilterPill::Mentions => "@Mentions",40
ChatFilterPill::Chats => "Chats",41
ChatFilterPill::Meetings => "Meeting chats",42
ChatFilterPill::Muted => "Muted",43
}44
}45
46
fn is_category(self) -> bool {47
matches!(self, ChatFilterPill::Chats | ChatFilterPill::Meetings)48
}49
50
fn excludes(self) -> Option<ChatFilterPill> {51
match self {52
ChatFilterPill::Mentions => Some(ChatFilterPill::Muted),53
ChatFilterPill::Muted => Some(ChatFilterPill::Mentions),54
ChatFilterPill::Chats => Some(ChatFilterPill::Meetings),55
ChatFilterPill::Meetings => Some(ChatFilterPill::Chats),56
ChatFilterPill::Unread => None,57
}58
}59
60
fn admits(self, chat: &ChatRecord, mentioned: &HashSet<String>) -> bool {61
let meeting = chat.kind.eq_ignore_ascii_case(MEETING_KIND);62
match self {63
ChatFilterPill::Unread => chat.unread,64
ChatFilterPill::Mentions => mentioned.contains(&chat.id),65
ChatFilterPill::Chats => !meeting,66
ChatFilterPill::Meetings => meeting,67
ChatFilterPill::Muted => chat.muted,68
}69
}70
}71
72
#[derive(Debug, Clone, Default, PartialEq, Eq)]73
pub struct ChatFilter {74
pub text: String,75
pub pills: Vec<ChatFilterPill>,76
}77
78
impl ChatFilter {79
pub fn is_active(&self) -> bool {80
!self.text.trim().is_empty() || !self.pills.is_empty()81
}82
83
pub fn has(&self, pill: ChatFilterPill) -> bool {84
self.pills.contains(&pill)85
}86
87
pub fn is_disabled(&self, pill: ChatFilterPill) -> bool {88
!self.has(pill)89
&& self90
.pills91
.iter()92
.any(|active| active.excludes() == Some(pill))93
}94
95
pub fn toggle(&mut self, pill: ChatFilterPill) -> bool {96
if self.has(pill) {97
self.pills.retain(|active| *active != pill);98
return true;99
}100
if self.is_disabled(pill) {101
return false;102
}103
self.pills.push(pill);104
true105
}106
107
pub fn clear(&mut self) {108
self.text.clear();109
self.pills.clear();110
}111
112
pub fn admits(&self, chat: &ChatRecord, mentioned: &HashSet<String>) -> bool {113
if !name_matches(&self.text, &chat_title(chat)) {114
return false;115
}116
let states_hold = self117
.pills118
.iter()119
.filter(|pill| !pill.is_category())120
.all(|pill| pill.admits(chat, mentioned));121
let mut categories = self122
.pills123
.iter()124
.filter(|pill| pill.is_category())125
.peekable();126
let category_holds =127
categories.peek().is_none() || categories.any(|pill| pill.admits(chat, mentioned));128
states_hold && category_holds129
}130
}131
132
pub fn mentioned_conversations<'a>(entries: impl Iterator<Item = &'a Entry>) -> HashSet<String> {133
entries134
.filter(|entry| entry.kind == Kind::Mention)135
.map(|entry| entry.conversation_id.clone())136
.collect()137
}138
139
fn words(text: &str) -> Vec<String> {140
text.to_lowercase()141
.split(|character: char| character.is_whitespace() || character == ',')142
.filter(|word| !word.is_empty())143
.map(str::to_owned)144
.collect()145
}146
147
pub fn name_matches(query: &str, title: &str) -> bool {148
let query = query.trim().to_lowercase();149
if query.is_empty() {150
return true;151
}152
let title_lower = title.to_lowercase();153
if title_lower.contains(&query) {154
return true;155
}156
let title_words = words(&title_lower);157
words(&query).iter().all(|word| {158
title_words159
.iter()160
.any(|title_word| title_word.starts_with(word.as_str()))161
})162
}163
164
pub fn filtered_sections(165
input: &SectionInput<'_>,166
filter: &ChatFilter,167
mentioned: &HashSet<String>,168
selected_id: Option<&str>,169
) -> Vec<Section> {170
let chats: Vec<ChatRecord> = input171
.chats172
.iter()173
.filter(|chat| Some(chat.id.as_str()) == selected_id || filter.admits(chat, mentioned))174
.cloned()175
.collect();176
let every_list: HashSet<String> = input177
.directory178
.folders179
.iter()180
.map(|folder| folder.id.clone())181
.chain([MUTED_ID.to_owned(), OTHERS_ID.to_owned()])182
.collect();183
let unpaged = SectionInput {184
chats: &chats,185
expanded_lists: &every_list,186
..*input187
};188
build_sections(&unpaged)189
.into_iter()190
.filter(|section| !section.items.is_empty())191
.map(|section| Section {192
hidden_count: 0,193
list_expanded: false,194
show_empty_hint: false,195
..section196
})197
.collect()198
}199
200
pub fn has_no_matches(sections: &[Section], selected_id: Option<&str>) -> bool {201
sections202
.iter()203
.flat_map(|section| §ion.items)204
.all(|item| Some(item.id.as_str()) == selected_id)205
}206
207
#[cfg(test)]208
mod tests {209
use chrono::{FixedOffset, TimeZone, Utc};210
211
use super::*;212
use crate::data::{Directory, FolderInfo, FolderKind};213
use crate::typing::TypingState;214
use teams_core::ChatSection;215
216
fn chat(id: &str, title: &str, kind: &str) -> ChatRecord {217
ChatRecord {218
id: id.into(),219
kind: kind.into(),220
title: title.into(),221
..Default::default()222
}223
}224
225
fn admitted(filter: &ChatFilter, chats: &[ChatRecord], mentioned: &[&str]) -> Vec<String> {226
let mentioned: HashSet<String> = mentioned.iter().map(|id| (*id).to_owned()).collect();227
chats228
.iter()229
.filter(|chat| filter.admits(chat, &mentioned))230
.map(|chat| chat.id.clone())231
.collect()232
}233
234
#[test]235
fn name_filter_matches_a_substring_or_every_word_prefix_like_teams() {236
assert!(name_matches("", "Anything"));237
assert!(name_matches("lind", "Mara Lindqvist"));238
assert!(name_matches("ma li", "Mara Lindqvist"));239
assert!(name_matches("LI, MA", "Mara Lindqvist"));240
assert!(!name_matches("ma xo", "Mara Lindqvist"));241
}242
243
#[test]244
fn state_pills_must_all_hold_and_category_pills_need_one() {245
let chats = [246
ChatRecord {247
unread: true,248
..chat("unread", "Unread chat", "group")249
},250
ChatRecord {251
unread: true,252
..chat("meeting", "Standup", "meeting")253
},254
ChatRecord {255
muted: true,256
..chat("muted", "Muted chat", "group")257
},258
chat("plain", "Plain chat", "oneOnOne"),259
];260
let mut filter = ChatFilter::default();261
assert_eq!(admitted(&filter, &chats, &[]).len(), 4);262
filter.toggle(ChatFilterPill::Unread);263
assert_eq!(admitted(&filter, &chats, &[]), ["unread", "meeting"]);264
filter.toggle(ChatFilterPill::Meetings);265
assert_eq!(admitted(&filter, &chats, &[]), ["meeting"]);266
filter.toggle(ChatFilterPill::Unread);267
filter.toggle(ChatFilterPill::Meetings);268
filter.toggle(ChatFilterPill::Chats);269
assert_eq!(admitted(&filter, &chats, &[]), ["unread", "muted", "plain"]);270
filter.toggle(ChatFilterPill::Mentions);271
assert_eq!(admitted(&filter, &chats, &["plain"]), ["plain"]);272
}273
274
#[test]275
fn exclusive_pills_disable_each_other() {276
let mut filter = ChatFilter::default();277
assert!(filter.toggle(ChatFilterPill::Chats));278
assert!(filter.is_disabled(ChatFilterPill::Meetings));279
assert!(!filter.toggle(ChatFilterPill::Meetings));280
assert!(filter.toggle(ChatFilterPill::Muted));281
assert!(filter.is_disabled(ChatFilterPill::Mentions));282
assert!(!filter.is_disabled(ChatFilterPill::Unread));283
assert!(filter.toggle(ChatFilterPill::Chats));284
assert!(!filter.is_disabled(ChatFilterPill::Meetings));285
filter.text = "x".into();286
assert!(filter.is_active());287
filter.clear();288
assert!(!filter.is_active());289
}290
291
#[test]292
fn text_combines_with_pills() {293
let chats = [294
ChatRecord {295
unread: true,296
..chat("a", "Release crew", "group")297
},298
chat("b", "Release notes", "group"),299
];300
let filter = ChatFilter {301
text: "rel".into(),302
pills: vec![ChatFilterPill::Unread],303
};304
assert_eq!(admitted(&filter, &chats, &[]), ["a"]);305
}306
307
static NO_TYPING: std::sync::LazyLock<TypingState> =308
std::sync::LazyLock::new(TypingState::default);309
310
#[test]311
fn filtered_sections_keep_sections_drop_empty_ones_and_unpage_muted() {312
let mut chats = vec![313
chat("fav", "Favorite release", "group"),314
chat("other", "Other release", "group"),315
chat("quiet", "Quiet", "group"),316
];317
chats.extend((0..7).map(|index| ChatRecord {318
muted: true,319
..chat(320
&format!("m{index}"),321
&format!("Muted release {index}"),322
"group",323
)324
}));325
let mut directory = Directory {326
folders: vec![327
FolderInfo {328
id: "favorites".into(),329
name: "Favorites".into(),330
kind: FolderKind::Favorites,331
expanded: None,332
conversation_ids: vec!["fav".into()],333
},334
FolderInfo {335
id: "empty".into(),336
name: "Empty".into(),337
kind: FolderKind::UserCreated,338
expanded: None,339
conversation_ids: Vec::new(),340
},341
],342
..Default::default()343
};344
directory.section_settings.set(ChatSection::Muted, true);345
let collapsed = HashSet::new();346
let expanded = HashSet::new();347
let input = SectionInput {348
chats: &chats,349
directory: &directory,350
collapsed: &collapsed,351
expanded_lists: &expanded,352
typing: &NO_TYPING,353
now: Utc.with_ymd_and_hms(2026, 10, 17, 12, 0, 0).unwrap(),354
offset: FixedOffset::east_opt(0).unwrap(),355
};356
let filter = ChatFilter {357
text: "release".into(),358
pills: Vec::new(),359
};360
let sections = filtered_sections(&input, &filter, &HashSet::new(), None);361
let names: Vec<(&str, usize)> = sections362
.iter()363
.map(|section| (section.id.as_str(), section.items.len()))364
.collect();365
assert_eq!(names, [("favorites", 1), (OTHERS_ID, 1), (MUTED_ID, 7)]);366
assert!(sections.iter().all(|section| section.hidden_count == 0367
&& !section.list_expanded368
&& !section.show_empty_hint));369
let with_selection = filtered_sections(&input, &filter, &HashSet::new(), Some("quiet"));370
assert!(371
with_selection372
.iter()373
.any(|section| section.items.iter().any(|item| item.id == "quiet"))374
);375
}376
}@@ -737,6 +737,16 @@ pub fn activity_entries() -> Vec<Entry> {
737
737
false,
738
738
),
739
739
reaction,
740
entry(
741
"demo-chat-allhands",
742
Kind::Mention,
743
"demo-allhands-policy",
744
vec![actor(LEA_ID, "Lea Schneider")],
745
"@Dana please read the new vacation policy before Friday.",
746
1,
747
at(0, 9, 0),
748
false,
749
),
740
750
entry(
741
751
"demo-chat-customer-3",
742
752
Kind::Messages,
@@ -737,6 +737,16 @@ pub fn activity_entries() -> Vec<Entry> {737
false,737
false,738
),738
),739
reaction,739
reaction,740
entry(741
"demo-chat-allhands",742
Kind::Mention,743
"demo-allhands-policy",744
vec![actor(LEA_ID, "Lea Schneider")],745
"@Dana please read the new vacation policy before Friday.",746
1,747
at(0, 9, 0),748
false,749
),740
entry(750
entry(741
"demo-chat-customer-3",751
"demo-chat-customer-3",742
Kind::Messages,752
Kind::Messages,@@ -10,6 +10,7 @@ pub mod card_inputs;
10
10
pub mod card_refresh;
11
11
pub mod card_state;
12
12
pub mod chat_actions;
13
pub mod chat_filter;
13
14
pub mod chat_members;
14
15
pub mod connection_banner;
15
16
pub mod data;
@@ -10,6 +10,7 @@ pub mod card_inputs;10
pub mod card_refresh;10
pub mod card_refresh;11
pub mod card_state;11
pub mod card_state;12
pub mod chat_actions;12
pub mod chat_actions;13
pub mod chat_filter;13
pub mod chat_members;14
pub mod chat_members;14
pub mod connection_banner;15
pub mod connection_banner;15
pub mod data;16
pub mod data;@@ -189,9 +189,13 @@ mod frames {
189
189
AppShell, Startup, bind_keys, install_globals, sidebar_hidden_in_call,
190
190
};
191
191
use crate::views::shortcuts::{
192
OpenActivity, OpenAgents, OpenCallsTab, OpenChannelsTab, OpenSaved,
192
ClearChatFilters, FilterMutedChats, OpenActivity, OpenAgents, OpenCallsTab,
193
OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
193
194
};
194
195
use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;
196
use crate::views::sidebar::chat_filter_bar::{
197
FILTER_EMPTY_TAG, FILTER_INPUT_TAG, FILTER_PILLS_TAG, FILTER_TAG,
198
};
195
199
use crate::views::status_menu::{OWN_AVATAR_DISC, TITLE_AVATAR_SIZE};
196
200
197
201
const GUARDED: &[&str] = &[
@@ -214,6 +218,8 @@ mod frames {
214
218
"shell/islands/main/call-controls/leave",
215
219
];
216
220
const AGENTS_LIST: &str = "shell/islands/sidebar/agents";
221
const CHAT_FILTER_TAGS: &[&str] = &[FILTER_TAG, FILTER_PILLS_TAG];
222
const CHAT_FILTER_OPEN_TAGS: &[&str] = &[FILTER_INPUT_TAG, FILTER_EMPTY_TAG];
217
223
const CALLS_TAGS: &[&str] = &[
218
224
"shell/islands/sidebar/calls-actions",
219
225
"shell/islands/sidebar/calls-actions/meet-now",
@@ -554,6 +560,8 @@ mod frames {
554
560
.iter()
555
561
.chain(CALL_GUARDED)
556
562
.chain(CALLS_TAGS)
563
.chain(CHAT_FILTER_TAGS)
564
.chain(CHAT_FILTER_OPEN_TAGS)
557
565
.chain(PREJOIN_TAGS)
558
566
.chain(SHARE_GUARDED)
559
567
.chain(CONSULT_GUARDED)
@@ -764,7 +772,17 @@ mod frames {
764
772
size: size(px(width), px(height)),
765
773
};
766
774
let screens = [
767
Screen::Tab("chats", None),
775
Screen::Tab("chats", Some(|visual| visual.dispatch_action(OpenChatsTab))),
776
Screen::Tab(
777
"chat-filter",
778
Some(|visual| {
779
visual.dispatch_action(OpenChatsTab);
780
visual.dispatch_action(OpenChatFilter);
781
visual.dispatch_action(FilterMutedChats);
782
visual.run_until_parked();
783
visual.simulate_input("zzz");
784
}),
785
),
768
786
Screen::Tab(
769
787
"activity",
770
788
Some(|visual| visual.dispatch_action(OpenActivity)),
@@ -897,6 +915,11 @@ mod frames {
897
915
expected.push(MENU);
898
916
}
899
917
match screen_name {
918
"chats" => expected.extend(CHAT_FILTER_TAGS),
919
"chat-filter" => {
920
expected.extend(CHAT_FILTER_TAGS);
921
expected.extend(CHAT_FILTER_OPEN_TAGS);
922
}
900
923
"calls" => expected.extend(CALLS_TAGS),
901
924
"agents" => expected.push(AGENTS_LIST),
902
925
"prejoin" => expected.extend(PREJOIN_TAGS),
@@ -936,6 +959,11 @@ mod frames {
936
959
})
937
960
});
938
961
}
962
if screen_name == "chat-filter" {
963
visual.dispatch_action(ClearChatFilters);
964
visual.dispatch_action(OpenChatFilter);
965
visual.run_until_parked();
966
}
939
967
if screen_name == "prejoin" {
940
968
let state = visual.update(|_, cx| cx.global::<AppHandle>().0.clone());
941
969
visual.update(|_, cx| state.update(cx, |state, cx| state.cancel_prejoin(cx)));
@@ -189,9 +189,13 @@ mod frames {189
AppShell, Startup, bind_keys, install_globals, sidebar_hidden_in_call,189
AppShell, Startup, bind_keys, install_globals, sidebar_hidden_in_call,190
};190
};191
use crate::views::shortcuts::{191
use crate::views::shortcuts::{192
OpenActivity, OpenAgents, OpenCallsTab, OpenChannelsTab, OpenSaved,192
ClearChatFilters, FilterMutedChats, OpenActivity, OpenAgents, OpenCallsTab,193
OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,193
};194
};194
use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;195
use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;196
use crate::views::sidebar::chat_filter_bar::{197
FILTER_EMPTY_TAG, FILTER_INPUT_TAG, FILTER_PILLS_TAG, FILTER_TAG,198
};195
use crate::views::status_menu::{OWN_AVATAR_DISC, TITLE_AVATAR_SIZE};199
use crate::views::status_menu::{OWN_AVATAR_DISC, TITLE_AVATAR_SIZE};196
200
197
const GUARDED: &[&str] = &[201
const GUARDED: &[&str] = &[@@ -214,6 +218,8 @@ mod frames {214
"shell/islands/main/call-controls/leave",218
"shell/islands/main/call-controls/leave",215
];219
];216
const AGENTS_LIST: &str = "shell/islands/sidebar/agents";220
const AGENTS_LIST: &str = "shell/islands/sidebar/agents";221
const CHAT_FILTER_TAGS: &[&str] = &[FILTER_TAG, FILTER_PILLS_TAG];222
const CHAT_FILTER_OPEN_TAGS: &[&str] = &[FILTER_INPUT_TAG, FILTER_EMPTY_TAG];217
const CALLS_TAGS: &[&str] = &[223
const CALLS_TAGS: &[&str] = &[218
"shell/islands/sidebar/calls-actions",224
"shell/islands/sidebar/calls-actions",219
"shell/islands/sidebar/calls-actions/meet-now",225
"shell/islands/sidebar/calls-actions/meet-now",@@ -554,6 +560,8 @@ mod frames {554
.iter()560
.iter()555
.chain(CALL_GUARDED)561
.chain(CALL_GUARDED)556
.chain(CALLS_TAGS)562
.chain(CALLS_TAGS)563
.chain(CHAT_FILTER_TAGS)564
.chain(CHAT_FILTER_OPEN_TAGS)557
.chain(PREJOIN_TAGS)565
.chain(PREJOIN_TAGS)558
.chain(SHARE_GUARDED)566
.chain(SHARE_GUARDED)559
.chain(CONSULT_GUARDED)567
.chain(CONSULT_GUARDED)@@ -764,7 +772,17 @@ mod frames {764
size: size(px(width), px(height)),772
size: size(px(width), px(height)),765
};773
};766
let screens = [774
let screens = [767
Screen::Tab("chats", None),775
Screen::Tab("chats", Some(|visual| visual.dispatch_action(OpenChatsTab))),776
Screen::Tab(777
"chat-filter",778
Some(|visual| {779
visual.dispatch_action(OpenChatsTab);780
visual.dispatch_action(OpenChatFilter);781
visual.dispatch_action(FilterMutedChats);782
visual.run_until_parked();783
visual.simulate_input("zzz");784
}),785
),768
Screen::Tab(786
Screen::Tab(769
"activity",787
"activity",770
Some(|visual| visual.dispatch_action(OpenActivity)),788
Some(|visual| visual.dispatch_action(OpenActivity)),@@ -897,6 +915,11 @@ mod frames {897
expected.push(MENU);915
expected.push(MENU);898
}916
}899
match screen_name {917
match screen_name {918
"chats" => expected.extend(CHAT_FILTER_TAGS),919
"chat-filter" => {920
expected.extend(CHAT_FILTER_TAGS);921
expected.extend(CHAT_FILTER_OPEN_TAGS);922
}900
"calls" => expected.extend(CALLS_TAGS),923
"calls" => expected.extend(CALLS_TAGS),901
"agents" => expected.push(AGENTS_LIST),924
"agents" => expected.push(AGENTS_LIST),902
"prejoin" => expected.extend(PREJOIN_TAGS),925
"prejoin" => expected.extend(PREJOIN_TAGS),@@ -936,6 +959,11 @@ mod frames {936
})959
})937
});960
});938
}961
}962
if screen_name == "chat-filter" {963
visual.dispatch_action(ClearChatFilters);964
visual.dispatch_action(OpenChatFilter);965
visual.run_until_parked();966
}939
if screen_name == "prejoin" {967
if screen_name == "prejoin" {940
let state = visual.update(|_, cx| cx.global::<AppHandle>().0.clone());968
let state = visual.update(|_, cx| cx.global::<AppHandle>().0.clone());941
visual.update(|_, cx| state.update(cx, |state, cx| state.cancel_prejoin(cx)));969
visual.update(|_, cx| state.update(cx, |state, cx| state.cancel_prejoin(cx)));@@ -45,6 +45,10 @@ pub struct ActivityPanel {
45
45
impl EventEmitter<ActivityPanelEvent> for ActivityPanel {}
46
46
47
47
impl ActivityPanel {
48
pub fn activity(&self) -> Entity<ActivityCenter> {
49
self.activity.clone()
50
}
51
48
52
pub fn new(
49
53
app: Entity<AppState>,
50
54
activity: Entity<ActivityCenter>,
@@ -45,6 +45,10 @@ pub struct ActivityPanel {45
impl EventEmitter<ActivityPanelEvent> for ActivityPanel {}45
impl EventEmitter<ActivityPanelEvent> for ActivityPanel {}46
46
47
impl ActivityPanel {47
impl ActivityPanel {48
pub fn activity(&self) -> Entity<ActivityCenter> {49
self.activity.clone()50
}51
48
pub fn new(52
pub fn new(49
app: Entity<AppState>,53
app: Entity<AppState>,50
activity: Entity<ActivityCenter>,54
activity: Entity<ActivityCenter>,@@ -17,10 +17,12 @@ use super::prejoin_view::PrejoinView;
17
17
use super::profile_card::{ProfileCard, ProfileCardEvent};
18
18
use gpui_kit::prelude::FluentBuilder as _;
19
19
use super::rail::RailView;
20
use crate::chat_filter::ChatFilterPill;
20
21
use super::saved_panel::{SavedPanel, SavedPanelEvent};
21
22
use super::shortcuts::{
22
AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,
23
OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
23
AcceptCall, ClearChatFilters, DeclineCall, FilterMeetingChats, FilterMutedChats,
24
FilterNonMeetingChats, FilterUnreadChats, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,
25
OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,
24
26
Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,
25
27
ToggleCallHand, ToggleCallShare, ZoomIn, ZoomOut, ZoomReset, ZoomShareIn, ZoomShareOut,
26
28
ZoomShareReset,
@@ -28,7 +30,7 @@ use super::shortcuts::{
28
30
use super::window_zoom::{WindowZoom, change_zoom};
29
31
use super::call_pop_out::zoom_listener;
30
32
use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
31
use super::sidebar::SidebarView;
33
use super::sidebar::{SidebarEvent, SidebarView};
32
34
use app_ui_kit::render::hooks::RenderHooks;
33
35
use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};
34
36
use super::connection_banner::render_connection_banner;
@@ -138,6 +140,7 @@ pub struct AppShell {
138
140
call_mini: Entity<CallMiniView>,
139
141
_call_media_observation: Subscription,
140
142
_panel_subscriptions: [Subscription; 2],
143
_sidebar_subscription: Subscription,
141
144
_agents_subscription: Option<Subscription>,
142
145
_agent_subscription: Option<Subscription>,
143
146
_escape_observation: Subscription,
@@ -251,6 +254,9 @@ impl AppShell {
251
254
)
252
255
});
253
256
let sidebar = cx.new(|cx| SidebarView::new(state.clone(), activity_panel, saved_panel, agents_panel, cx));
257
let sidebar_subscription = cx.subscribe_in(&sidebar, window, |this, _, _: &SidebarEvent, window, cx| {
258
this.restore_focus(window, cx);
259
});
254
260
let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx));
255
261
let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx));
256
262
let timeline = conversation.read(cx).timeline_bounds();
@@ -332,6 +338,7 @@ impl AppShell {
332
338
call_mini,
333
339
_call_media_observation: call_media_observation,
334
340
_panel_subscriptions: panel_subscriptions,
341
_sidebar_subscription: sidebar_subscription,
335
342
_agents_subscription: agents_subscription,
336
343
_agent_subscription: agent_subscription,
337
344
_escape_observation: escape_observation,
@@ -968,6 +975,31 @@ impl Render for AppShell {
968
975
this.sidebar
969
976
.update(cx, |sidebar, cx| sidebar.show_chats(cx));
970
977
}))
978
.on_action(cx.listener(|this, _: &OpenChatFilter, window, cx| {
979
this.close_image_viewer(window, cx);
980
this.sidebar
981
.update(cx, |sidebar, cx| sidebar.toggle_filter_box(window, cx));
982
}))
983
.on_action(cx.listener(|this, _: &FilterUnreadChats, _, cx| {
984
this.sidebar
985
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Unread, cx));
986
}))
987
.on_action(cx.listener(|this, _: &FilterNonMeetingChats, _, cx| {
988
this.sidebar
989
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Chats, cx));
990
}))
991
.on_action(cx.listener(|this, _: &FilterMeetingChats, _, cx| {
992
this.sidebar
993
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Meetings, cx));
994
}))
995
.on_action(cx.listener(|this, _: &FilterMutedChats, _, cx| {
996
this.sidebar
997
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Muted, cx));
998
}))
999
.on_action(cx.listener(|this, _: &ClearChatFilters, window, cx| {
1000
this.sidebar
1001
.update(cx, |sidebar, cx| sidebar.clear_filters(window, cx));
1002
}))
971
1003
.on_action(cx.listener(|this, _: &OpenChannelsTab, window, cx| {
972
1004
this.close_image_viewer(window, cx);
973
1005
this.sidebar
@@ -17,10 +17,12 @@ use super::prejoin_view::PrejoinView;17
use super::profile_card::{ProfileCard, ProfileCardEvent};17
use super::profile_card::{ProfileCard, ProfileCardEvent};18
use gpui_kit::prelude::FluentBuilder as _;18
use gpui_kit::prelude::FluentBuilder as _;19
use super::rail::RailView;19
use super::rail::RailView;20
use crate::chat_filter::ChatFilterPill;20
use super::saved_panel::{SavedPanel, SavedPanelEvent};21
use super::saved_panel::{SavedPanel, SavedPanelEvent};21
use super::shortcuts::{22
use super::shortcuts::{22
AcceptCall, DeclineCall, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,23
AcceptCall, ClearChatFilters, DeclineCall, FilterMeetingChats, FilterMutedChats,23
OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,24
FilterNonMeetingChats, FilterUnreadChats, HangUpCall, JoinMeetingFromToast, JumpToLastReadOrNewest, NextConversation, OpenActivity,25
OpenAgents, OpenCallsTab, OpenSettings, OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenLobbyList, OpenSaved, PreviousConversation, PushToTalk,24
Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,26
Scope, ShowShortcuts, StartAudioCall, StartVideoCall, ToggleCallCamera, ToggleCallFullscreen,25
ToggleCallHand, ToggleCallShare, ZoomIn, ZoomOut, ZoomReset, ZoomShareIn, ZoomShareOut,27
ToggleCallHand, ToggleCallShare, ZoomIn, ZoomOut, ZoomReset, ZoomShareIn, ZoomShareOut,26
ZoomShareReset,28
ZoomShareReset,@@ -28,7 +30,7 @@ use super::shortcuts::{28
use super::window_zoom::{WindowZoom, change_zoom};30
use super::window_zoom::{WindowZoom, change_zoom};29
use super::call_pop_out::zoom_listener;31
use super::call_pop_out::zoom_listener;30
use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};32
use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};31
use super::sidebar::SidebarView;33
use super::sidebar::{SidebarEvent, SidebarView};32
use app_ui_kit::render::hooks::RenderHooks;34
use app_ui_kit::render::hooks::RenderHooks;33
use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};35
use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};34
use super::connection_banner::render_connection_banner;36
use super::connection_banner::render_connection_banner;@@ -138,6 +140,7 @@ pub struct AppShell {138
call_mini: Entity<CallMiniView>,140
call_mini: Entity<CallMiniView>,139
_call_media_observation: Subscription,141
_call_media_observation: Subscription,140
_panel_subscriptions: [Subscription; 2],142
_panel_subscriptions: [Subscription; 2],143
_sidebar_subscription: Subscription,141
_agents_subscription: Option<Subscription>,144
_agents_subscription: Option<Subscription>,142
_agent_subscription: Option<Subscription>,145
_agent_subscription: Option<Subscription>,143
_escape_observation: Subscription,146
_escape_observation: Subscription,@@ -251,6 +254,9 @@ impl AppShell {251
)254
)252
});255
});253
let sidebar = cx.new(|cx| SidebarView::new(state.clone(), activity_panel, saved_panel, agents_panel, cx));256
let sidebar = cx.new(|cx| SidebarView::new(state.clone(), activity_panel, saved_panel, agents_panel, cx));257
let sidebar_subscription = cx.subscribe_in(&sidebar, window, |this, _, _: &SidebarEvent, window, cx| {258
this.restore_focus(window, cx);259
});254
let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx));260
let rail = cx.new(|cx| RailView::new(state.clone(), activity.clone(), sidebar.clone(), cx));255
let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx));261
let conversation = cx.new(|cx| ConversationView::new(state.clone(), window, cx));256
let timeline = conversation.read(cx).timeline_bounds();262
let timeline = conversation.read(cx).timeline_bounds();@@ -332,6 +338,7 @@ impl AppShell {332
call_mini,338
call_mini,333
_call_media_observation: call_media_observation,339
_call_media_observation: call_media_observation,334
_panel_subscriptions: panel_subscriptions,340
_panel_subscriptions: panel_subscriptions,341
_sidebar_subscription: sidebar_subscription,335
_agents_subscription: agents_subscription,342
_agents_subscription: agents_subscription,336
_agent_subscription: agent_subscription,343
_agent_subscription: agent_subscription,337
_escape_observation: escape_observation,344
_escape_observation: escape_observation,@@ -968,6 +975,31 @@ impl Render for AppShell {968
this.sidebar975
this.sidebar969
.update(cx, |sidebar, cx| sidebar.show_chats(cx));976
.update(cx, |sidebar, cx| sidebar.show_chats(cx));970
}))977
}))978
.on_action(cx.listener(|this, _: &OpenChatFilter, window, cx| {979
this.close_image_viewer(window, cx);980
this.sidebar981
.update(cx, |sidebar, cx| sidebar.toggle_filter_box(window, cx));982
}))983
.on_action(cx.listener(|this, _: &FilterUnreadChats, _, cx| {984
this.sidebar985
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Unread, cx));986
}))987
.on_action(cx.listener(|this, _: &FilterNonMeetingChats, _, cx| {988
this.sidebar989
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Chats, cx));990
}))991
.on_action(cx.listener(|this, _: &FilterMeetingChats, _, cx| {992
this.sidebar993
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Meetings, cx));994
}))995
.on_action(cx.listener(|this, _: &FilterMutedChats, _, cx| {996
this.sidebar997
.update(cx, |sidebar, cx| sidebar.toggle_pill(ChatFilterPill::Muted, cx));998
}))999
.on_action(cx.listener(|this, _: &ClearChatFilters, window, cx| {1000
this.sidebar1001
.update(cx, |sidebar, cx| sidebar.clear_filters(window, cx));1002
}))971
.on_action(cx.listener(|this, _: &OpenChannelsTab, window, cx| {1003
.on_action(cx.listener(|this, _: &OpenChannelsTab, window, cx| {972
this.close_image_viewer(window, cx);1004
this.close_image_viewer(window, cx);973
this.sidebar1005
this.sidebar@@ -29,6 +29,12 @@ actions!(
29
29
OpenSaved,
30
30
OpenCallsTab,
31
31
OpenAgents,
32
OpenChatFilter,
33
FilterUnreadChats,
34
FilterNonMeetingChats,
35
FilterMeetingChats,
36
FilterMutedChats,
37
ClearChatFilters,
32
38
PreviousConversation,
33
39
NextConversation,
34
40
JumpToLastReadOrNewest,
@@ -129,6 +135,12 @@ pub const SHORTCUTS: &[Shortcut] = &[
129
135
shortcut!(Navigation, GlobalOverTextFields, "Open Agents", "ctrl-6", Some("cmd-6"), OpenAgents),
130
136
shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),
131
137
shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),
138
shortcut!(Navigation, GlobalOverTextFields, "Open filter", "ctrl-shift-f", Some("cmd-shift-f"), OpenChatFilter),
139
shortcut!(Navigation, OutsideTextFields, "Filter chat list by unread chats only", "ctrl-alt-u", None, FilterUnreadChats),
140
shortcut!(Navigation, OutsideTextFields, "Filter chat list by chats only", "ctrl-alt-c", None, FilterNonMeetingChats),
141
shortcut!(Navigation, OutsideTextFields, "Filter chat list by meeting chats only", "ctrl-alt-b", None, FilterMeetingChats),
142
shortcut!(Navigation, OutsideTextFields, "Filter chat list by muted chats only", "ctrl-alt-q", None, FilterMutedChats),
143
shortcut!(Navigation, OutsideTextFields, "Remove all filters in the chat list", "ctrl-alt-z", None, ClearChatFilters),
132
144
shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),
133
145
shortcut!(Composer, Global, "Jump to last read or newest message", "ctrl-j", Some("cmd-j"), JumpToLastReadOrNewest),
134
146
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),
@@ -29,6 +29,12 @@ actions!(29
OpenSaved,29
OpenSaved,30
OpenCallsTab,30
OpenCallsTab,31
OpenAgents,31
OpenAgents,32
OpenChatFilter,33
FilterUnreadChats,34
FilterNonMeetingChats,35
FilterMeetingChats,36
FilterMutedChats,37
ClearChatFilters,32
PreviousConversation,38
PreviousConversation,33
NextConversation,39
NextConversation,34
JumpToLastReadOrNewest,40
JumpToLastReadOrNewest,@@ -129,6 +135,12 @@ pub const SHORTCUTS: &[Shortcut] = &[129
shortcut!(Navigation, GlobalOverTextFields, "Open Agents", "ctrl-6", Some("cmd-6"), OpenAgents),135
shortcut!(Navigation, GlobalOverTextFields, "Open Agents", "ctrl-6", Some("cmd-6"), OpenAgents),130
shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),136
shortcut!(Navigation, GlobalOverTextFields, "Previous chat or channel", "alt-up", None, PreviousConversation),131
shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),137
shortcut!(Navigation, GlobalOverTextFields, "Next chat or channel", "alt-down", None, NextConversation),138
shortcut!(Navigation, GlobalOverTextFields, "Open filter", "ctrl-shift-f", Some("cmd-shift-f"), OpenChatFilter),139
shortcut!(Navigation, OutsideTextFields, "Filter chat list by unread chats only", "ctrl-alt-u", None, FilterUnreadChats),140
shortcut!(Navigation, OutsideTextFields, "Filter chat list by chats only", "ctrl-alt-c", None, FilterNonMeetingChats),141
shortcut!(Navigation, OutsideTextFields, "Filter chat list by meeting chats only", "ctrl-alt-b", None, FilterMeetingChats),142
shortcut!(Navigation, OutsideTextFields, "Filter chat list by muted chats only", "ctrl-alt-q", None, FilterMutedChats),143
shortcut!(Navigation, OutsideTextFields, "Remove all filters in the chat list", "ctrl-alt-z", None, ClearChatFilters),132
shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),144
shortcut!(Composer, Global, "Reply to the message under the pointer", "alt-r", None, ReplyToHovered),133
shortcut!(Composer, Global, "Jump to last read or newest message", "ctrl-j", Some("cmd-j"), JumpToLastReadOrNewest),145
shortcut!(Composer, Global, "Jump to last read or newest message", "ctrl-j", Some("cmd-j"), JumpToLastReadOrNewest),134
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),146
shortcut!(Composer, Composer, "Bold", "ctrl-b", Some("cmd-b"), ToggleBold),@@ -25,6 +25,7 @@ use super::widgets::{count_badge, icon, page_header, unread_marker};
25
25
use crate::agents::AgentsPanel;
26
26
use crate::app_state::{AppEvent, AppState, Selection};
27
27
use crate::chat_actions::TITLE_LIMIT;
28
use crate::chat_filter::{ChatFilter, filtered_sections, has_no_matches};
28
29
use crate::data::{Directory, is_pending_folder};
29
30
use crate::format;
30
31
use crate::local_previews::LocalPreview;
@@ -37,6 +38,9 @@ use crate::sidebar_model::{
37
38
};
38
39
use crate::theme;
39
40
use app_ui_kit::layout::SIDEBAR_WIDTH;
41
use gpui_kit::component::input::InputState;
42
43
pub(crate) mod chat_filter_bar;
40
44
41
45
pub const SIDEBAR_SCROLL_DIVIDER: &str = "shell/islands/sidebar/divider-scroll";
42
46
const COLLAPSED_TEAMS_META_KEY: &str = "sidebar_collapsed_teams";
@@ -473,6 +477,12 @@ pub(crate) fn confirm_leave(
473
477
});
474
478
}
475
479
480
pub enum SidebarEvent {
481
RestoreFocus,
482
}
483
484
impl EventEmitter<SidebarEvent> for SidebarView {}
485
476
486
pub struct SidebarView {
477
487
state: Entity<AppState>,
478
488
tab: SidebarTab,
@@ -487,6 +497,12 @@ pub struct SidebarView {
487
497
older_chats_seen: Cell<(bool, bool)>,
488
498
channels_scroll: ScrollHandle,
489
499
calls_scroll: ScrollHandle,
500
chat_filter: ChatFilter,
501
filter_box_open: bool,
502
more_filters_open: bool,
503
filter_input: Option<Entity<InputState>>,
504
filter_subscription: Option<Subscription>,
505
_activity_observation: Subscription,
490
506
_subscription: Subscription,
491
507
_state_observation: Subscription,
492
508
_agent_observation: Option<Subscription>,
@@ -577,6 +593,15 @@ impl SidebarView {
577
593
SidebarTab::Chats
578
594
};
579
595
let collapsed_teams = load_collapsed_teams(&state.read(cx).store);
596
let activity = activity_panel.read(cx).activity();
597
let activity_observation = cx.observe(&activity, |view, _, cx| {
598
if view
599
.chat_filter
600
.has(crate::chat_filter::ChatFilterPill::Mentions)
601
{
602
cx.notify();
603
}
604
});
580
605
cx.spawn(async move |this, cx| {
581
606
loop {
582
607
cx.background_executor().timer(CALLS_REFRESH).await;
@@ -605,6 +630,12 @@ impl SidebarView {
605
630
older_chats_seen: Cell::new((false, false)),
606
631
channels_scroll: ScrollHandle::new(),
607
632
calls_scroll: ScrollHandle::new(),
633
chat_filter: ChatFilter::default(),
634
filter_box_open: false,
635
more_filters_open: false,
636
filter_input: None,
637
filter_subscription: None,
638
_activity_observation: activity_observation,
608
639
_subscription: subscription,
609
640
_state_observation: state_observation,
610
641
_agent_observation: agent_observation,
@@ -1069,7 +1100,18 @@ impl SidebarView {
1069
1100
now,
1070
1101
offset,
1071
1102
};
1072
let sections = build_sections(&input);
1103
let sections = if self.chat_filter.is_active() {
1104
let mentioned = self.mentioned_chats(cx);
1105
let selected_id = self.selected_chat_id(cx);
1106
filtered_sections(
1107
&input,
1108
&self.chat_filter,
1109
&mentioned,
1110
selected_id.as_deref(),
1111
)
1112
} else {
1113
build_sections(&input)
1114
};
1073
1115
let menu = MenuContext {
1074
1116
state: self.state.clone(),
1075
1117
folders: state.directory.move_targets(),
@@ -1194,6 +1236,10 @@ impl SidebarView {
1194
1236
.child(LOADING_OLDER_LABEL),
1195
1237
);
1196
1238
}
1239
let selected_chat_id = self.selected_chat_id(cx);
1240
if self.chat_filter.is_active() && has_no_matches(§ions, selected_chat_id.as_deref()) {
1241
list = list.child(self.filter_empty_state(cx));
1242
}
1197
1243
list = with_spacer(list, &mut skipped_height);
1198
1244
self.request_lazy_data(faces, presence_users, cx);
1199
1245
let scroll_area = div()
@@ -1772,12 +1818,18 @@ impl Render for SidebarView {
1772
1818
};
1773
1819
let header = match self.tab {
1774
1820
SidebarTab::Chats => Some(
1775
page_header(self.tab.title())
1776
.child(self.chat_list_menu_button(cx))
1777
.child(self.new_chat_button(cx)),
1821
v_flex()
1822
.flex_none()
1823
.child(
1824
page_header(self.tab.title())
1825
.child(self.chat_list_menu_button(cx))
1826
.child(self.filter_toggle_button(cx))
1827
.child(self.new_chat_button(cx)),
1828
)
1829
.child(self.filter_bar(cx)),
1778
1830
),
1779
1831
SidebarTab::Channels | SidebarTab::Calls | SidebarTab::Agents => {
1780
Some(page_header(self.tab.title()))
1832
Some(v_flex().child(page_header(self.tab.title())))
1781
1833
}
1782
1834
SidebarTab::Activity | SidebarTab::Saved => None,
1783
1835
};
@@ -25,6 +25,7 @@ use super::widgets::{count_badge, icon, page_header, unread_marker};25
use crate::agents::AgentsPanel;25
use crate::agents::AgentsPanel;26
use crate::app_state::{AppEvent, AppState, Selection};26
use crate::app_state::{AppEvent, AppState, Selection};27
use crate::chat_actions::TITLE_LIMIT;27
use crate::chat_actions::TITLE_LIMIT;28
use crate::chat_filter::{ChatFilter, filtered_sections, has_no_matches};28
use crate::data::{Directory, is_pending_folder};29
use crate::data::{Directory, is_pending_folder};29
use crate::format;30
use crate::format;30
use crate::local_previews::LocalPreview;31
use crate::local_previews::LocalPreview;@@ -37,6 +38,9 @@ use crate::sidebar_model::{37
};38
};38
use crate::theme;39
use crate::theme;39
use app_ui_kit::layout::SIDEBAR_WIDTH;40
use app_ui_kit::layout::SIDEBAR_WIDTH;41
use gpui_kit::component::input::InputState;42
43
pub(crate) mod chat_filter_bar;40
44
41
pub const SIDEBAR_SCROLL_DIVIDER: &str = "shell/islands/sidebar/divider-scroll";45
pub const SIDEBAR_SCROLL_DIVIDER: &str = "shell/islands/sidebar/divider-scroll";42
const COLLAPSED_TEAMS_META_KEY: &str = "sidebar_collapsed_teams";46
const COLLAPSED_TEAMS_META_KEY: &str = "sidebar_collapsed_teams";@@ -473,6 +477,12 @@ pub(crate) fn confirm_leave(473
});477
});474
}478
}475
479
480
pub enum SidebarEvent {481
RestoreFocus,482
}483
484
impl EventEmitter<SidebarEvent> for SidebarView {}485
476
pub struct SidebarView {486
pub struct SidebarView {477
state: Entity<AppState>,487
state: Entity<AppState>,478
tab: SidebarTab,488
tab: SidebarTab,@@ -487,6 +497,12 @@ pub struct SidebarView {487
older_chats_seen: Cell<(bool, bool)>,497
older_chats_seen: Cell<(bool, bool)>,488
channels_scroll: ScrollHandle,498
channels_scroll: ScrollHandle,489
calls_scroll: ScrollHandle,499
calls_scroll: ScrollHandle,500
chat_filter: ChatFilter,501
filter_box_open: bool,502
more_filters_open: bool,503
filter_input: Option<Entity<InputState>>,504
filter_subscription: Option<Subscription>,505
_activity_observation: Subscription,490
_subscription: Subscription,506
_subscription: Subscription,491
_state_observation: Subscription,507
_state_observation: Subscription,492
_agent_observation: Option<Subscription>,508
_agent_observation: Option<Subscription>,@@ -577,6 +593,15 @@ impl SidebarView {577
SidebarTab::Chats593
SidebarTab::Chats578
};594
};579
let collapsed_teams = load_collapsed_teams(&state.read(cx).store);595
let collapsed_teams = load_collapsed_teams(&state.read(cx).store);596
let activity = activity_panel.read(cx).activity();597
let activity_observation = cx.observe(&activity, |view, _, cx| {598
if view599
.chat_filter600
.has(crate::chat_filter::ChatFilterPill::Mentions)601
{602
cx.notify();603
}604
});580
cx.spawn(async move |this, cx| {605
cx.spawn(async move |this, cx| {581
loop {606
loop {582
cx.background_executor().timer(CALLS_REFRESH).await;607
cx.background_executor().timer(CALLS_REFRESH).await;@@ -605,6 +630,12 @@ impl SidebarView {605
older_chats_seen: Cell::new((false, false)),630
older_chats_seen: Cell::new((false, false)),606
channels_scroll: ScrollHandle::new(),631
channels_scroll: ScrollHandle::new(),607
calls_scroll: ScrollHandle::new(),632
calls_scroll: ScrollHandle::new(),633
chat_filter: ChatFilter::default(),634
filter_box_open: false,635
more_filters_open: false,636
filter_input: None,637
filter_subscription: None,638
_activity_observation: activity_observation,608
_subscription: subscription,639
_subscription: subscription,609
_state_observation: state_observation,640
_state_observation: state_observation,610
_agent_observation: agent_observation,641
_agent_observation: agent_observation,@@ -1069,7 +1100,18 @@ impl SidebarView {1069
now,1100
now,1070
offset,1101
offset,1071
};1102
};1072
let sections = build_sections(&input);1103
let sections = if self.chat_filter.is_active() {1104
let mentioned = self.mentioned_chats(cx);1105
let selected_id = self.selected_chat_id(cx);1106
filtered_sections(1107
&input,1108
&self.chat_filter,1109
&mentioned,1110
selected_id.as_deref(),1111
)1112
} else {1113
build_sections(&input)1114
};1073
let menu = MenuContext {1115
let menu = MenuContext {1074
state: self.state.clone(),1116
state: self.state.clone(),1075
folders: state.directory.move_targets(),1117
folders: state.directory.move_targets(),@@ -1194,6 +1236,10 @@ impl SidebarView {1194
.child(LOADING_OLDER_LABEL),1236
.child(LOADING_OLDER_LABEL),1195
);1237
);1196
}1238
}1239
let selected_chat_id = self.selected_chat_id(cx);1240
if self.chat_filter.is_active() && has_no_matches(§ions, selected_chat_id.as_deref()) {1241
list = list.child(self.filter_empty_state(cx));1242
}1197
list = with_spacer(list, &mut skipped_height);1243
list = with_spacer(list, &mut skipped_height);1198
self.request_lazy_data(faces, presence_users, cx);1244
self.request_lazy_data(faces, presence_users, cx);1199
let scroll_area = div()1245
let scroll_area = div()@@ -1772,12 +1818,18 @@ impl Render for SidebarView {1772
};1818
};1773
let header = match self.tab {1819
let header = match self.tab {1774
SidebarTab::Chats => Some(1820
SidebarTab::Chats => Some(1775
page_header(self.tab.title())1821
v_flex()1776
.child(self.chat_list_menu_button(cx))1822
.flex_none()1777
.child(self.new_chat_button(cx)),1823
.child(1824
page_header(self.tab.title())1825
.child(self.chat_list_menu_button(cx))1826
.child(self.filter_toggle_button(cx))1827
.child(self.new_chat_button(cx)),1828
)1829
.child(self.filter_bar(cx)),1778
),1830
),1779
SidebarTab::Channels | SidebarTab::Calls | SidebarTab::Agents => {1831
SidebarTab::Channels | SidebarTab::Calls | SidebarTab::Agents => {1780
Some(page_header(self.tab.title()))1832
Some(v_flex().child(page_header(self.tab.title())))1781
}1833
}1782
SidebarTab::Activity | SidebarTab::Saved => None,1834
SidebarTab::Activity | SidebarTab::Saved => None,1783
};1835
};@@ -0,0 +1,320 @@
1
use std::collections::HashSet;
2
3
use gpui_kit::assets::IconName;
4
use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};
5
use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
6
use gpui_kit::prelude::FluentBuilder as _;
7
use gpui_kit::*;
8
9
use super::{NEW_CHAT_BUTTON_SIZE, SidebarEvent, SidebarTab, SidebarView};
10
use crate::app_state::Selection;
11
use crate::chat_filter::{
12
CLEAR_FILTER_TEXT, CLEAR_FILTERS, CLOSE_FILTER_TEXT, ChatFilterPill, FEWER_FILTERS,
13
FILTER_PLACEHOLDER, MORE_FILTERS, NO_MATCHES, SHOW_FILTER_TEXT, mentioned_conversations,
14
};
15
use crate::theme;
16
use crate::views::widgets::icon;
17
18
pub const FILTER_TAG: &str = "shell/islands/sidebar/chat-filter";
19
pub const FILTER_INPUT_TAG: &str = "shell/islands/sidebar/chat-filter/input";
20
pub const FILTER_PILLS_TAG: &str = "shell/islands/sidebar/chat-filter/pills";
21
pub const FILTER_EMPTY_TAG: &str = "shell/islands/sidebar/chat-filter-empty";
22
const INPUT_HEIGHT: f32 = 32.;
23
const PILL_HEIGHT: f32 = 24.;
24
const SIDE_INSET: f32 = 16.;
25
26
impl SidebarView {
27
pub fn toggle_filter_box(&mut self, window: &mut Window, cx: &mut Context<Self>) {
28
if self.tab != SidebarTab::Chats {
29
self.open_tab(SidebarTab::Chats, cx);
30
} else if self.filter_box_open {
31
self.close_filter_box(window, cx);
32
return;
33
}
34
self.filter_box_open = true;
35
let input = self.filter_input(window, cx);
36
input.update(cx, |input, cx| input.focus(window, cx));
37
cx.notify();
38
}
39
40
pub fn toggle_pill(&mut self, pill: ChatFilterPill, cx: &mut Context<Self>) {
41
if self.tab != SidebarTab::Chats {
42
self.open_tab(SidebarTab::Chats, cx);
43
}
44
if self.chat_filter.toggle(pill) {
45
cx.notify();
46
}
47
}
48
49
pub fn clear_filters(&mut self, window: &mut Window, cx: &mut Context<Self>) {
50
self.chat_filter.clear();
51
if let Some(input) = &self.filter_input {
52
input.update(cx, |input, cx| input.set_value("", window, cx));
53
}
54
cx.notify();
55
}
56
57
pub(super) fn mentioned_chats(&self, cx: &App) -> HashSet<String> {
58
if !self.chat_filter.has(ChatFilterPill::Mentions) {
59
return HashSet::new();
60
}
61
let activity = self.activity_panel.read(cx).activity();
62
mentioned_conversations(activity.read(cx).feed().unread_entries())
63
}
64
65
pub(super) fn selected_chat_id(&self, cx: &App) -> Option<String> {
66
match &self.state.read(cx).selection {
67
Some(Selection::Chat(chat_id)) => Some(chat_id.clone()),
68
_ => None,
69
}
70
}
71
72
fn close_filter_box(&mut self, window: &mut Window, cx: &mut Context<Self>) {
73
self.filter_box_open = false;
74
cx.emit(SidebarEvent::RestoreFocus);
75
self.chat_filter.text.clear();
76
if let Some(input) = &self.filter_input {
77
input.update(cx, |input, cx| input.set_value("", window, cx));
78
}
79
cx.notify();
80
}
81
82
fn filter_input(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Entity<InputState> {
83
if let Some(input) = &self.filter_input {
84
return input.clone();
85
}
86
let input = cx.new(|cx| InputState::new(window, cx).placeholder(FILTER_PLACEHOLDER));
87
let subscription = cx.subscribe_in(&input, window, |this, input, event, _, cx| {
88
if matches!(event, InputEvent::Change) {
89
this.chat_filter.text = input.read(cx).value().to_string();
90
cx.notify();
91
}
92
});
93
self.filter_subscription = Some(subscription);
94
self.filter_input = Some(input.clone());
95
input
96
}
97
98
pub(super) fn filter_toggle_button(&self, cx: &mut Context<Self>) -> impl IntoElement {
99
let open = self.filter_box_open;
100
let active = open || self.chat_filter.is_active();
101
let label = if open {
102
CLOSE_FILTER_TEXT
103
} else {
104
SHOW_FILTER_TEXT
105
};
106
div()
107
.id("chat-filter-toggle")
108
.size(px(NEW_CHAT_BUTTON_SIZE))
109
.flex_none()
110
.flex()
111
.items_center()
112
.justify_center()
113
.rounded(px(8.))
114
.cursor_pointer()
115
.when(active, |button| button.bg(theme::popup_hover()))
116
.hover(|button| button.bg(theme::popup_hover()))
117
.tooltip(move |window, cx| {
118
Tooltip::new(format!("{label} (Ctrl+Shift+F)")).build(window, cx)
119
})
120
.child(icon(
121
IconName::Funnel,
122
16.,
123
if active {
124
theme::accent_text()
125
} else {
126
theme::text_soft()
127
},
128
))
129
.on_click(cx.listener(|this, _, window, cx| this.toggle_filter_box(window, cx)))
130
}
131
132
pub(super) fn filter_bar(&self, cx: &mut Context<Self>) -> impl IntoElement {
133
let input_row = self
134
.filter_input
135
.clone()
136
.filter(|_| self.filter_box_open)
137
.map(|input| self.filter_input_row(&input, cx));
138
v_flex()
139
.debug_selector(|| FILTER_TAG.into())
140
.flex_none()
141
.w_full()
142
.pb(px(8.))
143
.gap(px(8.))
144
.children(input_row)
145
.child(self.filter_pills(cx))
146
}
147
148
fn filter_input_row(&self, input: &Entity<InputState>, cx: &mut Context<Self>) -> Div {
149
let has_text = !self.chat_filter.text.is_empty();
150
h_flex()
151
.debug_selector(|| FILTER_INPUT_TAG.into())
152
.mx(px(SIDE_INSET))
153
.h(px(INPUT_HEIGHT))
154
.flex_none()
155
.pl(px(10.))
156
.pr(px(4.))
157
.gap(px(8.))
158
.items_center()
159
.rounded(px(6.))
160
.bg(theme::surface_raised())
161
.capture_action(cx.listener(|this, _: &Escape, window, cx| {
162
this.close_filter_box(window, cx);
163
cx.stop_propagation();
164
}))
165
.child(icon(IconName::Funnel, 14., theme::text_muted()))
166
.child(
167
div()
168
.flex_1()
169
.min_w_0()
170
.child(Input::new(input).appearance(false).bordered(false)),
171
)
172
.when(has_text, |row| {
173
row.child(
174
div()
175
.id("chat-filter-clear-text")
176
.size(px(PILL_HEIGHT))
177
.flex_none()
178
.flex()
179
.items_center()
180
.justify_center()
181
.rounded(px(6.))
182
.cursor_pointer()
183
.hover(|button| button.bg(theme::popup_hover()))
184
.tooltip(|window, cx| Tooltip::new(CLEAR_FILTER_TEXT).build(window, cx))
185
.child(icon(IconName::X, 14., theme::text_muted()))
186
.on_click(cx.listener(|this, _, window, cx| {
187
this.chat_filter.text.clear();
188
if let Some(input) = &this.filter_input {
189
input.update(cx, |input, cx| {
190
input.set_value("", window, cx);
191
input.focus(window, cx);
192
});
193
}
194
cx.notify();
195
})),
196
)
197
})
198
}
199
200
fn filter_pills(&self, cx: &mut Context<Self>) -> impl IntoElement {
201
let overflow_active = ChatFilterPill::OVERFLOW
202
.iter()
203
.any(|pill| self.chat_filter.has(*pill));
204
let show_overflow = self.more_filters_open || overflow_active;
205
let mut pills: Vec<AnyElement> = ChatFilterPill::PRIMARY
206
.into_iter()
207
.map(|pill| self.filter_pill(pill, cx).into_any_element())
208
.collect();
209
if show_overflow {
210
pills.extend(
211
ChatFilterPill::OVERFLOW
212
.into_iter()
213
.map(|pill| self.filter_pill(pill, cx).into_any_element()),
214
);
215
}
216
if !overflow_active {
217
pills.push(self.more_filters_button(cx).into_any_element());
218
}
219
h_flex()
220
.debug_selector(|| FILTER_PILLS_TAG.into())
221
.px(px(SIDE_INSET))
222
.flex_wrap()
223
.gap(px(6.))
224
.children(pills)
225
}
226
227
fn filter_pill(&self, pill: ChatFilterPill, cx: &mut Context<Self>) -> impl IntoElement {
228
let selected = self.chat_filter.has(pill);
229
let disabled = self.chat_filter.is_disabled(pill);
230
div()
231
.id(ElementId::Name(
232
format!("chat-filter-{}", pill.label()).into(),
233
))
234
.h(px(PILL_HEIGHT))
235
.px(px(12.))
236
.flex()
237
.flex_none()
238
.items_center()
239
.rounded_full()
240
.text_size(px(12.))
241
.when(selected, |chip| {
242
chip.bg(theme::accent()).text_color(theme::on_accent())
243
})
244
.when(!selected && disabled, |chip| {
245
chip.bg(theme::surface_raised())
246
.text_color(theme::text_faint())
247
})
248
.when(!selected && !disabled, |chip| {
249
chip.bg(theme::surface_raised())
250
.text_color(theme::text_soft())
251
.cursor_pointer()
252
.hover(|chip| chip.bg(theme::border_strong()))
253
})
254
.child(pill.label())
255
.when(!disabled, |chip| {
256
chip.on_click(cx.listener(move |this, _, _, cx| this.toggle_pill(pill, cx)))
257
})
258
}
259
260
fn more_filters_button(&self, cx: &mut Context<Self>) -> impl IntoElement {
261
let open = self.more_filters_open;
262
let label = if open { FEWER_FILTERS } else { MORE_FILTERS };
263
div()
264
.id("chat-filter-more")
265
.size(px(PILL_HEIGHT))
266
.flex()
267
.flex_none()
268
.items_center()
269
.justify_center()
270
.rounded_full()
271
.cursor_pointer()
272
.bg(theme::surface_raised())
273
.hover(|chip| chip.bg(theme::border_strong()))
274
.tooltip(move |window, cx| Tooltip::new(label).build(window, cx))
275
.child(icon(
276
if open {
277
IconName::ChevronUp
278
} else {
279
IconName::ChevronDown
280
},
281
14.,
282
theme::text_soft(),
283
))
284
.on_click(cx.listener(|this, _, _, cx| {
285
this.more_filters_open = !this.more_filters_open;
286
cx.notify();
287
}))
288
}
289
290
pub(super) fn filter_empty_state(&self, cx: &mut Context<Self>) -> impl IntoElement {
291
v_flex()
292
.debug_selector(|| FILTER_EMPTY_TAG.into())
293
.w_full()
294
.px(px(SIDE_INSET))
295
.py(px(SIDE_INSET))
296
.gap(px(8.))
297
.items_center()
298
.child(
299
div()
300
.text_size(px(13.))
301
.text_color(theme::text_muted())
302
.child(NO_MATCHES),
303
)
304
.child(
305
div()
306
.id("chat-filter-clear-all")
307
.px(px(8.))
308
.h(px(PILL_HEIGHT))
309
.flex()
310
.items_center()
311
.rounded(px(6.))
312
.cursor_pointer()
313
.text_size(px(12.))
314
.text_color(theme::accent_text())
315
.hover(|button| button.bg(theme::surface_raised()))
316
.child(CLEAR_FILTERS)
317
.on_click(cx.listener(|this, _, window, cx| this.clear_filters(window, cx))),
318
)
319
}
320
}
@@ -0,0 +1,320 @@1
use std::collections::HashSet;2
3
use gpui_kit::assets::IconName;4
use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};5
use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};6
use gpui_kit::prelude::FluentBuilder as _;7
use gpui_kit::*;8
9
use super::{NEW_CHAT_BUTTON_SIZE, SidebarEvent, SidebarTab, SidebarView};10
use crate::app_state::Selection;11
use crate::chat_filter::{12
CLEAR_FILTER_TEXT, CLEAR_FILTERS, CLOSE_FILTER_TEXT, ChatFilterPill, FEWER_FILTERS,13
FILTER_PLACEHOLDER, MORE_FILTERS, NO_MATCHES, SHOW_FILTER_TEXT, mentioned_conversations,14
};15
use crate::theme;16
use crate::views::widgets::icon;17
18
pub const FILTER_TAG: &str = "shell/islands/sidebar/chat-filter";19
pub const FILTER_INPUT_TAG: &str = "shell/islands/sidebar/chat-filter/input";20
pub const FILTER_PILLS_TAG: &str = "shell/islands/sidebar/chat-filter/pills";21
pub const FILTER_EMPTY_TAG: &str = "shell/islands/sidebar/chat-filter-empty";22
const INPUT_HEIGHT: f32 = 32.;23
const PILL_HEIGHT: f32 = 24.;24
const SIDE_INSET: f32 = 16.;25
26
impl SidebarView {27
pub fn toggle_filter_box(&mut self, window: &mut Window, cx: &mut Context<Self>) {28
if self.tab != SidebarTab::Chats {29
self.open_tab(SidebarTab::Chats, cx);30
} else if self.filter_box_open {31
self.close_filter_box(window, cx);32
return;33
}34
self.filter_box_open = true;35
let input = self.filter_input(window, cx);36
input.update(cx, |input, cx| input.focus(window, cx));37
cx.notify();38
}39
40
pub fn toggle_pill(&mut self, pill: ChatFilterPill, cx: &mut Context<Self>) {41
if self.tab != SidebarTab::Chats {42
self.open_tab(SidebarTab::Chats, cx);43
}44
if self.chat_filter.toggle(pill) {45
cx.notify();46
}47
}48
49
pub fn clear_filters(&mut self, window: &mut Window, cx: &mut Context<Self>) {50
self.chat_filter.clear();51
if let Some(input) = &self.filter_input {52
input.update(cx, |input, cx| input.set_value("", window, cx));53
}54
cx.notify();55
}56
57
pub(super) fn mentioned_chats(&self, cx: &App) -> HashSet<String> {58
if !self.chat_filter.has(ChatFilterPill::Mentions) {59
return HashSet::new();60
}61
let activity = self.activity_panel.read(cx).activity();62
mentioned_conversations(activity.read(cx).feed().unread_entries())63
}64
65
pub(super) fn selected_chat_id(&self, cx: &App) -> Option<String> {66
match &self.state.read(cx).selection {67
Some(Selection::Chat(chat_id)) => Some(chat_id.clone()),68
_ => None,69
}70
}71
72
fn close_filter_box(&mut self, window: &mut Window, cx: &mut Context<Self>) {73
self.filter_box_open = false;74
cx.emit(SidebarEvent::RestoreFocus);75
self.chat_filter.text.clear();76
if let Some(input) = &self.filter_input {77
input.update(cx, |input, cx| input.set_value("", window, cx));78
}79
cx.notify();80
}81
82
fn filter_input(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Entity<InputState> {83
if let Some(input) = &self.filter_input {84
return input.clone();85
}86
let input = cx.new(|cx| InputState::new(window, cx).placeholder(FILTER_PLACEHOLDER));87
let subscription = cx.subscribe_in(&input, window, |this, input, event, _, cx| {88
if matches!(event, InputEvent::Change) {89
this.chat_filter.text = input.read(cx).value().to_string();90
cx.notify();91
}92
});93
self.filter_subscription = Some(subscription);94
self.filter_input = Some(input.clone());95
input96
}97
98
pub(super) fn filter_toggle_button(&self, cx: &mut Context<Self>) -> impl IntoElement {99
let open = self.filter_box_open;100
let active = open || self.chat_filter.is_active();101
let label = if open {102
CLOSE_FILTER_TEXT103
} else {104
SHOW_FILTER_TEXT105
};106
div()107
.id("chat-filter-toggle")108
.size(px(NEW_CHAT_BUTTON_SIZE))109
.flex_none()110
.flex()111
.items_center()112
.justify_center()113
.rounded(px(8.))114
.cursor_pointer()115
.when(active, |button| button.bg(theme::popup_hover()))116
.hover(|button| button.bg(theme::popup_hover()))117
.tooltip(move |window, cx| {118
Tooltip::new(format!("{label} (Ctrl+Shift+F)")).build(window, cx)119
})120
.child(icon(121
IconName::Funnel,122
16.,123
if active {124
theme::accent_text()125
} else {126
theme::text_soft()127
},128
))129
.on_click(cx.listener(|this, _, window, cx| this.toggle_filter_box(window, cx)))130
}131
132
pub(super) fn filter_bar(&self, cx: &mut Context<Self>) -> impl IntoElement {133
let input_row = self134
.filter_input135
.clone()136
.filter(|_| self.filter_box_open)137
.map(|input| self.filter_input_row(&input, cx));138
v_flex()139
.debug_selector(|| FILTER_TAG.into())140
.flex_none()141
.w_full()142
.pb(px(8.))143
.gap(px(8.))144
.children(input_row)145
.child(self.filter_pills(cx))146
}147
148
fn filter_input_row(&self, input: &Entity<InputState>, cx: &mut Context<Self>) -> Div {149
let has_text = !self.chat_filter.text.is_empty();150
h_flex()151
.debug_selector(|| FILTER_INPUT_TAG.into())152
.mx(px(SIDE_INSET))153
.h(px(INPUT_HEIGHT))154
.flex_none()155
.pl(px(10.))156
.pr(px(4.))157
.gap(px(8.))158
.items_center()159
.rounded(px(6.))160
.bg(theme::surface_raised())161
.capture_action(cx.listener(|this, _: &Escape, window, cx| {162
this.close_filter_box(window, cx);163
cx.stop_propagation();164
}))165
.child(icon(IconName::Funnel, 14., theme::text_muted()))166
.child(167
div()168
.flex_1()169
.min_w_0()170
.child(Input::new(input).appearance(false).bordered(false)),171
)172
.when(has_text, |row| {173
row.child(174
div()175
.id("chat-filter-clear-text")176
.size(px(PILL_HEIGHT))177
.flex_none()178
.flex()179
.items_center()180
.justify_center()181
.rounded(px(6.))182
.cursor_pointer()183
.hover(|button| button.bg(theme::popup_hover()))184
.tooltip(|window, cx| Tooltip::new(CLEAR_FILTER_TEXT).build(window, cx))185
.child(icon(IconName::X, 14., theme::text_muted()))186
.on_click(cx.listener(|this, _, window, cx| {187
this.chat_filter.text.clear();188
if let Some(input) = &this.filter_input {189
input.update(cx, |input, cx| {190
input.set_value("", window, cx);191
input.focus(window, cx);192
});193
}194
cx.notify();195
})),196
)197
})198
}199
200
fn filter_pills(&self, cx: &mut Context<Self>) -> impl IntoElement {201
let overflow_active = ChatFilterPill::OVERFLOW202
.iter()203
.any(|pill| self.chat_filter.has(*pill));204
let show_overflow = self.more_filters_open || overflow_active;205
let mut pills: Vec<AnyElement> = ChatFilterPill::PRIMARY206
.into_iter()207
.map(|pill| self.filter_pill(pill, cx).into_any_element())208
.collect();209
if show_overflow {210
pills.extend(211
ChatFilterPill::OVERFLOW212
.into_iter()213
.map(|pill| self.filter_pill(pill, cx).into_any_element()),214
);215
}216
if !overflow_active {217
pills.push(self.more_filters_button(cx).into_any_element());218
}219
h_flex()220
.debug_selector(|| FILTER_PILLS_TAG.into())221
.px(px(SIDE_INSET))222
.flex_wrap()223
.gap(px(6.))224
.children(pills)225
}226
227
fn filter_pill(&self, pill: ChatFilterPill, cx: &mut Context<Self>) -> impl IntoElement {228
let selected = self.chat_filter.has(pill);229
let disabled = self.chat_filter.is_disabled(pill);230
div()231
.id(ElementId::Name(232
format!("chat-filter-{}", pill.label()).into(),233
))234
.h(px(PILL_HEIGHT))235
.px(px(12.))236
.flex()237
.flex_none()238
.items_center()239
.rounded_full()240
.text_size(px(12.))241
.when(selected, |chip| {242
chip.bg(theme::accent()).text_color(theme::on_accent())243
})244
.when(!selected && disabled, |chip| {245
chip.bg(theme::surface_raised())246
.text_color(theme::text_faint())247
})248
.when(!selected && !disabled, |chip| {249
chip.bg(theme::surface_raised())250
.text_color(theme::text_soft())251
.cursor_pointer()252
.hover(|chip| chip.bg(theme::border_strong()))253
})254
.child(pill.label())255
.when(!disabled, |chip| {256
chip.on_click(cx.listener(move |this, _, _, cx| this.toggle_pill(pill, cx)))257
})258
}259
260
fn more_filters_button(&self, cx: &mut Context<Self>) -> impl IntoElement {261
let open = self.more_filters_open;262
let label = if open { FEWER_FILTERS } else { MORE_FILTERS };263
div()264
.id("chat-filter-more")265
.size(px(PILL_HEIGHT))266
.flex()267
.flex_none()268
.items_center()269
.justify_center()270
.rounded_full()271
.cursor_pointer()272
.bg(theme::surface_raised())273
.hover(|chip| chip.bg(theme::border_strong()))274
.tooltip(move |window, cx| Tooltip::new(label).build(window, cx))275
.child(icon(276
if open {277
IconName::ChevronUp278
} else {279
IconName::ChevronDown280
},281
14.,282
theme::text_soft(),283
))284
.on_click(cx.listener(|this, _, _, cx| {285
this.more_filters_open = !this.more_filters_open;286
cx.notify();287
}))288
}289
290
pub(super) fn filter_empty_state(&self, cx: &mut Context<Self>) -> impl IntoElement {291
v_flex()292
.debug_selector(|| FILTER_EMPTY_TAG.into())293
.w_full()294
.px(px(SIDE_INSET))295
.py(px(SIDE_INSET))296
.gap(px(8.))297
.items_center()298
.child(299
div()300
.text_size(px(13.))301
.text_color(theme::text_muted())302
.child(NO_MATCHES),303
)304
.child(305
div()306
.id("chat-filter-clear-all")307
.px(px(8.))308
.h(px(PILL_HEIGHT))309
.flex()310
.items_center()311
.rounded(px(6.))312
.cursor_pointer()313
.text_size(px(12.))314
.text_color(theme::accent_text())315
.hover(|button| button.bg(theme::surface_raised()))316
.child(CLEAR_FILTERS)317
.on_click(cx.listener(|this, _, window, cx| this.clear_filters(window, cx))),318
)319
}320
}