Merge remote-tracking branch 'origin/main' into fix/write-path-parity
@@ -2,7 +2,10 @@ use std::collections::{HashMap, HashSet};
2
2
3
3
use app_ui_kit::widgets::Unread;
4
4
use chrono::{DateTime, FixedOffset, Utc};
5
use store::{ChannelRecord, ChatRecord, MessageImportance, Sidebar, SidebarTeam, is_bot_id};
5
use store::{
6
ChannelNotificationLevel, ChannelRecord, ChatRecord, MessageImportance, Sidebar, SidebarTeam,
7
is_bot_id,
8
};
6
9
use teams_core::{ChatSection, is_event_preview};
7
10
8
11
use crate::app_state::chat_title;
@@ -338,10 +341,16 @@ pub fn team_badge(team: &SidebarTeam, expanded: bool) -> Option<MentionBadge> {
338
341
}
339
342
}
340
343
344
pub fn channel_shows_unread(team: &SidebarTeam, channel: &ChannelRecord) -> bool {
345
channel.unread
346
&& (team.channel_notifications(&channel.id).level != ChannelNotificationLevel::Off
347
|| team.channel_mentions(&channel.id).personal > 0)
348
}
349
341
350
pub fn team_has_unread(team: &SidebarTeam) -> bool {
342
351
team.channels
343
352
.iter()
344
.any(|channel| channel.unread && channel_shown(team, &channel.id))
353
.any(|channel| channel_shows_unread(team, channel) && channel_shown(team, &channel.id))
345
354
}
346
355
347
356
pub fn team_name_style(team: &SidebarTeam, expanded: bool) -> NameStyle {
@@ -919,6 +928,28 @@ mod tests {
919
928
assert_eq!(team_name_style(&only_hidden, false), NameStyle::PLAIN);
920
929
}
921
930
931
#[test]
932
fn muted_channel_shows_no_unread_unless_personally_mentioned() {
933
let mut entry = with_unread(team("t1", false, &["a"], &[]), &["a"]);
934
entry.notifications.insert(
935
"a".into(),
936
store::ChannelNotifications {
937
level: ChannelNotificationLevel::Off,
938
include_replies: false,
939
},
940
);
941
assert!(!channel_shows_unread(&entry, &entry.channels[0]));
942
assert_eq!(team_name_style(&entry, false), NameStyle::PLAIN);
943
entry.mentions.insert(
944
"a".into(),
945
store::ChannelMentions {
946
personal: 1,
947
..Default::default()
948
},
949
);
950
assert!(channel_shows_unread(&entry, &entry.channels[0]));
951
}
952
922
953
#[test]
923
954
fn rail_dot_counts_shown_channels_of_shown_teams_only() {
924
955
let sidebar = |teams: Vec<SidebarTeam>| Sidebar {
@@ -2,7 +2,10 @@ use std::collections::{HashMap, HashSet};2
2
3
use app_ui_kit::widgets::Unread;3
use app_ui_kit::widgets::Unread;4
use chrono::{DateTime, FixedOffset, Utc};4
use chrono::{DateTime, FixedOffset, Utc};5
use store::{ChannelRecord, ChatRecord, MessageImportance, Sidebar, SidebarTeam, is_bot_id};5
use store::{6
ChannelNotificationLevel, ChannelRecord, ChatRecord, MessageImportance, Sidebar, SidebarTeam,7
is_bot_id,8
};6
use teams_core::{ChatSection, is_event_preview};9
use teams_core::{ChatSection, is_event_preview};7
10
8
use crate::app_state::chat_title;11
use crate::app_state::chat_title;@@ -338,10 +341,16 @@ pub fn team_badge(team: &SidebarTeam, expanded: bool) -> Option<MentionBadge> {338
}341
}339
}342
}340
343
344
pub fn channel_shows_unread(team: &SidebarTeam, channel: &ChannelRecord) -> bool {345
channel.unread346
&& (team.channel_notifications(&channel.id).level != ChannelNotificationLevel::Off347
|| team.channel_mentions(&channel.id).personal > 0)348
}349
341
pub fn team_has_unread(team: &SidebarTeam) -> bool {350
pub fn team_has_unread(team: &SidebarTeam) -> bool {342
team.channels351
team.channels343
.iter()352
.iter()344
.any(|channel| channel.unread && channel_shown(team, &channel.id))353
.any(|channel| channel_shows_unread(team, channel) && channel_shown(team, &channel.id))345
}354
}346
355
347
pub fn team_name_style(team: &SidebarTeam, expanded: bool) -> NameStyle {356
pub fn team_name_style(team: &SidebarTeam, expanded: bool) -> NameStyle {@@ -919,6 +928,28 @@ mod tests {919
assert_eq!(team_name_style(&only_hidden, false), NameStyle::PLAIN);928
assert_eq!(team_name_style(&only_hidden, false), NameStyle::PLAIN);920
}929
}921
930
931
#[test]932
fn muted_channel_shows_no_unread_unless_personally_mentioned() {933
let mut entry = with_unread(team("t1", false, &["a"], &[]), &["a"]);934
entry.notifications.insert(935
"a".into(),936
store::ChannelNotifications {937
level: ChannelNotificationLevel::Off,938
include_replies: false,939
},940
);941
assert!(!channel_shows_unread(&entry, &entry.channels[0]));942
assert_eq!(team_name_style(&entry, false), NameStyle::PLAIN);943
entry.mentions.insert(944
"a".into(),945
store::ChannelMentions {946
personal: 1,947
..Default::default()948
},949
);950
assert!(channel_shows_unread(&entry, &entry.channels[0]));951
}952
922
#[test]953
#[test]923
fn rail_dot_counts_shown_channels_of_shown_teams_only() {954
fn rail_dot_counts_shown_channels_of_shown_teams_only() {924
let sidebar = |teams: Vec<SidebarTeam>| Sidebar {955
let sidebar = |teams: Vec<SidebarTeam>| Sidebar {@@ -12,7 +12,7 @@ use gpui_kit::prelude::FluentBuilder as _;
12
12
use gpui_kit::*;
13
13
use store::{
14
14
ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,
15
Store, TeamRecord,
15
Store,
16
16
};
17
17
use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat};
18
18
@@ -37,9 +37,9 @@ use crate::notice::truncated;
37
37
use crate::sidebar_model::{
38
38
AvatarSpec, ChannelOrderInput, ChatItem, DELETED_CHAT_PREVIEW, EMPTY_FOLDER_HINT, MentionBadge,
39
39
NameStyle, NameWeight, Preview, Section, SectionInput, SectionKind, Step, build_sections,
40
channel_badge, channel_name_style, channel_shown, older_chats_trigger_resets, step_id,
41
team_badge, team_channel_rows, team_hoisted, team_name_style, visible_channel_ids,
42
wants_older_chats,
40
channel_badge, channel_name_style, channel_shown, channel_shows_unread,
41
older_chats_trigger_resets, step_id, team_badge, team_channel_rows, team_hoisted,
42
team_name_style, visible_channel_ids, wants_older_chats,
43
43
};
44
44
use crate::theme;
45
45
use app_ui_kit::layout::SIDEBAR_WIDTH;
@@ -1419,13 +1419,14 @@ impl SidebarView {
1419
1419
fn channel_row(
1420
1420
&self,
1421
1421
channel_id: &str,
1422
team: &TeamRecord,
1422
entry: &SidebarTeam,
1423
1423
channel: &ChannelRecord,
1424
1424
selected: bool,
1425
notifications: ChannelNotifications,
1426
badge: Option<MentionBadge>,
1427
1425
) -> AnyElement {
1428
let unread = channel.unread;
1426
let team = &entry.team;
1427
let unread = channel_shows_unread(entry, channel);
1428
let notifications = entry.channel_notifications(channel_id);
1429
let badge = channel_badge(entry, channel_id);
1429
1430
let name_style = channel_name_style(unread, true, selected);
1430
1431
let state = self.state.clone();
1431
1432
let menu_state = self.state.clone();
@@ -1600,7 +1601,7 @@ impl SidebarView {
1600
1601
channel,
1601
1602
is_selected(channel),
1602
1603
channel_name_style(
1603
channel.unread,
1604
channel_shows_unread(entry, channel),
1604
1605
channel_shown(entry, &channel.id),
1605
1606
is_selected(channel),
1606
1607
),
@@ -1628,7 +1629,7 @@ impl SidebarView {
1628
1629
list = list.child(self.team_channel_row(
1629
1630
channel,
1630
1631
false,
1631
channel_name_style(channel.unread, false, false),
1632
channel_name_style(channel_shows_unread(entry, channel), false, false),
1632
1633
entry.channel_notifications(&channel.id),
1633
1634
channel_badge(entry, &channel.id),
1634
1635
));
@@ -1764,14 +1765,7 @@ impl SidebarView {
1764
1765
list = list.child(self.plain_header(PINNED_LABEL));
1765
1766
for (entry, channel) in pinned {
1766
1767
let is_selected = selected == Some(Selection::Channel(channel.id.clone()));
1767
list = list.child(self.channel_row(
1768
&channel.id,
1769
&entry.team,
1770
channel,
1771
is_selected,
1772
entry.channel_notifications(&channel.id),
1773
channel_badge(entry, &channel.id),
1774
));
1768
list = list.child(self.channel_row(&channel.id, entry, channel, is_selected));
1775
1769
}
1776
1770
}
1777
1771
list = list.child(self.plain_header(TEAMS_LABEL));
@@ -12,7 +12,7 @@ use gpui_kit::prelude::FluentBuilder as _;12
use gpui_kit::*;12
use gpui_kit::*;13
use store::{13
use store::{14
ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,14
ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam,15
Store, TeamRecord,15
Store,16
};16
};17
use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat};17
use teams_core::{ChatNotificationMode, DesktopNotifications, is_notes_chat};18
18
@@ -37,9 +37,9 @@ use crate::notice::truncated;37
use crate::sidebar_model::{37
use crate::sidebar_model::{38
AvatarSpec, ChannelOrderInput, ChatItem, DELETED_CHAT_PREVIEW, EMPTY_FOLDER_HINT, MentionBadge,38
AvatarSpec, ChannelOrderInput, ChatItem, DELETED_CHAT_PREVIEW, EMPTY_FOLDER_HINT, MentionBadge,39
NameStyle, NameWeight, Preview, Section, SectionInput, SectionKind, Step, build_sections,39
NameStyle, NameWeight, Preview, Section, SectionInput, SectionKind, Step, build_sections,40
channel_badge, channel_name_style, channel_shown, older_chats_trigger_resets, step_id,40
channel_badge, channel_name_style, channel_shown, channel_shows_unread,41
team_badge, team_channel_rows, team_hoisted, team_name_style, visible_channel_ids,41
older_chats_trigger_resets, step_id, team_badge, team_channel_rows, team_hoisted,42
wants_older_chats,42
team_name_style, visible_channel_ids, wants_older_chats,43
};43
};44
use crate::theme;44
use crate::theme;45
use app_ui_kit::layout::SIDEBAR_WIDTH;45
use app_ui_kit::layout::SIDEBAR_WIDTH;@@ -1419,13 +1419,14 @@ impl SidebarView {1419
fn channel_row(1419
fn channel_row(1420
&self,1420
&self,1421
channel_id: &str,1421
channel_id: &str,1422
team: &TeamRecord,1422
entry: &SidebarTeam,1423
channel: &ChannelRecord,1423
channel: &ChannelRecord,1424
selected: bool,1424
selected: bool,1425
notifications: ChannelNotifications,1426
badge: Option<MentionBadge>,1427
) -> AnyElement {1425
) -> AnyElement {1428
let unread = channel.unread;1426
let team = &entry.team;1427
let unread = channel_shows_unread(entry, channel);1428
let notifications = entry.channel_notifications(channel_id);1429
let badge = channel_badge(entry, channel_id);1429
let name_style = channel_name_style(unread, true, selected);1430
let name_style = channel_name_style(unread, true, selected);1430
let state = self.state.clone();1431
let state = self.state.clone();1431
let menu_state = self.state.clone();1432
let menu_state = self.state.clone();@@ -1600,7 +1601,7 @@ impl SidebarView {1600
channel,1601
channel,1601
is_selected(channel),1602
is_selected(channel),1602
channel_name_style(1603
channel_name_style(1603
channel.unread,1604
channel_shows_unread(entry, channel),1604
channel_shown(entry, &channel.id),1605
channel_shown(entry, &channel.id),1605
is_selected(channel),1606
is_selected(channel),1606
),1607
),@@ -1628,7 +1629,7 @@ impl SidebarView {1628
list = list.child(self.team_channel_row(1629
list = list.child(self.team_channel_row(1629
channel,1630
channel,1630
false,1631
false,1631
channel_name_style(channel.unread, false, false),1632
channel_name_style(channel_shows_unread(entry, channel), false, false),1632
entry.channel_notifications(&channel.id),1633
entry.channel_notifications(&channel.id),1633
channel_badge(entry, &channel.id),1634
channel_badge(entry, &channel.id),1634
));1635
));@@ -1764,14 +1765,7 @@ impl SidebarView {1764
list = list.child(self.plain_header(PINNED_LABEL));1765
list = list.child(self.plain_header(PINNED_LABEL));1765
for (entry, channel) in pinned {1766
for (entry, channel) in pinned {1766
let is_selected = selected == Some(Selection::Channel(channel.id.clone()));1767
let is_selected = selected == Some(Selection::Channel(channel.id.clone()));1767
list = list.child(self.channel_row(1768
list = list.child(self.channel_row(&channel.id, entry, channel, is_selected));1768
&channel.id,1769
&entry.team,1770
channel,1771
is_selected,1772
entry.channel_notifications(&channel.id),1773
channel_badge(entry, &channel.id),1774
));1775
}1769
}1776
}1770
}1777
list = list.child(self.plain_header(TEAMS_LABEL));1771
list = list.child(self.plain_header(TEAMS_LABEL));