feat(app): reactions inside the bubble with faces and who reacted
- Pills sit in the bubble's last line next to the time; up to 3 faces, from 4 people a count; your own reaction in the accent color - Right-click on a pill lists who reacted and when, with emoji tabs - Reactions keep their time (created_at) from Graph - Legacy "like" and the emoji form are one pill Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -610,12 +610,22 @@ fn priority_messages() -> Vec<MessageRecord> {
610
610
]
611
611
}
612
612
613
fn reaction(kind: &str, users: &[&str]) -> String {
613
fn reaction(kind: &str, users: &[(&str, &str, DateTime<Utc>)]) -> Vec<serde_json::Value> {
614
614
users
615
615
.iter()
616
.map(|user| format!(r#"{{"reaction_type":"{kind}","user_id":"{user}","user_name":null}}"#))
617
.collect::<Vec<_>>()
618
.join(",")
616
.map(|(user_id, user_name, created_at)| {
617
serde_json::json!({
618
"reaction_type": kind,
619
"user_id": user_id,
620
"user_name": user_name,
621
"created_at": created_at,
622
})
623
})
624
.collect()
625
}
626
627
fn reactions_json(groups: Vec<Vec<serde_json::Value>>) -> String {
628
serde_json::Value::Array(groups.into_iter().flatten().collect()).to_string()
619
629
}
620
630
621
631
fn release_messages() -> Vec<MessageRecord> {
@@ -623,8 +633,50 @@ fn release_messages() -> Vec<MessageRecord> {
623
633
let mara = (MARA_ID, "Mara Lindqvist");
624
634
let jonas = (JONAS_ID, "Jonas Ortega");
625
635
let me = (DEMO_USER_ID, DEMO_USER_NAME);
626
let likes = format!("[{}]", reaction("like", &[JONAS_ID, PRIYA_ID, LEA_ID]));
627
let hearts = format!("[{}]", reaction("heart", &[DEMO_USER_ID, JONAS_ID]));
636
let jonas_name = "Jonas Ortega";
637
let priya_name = "Priya Nair";
638
let lea_name = "Lea Schneider";
639
let mara_name = "Mara Lindqvist";
640
let tobias_name = "Tobias Klein";
641
let likes = reactions_json(vec![reaction(
642
"like",
643
&[
644
(JONAS_ID, jonas_name, at(1, 16, 30)),
645
(PRIYA_ID, priya_name, at(1, 17, 2)),
646
(LEA_ID, lea_name, at(0, 8, 15)),
647
],
648
)]);
649
let hearts = reactions_json(vec![reaction(
650
"heart",
651
&[
652
(DEMO_USER_ID, DEMO_USER_NAME, at(0, 10, 35)),
653
(JONAS_ID, jonas_name, at(0, 10, 33)),
654
],
655
)]);
656
let single = reactions_json(vec![reaction(
657
"laugh",
658
&[(PRIYA_ID, priya_name, at(0, 9, 10))],
659
)]);
660
let many = reactions_json(vec![
661
reaction(
662
"like",
663
&[
664
(MARA_ID, mara_name, at(0, 13, 37)),
665
(JONAS_ID, jonas_name, at(0, 13, 38)),
666
(PRIYA_ID, priya_name, at(0, 13, 40)),
667
(LEA_ID, lea_name, at(0, 13, 45)),
668
(TOBIAS_ID, tobias_name, at(0, 13, 50)),
669
],
670
),
671
reaction(
672
"heart",
673
&[
674
(LEA_ID, lea_name, at(0, 13, 46)),
675
(TOBIAS_ID, tobias_name, at(0, 13, 51)),
676
],
677
),
678
reaction("\u{1F389}", &[(MARA_ID, mara_name, at(0, 13, 39))]),
679
]);
628
680
vec![
629
681
message(
630
682
chat,
@@ -679,7 +731,7 @@ fn release_messages() -> Vec<MessageRecord> {
679
731
me,
680
732
at(0, 9, 2),
681
733
"<p>I'll take the changelog.</p>",
682
"[]",
734
&single,
683
735
false,
684
736
),
685
737
message(
@@ -739,7 +791,7 @@ fn release_messages() -> Vec<MessageRecord> {
739
791
me,
740
792
at(0, 13, 36),
741
793
"<p>Build 42 is green, see <a href=\"https://example.com/build/42\">pipeline</a>.</p>",
742
"[]",
794
&many,
743
795
false,
744
796
),
745
797
]
@@ -610,12 +610,22 @@ fn priority_messages() -> Vec<MessageRecord> {610
]610
]611
}611
}612
612
613
fn reaction(kind: &str, users: &[&str]) -> String {613
fn reaction(kind: &str, users: &[(&str, &str, DateTime<Utc>)]) -> Vec<serde_json::Value> {614
users614
users615
.iter()615
.iter()616
.map(|user| format!(r#"{{"reaction_type":"{kind}","user_id":"{user}","user_name":null}}"#))616
.map(|(user_id, user_name, created_at)| {617
.collect::<Vec<_>>()617
serde_json::json!({618
.join(",")618
"reaction_type": kind,619
"user_id": user_id,620
"user_name": user_name,621
"created_at": created_at,622
})623
})624
.collect()625
}626
627
fn reactions_json(groups: Vec<Vec<serde_json::Value>>) -> String {628
serde_json::Value::Array(groups.into_iter().flatten().collect()).to_string()619
}629
}620
630
621
fn release_messages() -> Vec<MessageRecord> {631
fn release_messages() -> Vec<MessageRecord> {@@ -623,8 +633,50 @@ fn release_messages() -> Vec<MessageRecord> {623
let mara = (MARA_ID, "Mara Lindqvist");633
let mara = (MARA_ID, "Mara Lindqvist");624
let jonas = (JONAS_ID, "Jonas Ortega");634
let jonas = (JONAS_ID, "Jonas Ortega");625
let me = (DEMO_USER_ID, DEMO_USER_NAME);635
let me = (DEMO_USER_ID, DEMO_USER_NAME);626
let likes = format!("[{}]", reaction("like", &[JONAS_ID, PRIYA_ID, LEA_ID]));636
let jonas_name = "Jonas Ortega";627
let hearts = format!("[{}]", reaction("heart", &[DEMO_USER_ID, JONAS_ID]));637
let priya_name = "Priya Nair";638
let lea_name = "Lea Schneider";639
let mara_name = "Mara Lindqvist";640
let tobias_name = "Tobias Klein";641
let likes = reactions_json(vec![reaction(642
"like",643
&[644
(JONAS_ID, jonas_name, at(1, 16, 30)),645
(PRIYA_ID, priya_name, at(1, 17, 2)),646
(LEA_ID, lea_name, at(0, 8, 15)),647
],648
)]);649
let hearts = reactions_json(vec![reaction(650
"heart",651
&[652
(DEMO_USER_ID, DEMO_USER_NAME, at(0, 10, 35)),653
(JONAS_ID, jonas_name, at(0, 10, 33)),654
],655
)]);656
let single = reactions_json(vec![reaction(657
"laugh",658
&[(PRIYA_ID, priya_name, at(0, 9, 10))],659
)]);660
let many = reactions_json(vec![661
reaction(662
"like",663
&[664
(MARA_ID, mara_name, at(0, 13, 37)),665
(JONAS_ID, jonas_name, at(0, 13, 38)),666
(PRIYA_ID, priya_name, at(0, 13, 40)),667
(LEA_ID, lea_name, at(0, 13, 45)),668
(TOBIAS_ID, tobias_name, at(0, 13, 50)),669
],670
),671
reaction(672
"heart",673
&[674
(LEA_ID, lea_name, at(0, 13, 46)),675
(TOBIAS_ID, tobias_name, at(0, 13, 51)),676
],677
),678
reaction("\u{1F389}", &[(MARA_ID, mara_name, at(0, 13, 39))]),679
]);628
vec![680
vec![629
message(681
message(630
chat,682
chat,@@ -679,7 +731,7 @@ fn release_messages() -> Vec<MessageRecord> {679
me,731
me,680
at(0, 9, 2),732
at(0, 9, 2),681
"<p>I'll take the changelog.</p>",733
"<p>I'll take the changelog.</p>",682
"[]",734
&single,683
false,735
false,684
),736
),685
message(737
message(@@ -739,7 +791,7 @@ fn release_messages() -> Vec<MessageRecord> {739
me,791
me,740
at(0, 13, 36),792
at(0, 13, 36),741
"<p>Build 42 is green, see <a href=\"https://example.com/build/42\">pipeline</a>.</p>",793
"<p>Build 42 is green, see <a href=\"https://example.com/build/42\">pipeline</a>.</p>",742
"[]",794
&many,743
false,795
false,744
),796
),745
]797
]@@ -14,6 +14,7 @@ mod format;
14
14
mod frame_log;
15
15
mod fuzzy;
16
16
mod notify;
17
mod reaction_model;
17
18
mod read_state;
18
19
mod render;
19
20
mod rows;
@@ -14,6 +14,7 @@ mod format;14
mod frame_log;14
mod frame_log;15
mod fuzzy;15
mod fuzzy;16
mod notify;16
mod notify;17
mod reaction_model;17
mod read_state;18
mod read_state;18
mod render;19
mod render;19
mod rows;20
mod rows;@@ -0,0 +1,220 @@
1
use std::fmt::Display;
2
3
use chrono::{DateTime, Datelike, TimeZone, Utc};
4
5
use crate::rows::ReactionChip;
6
7
const FACE_LIMIT: usize = 3;
8
const TOOLTIP_NAME_LIMIT: usize = 3;
9
const TOOLTIP_LEAD_NAMES: usize = 2;
10
pub const UNKNOWN_REACTOR: &str = "Unknown";
11
12
#[derive(Debug, Clone, PartialEq, Eq)]
13
pub struct Reactor {
14
pub user_id: Option<String>,
15
pub name: String,
16
pub created_at: Option<DateTime<Utc>>,
17
}
18
19
#[derive(Debug, Clone, PartialEq, Eq)]
20
pub struct ReactionTab {
21
pub glyph: Option<String>,
22
pub label: String,
23
pub count: usize,
24
}
25
26
#[derive(Debug, Clone, PartialEq, Eq)]
27
pub struct ReactionEntry {
28
pub reactor: Reactor,
29
pub label: String,
30
}
31
32
pub fn shows_faces(count: usize) -> bool {
33
(1..=FACE_LIMIT).contains(&count)
34
}
35
36
pub fn tooltip_text(names: &[&str]) -> String {
37
match names {
38
[] => String::new(),
39
[only] => (*only).to_owned(),
40
names if names.len() <= TOOLTIP_NAME_LIMIT => {
41
let (last, lead) = names.split_last().expect("not empty");
42
format!("{} and {last}", lead.join(", "))
43
}
44
names => format!(
45
"{} and {} others",
46
names[..TOOLTIP_LEAD_NAMES].join(", "),
47
names.len() - TOOLTIP_LEAD_NAMES
48
),
49
}
50
}
51
52
pub fn chip_tooltip(chip: &ReactionChip) -> String {
53
let names: Vec<&str> = chip
54
.reactors
55
.iter()
56
.map(|reactor| reactor.name.as_str())
57
.collect();
58
tooltip_text(&names)
59
}
60
61
pub fn reaction_time_label<Zone>(time: DateTime<Utc>, now: &DateTime<Zone>) -> String
62
where
63
Zone: TimeZone,
64
Zone::Offset: Display,
65
{
66
let local = time.with_timezone(&now.timezone());
67
let day = local.date_naive();
68
let today = now.date_naive();
69
let clock = local.format("%H:%M");
70
if day == today {
71
format!("today at {clock}")
72
} else if today.pred_opt() == Some(day) {
73
format!("yesterday at {clock}")
74
} else if day.year() == today.year() {
75
format!("{} at {clock}", local.format("%b %-d"))
76
} else {
77
format!("{} at {clock}", local.format("%b %-d, %Y"))
78
}
79
}
80
81
pub fn reaction_tabs(chips: &[ReactionChip]) -> Vec<ReactionTab> {
82
if chips.len() < 2 {
83
return Vec::new();
84
}
85
let total = chips.iter().map(|chip| chip.reactors.len()).sum();
86
std::iter::once(ReactionTab {
87
glyph: None,
88
label: "All".to_owned(),
89
count: total,
90
})
91
.chain(chips.iter().map(|chip| ReactionTab {
92
glyph: Some(chip.glyph()),
93
label: chip.label.clone(),
94
count: chip.reactors.len(),
95
}))
96
.collect()
97
}
98
99
pub fn reaction_entries(chips: &[ReactionChip], tab: Option<&str>) -> Vec<ReactionEntry> {
100
let mut entries: Vec<ReactionEntry> = chips
101
.iter()
102
.filter(|chip| tab.is_none_or(|glyph| chip.glyph() == glyph))
103
.flat_map(|chip| {
104
chip.reactors.iter().map(|reactor| ReactionEntry {
105
reactor: reactor.clone(),
106
label: chip.label.clone(),
107
})
108
})
109
.collect();
110
entries.sort_by_key(|entry| std::cmp::Reverse(entry.reactor.created_at));
111
entries
112
}
113
114
#[cfg(test)]
115
mod tests {
116
use chrono::{Duration, FixedOffset};
117
118
use super::*;
119
120
fn reactor(name: &str, created_at: Option<DateTime<Utc>>) -> Reactor {
121
Reactor {
122
user_id: None,
123
name: name.to_owned(),
124
created_at,
125
}
126
}
127
128
fn chip(reaction_type: &str, reactors: Vec<Reactor>) -> ReactionChip {
129
ReactionChip {
130
reaction_type: reaction_type.to_owned(),
131
label: crate::rows::reaction_label(reaction_type),
132
count: reactors.len(),
133
mine: false,
134
reactors,
135
}
136
}
137
138
fn utc(day: u32, hour: u32, minute: u32) -> DateTime<Utc> {
139
Utc.with_ymd_and_hms(2026, 10, day, hour, minute, 0)
140
.unwrap()
141
}
142
143
#[test]
144
fn faces_show_up_to_three_people_then_a_count() {
145
assert!(!shows_faces(0));
146
assert!(shows_faces(1));
147
assert!(shows_faces(3));
148
assert!(!shows_faces(4));
149
}
150
151
#[test]
152
fn tooltip_lists_names_then_others() {
153
assert_eq!(tooltip_text(&["Priya Nair"]), "Priya Nair");
154
assert_eq!(tooltip_text(&["Priya Nair", "Lea"]), "Priya Nair and Lea");
155
assert_eq!(tooltip_text(&["A", "B", "C"]), "A, B and C");
156
assert_eq!(
157
tooltip_text(&["Jonas Ortega", "Tobias Klein", "C", "D", "E"]),
158
"Jonas Ortega, Tobias Klein and 3 others"
159
);
160
}
161
162
#[test]
163
fn time_label_reads_today_yesterday_or_date() {
164
let now = FixedOffset::east_opt(0)
165
.unwrap()
166
.with_ymd_and_hms(2026, 10, 8, 12, 0, 0)
167
.unwrap();
168
assert_eq!(reaction_time_label(utc(8, 1, 5), &now), "today at 01:05");
169
assert_eq!(
170
reaction_time_label(utc(7, 17, 31), &now),
171
"yesterday at 17:31"
172
);
173
assert_eq!(reaction_time_label(utc(4, 17, 31), &now), "Oct 4 at 17:31");
174
}
175
176
#[test]
177
fn tabs_appear_only_for_several_kinds() {
178
let one = vec![chip("like", vec![reactor("A", None)])];
179
assert!(reaction_tabs(&one).is_empty());
180
let two = vec![
181
chip("like", vec![reactor("A", None), reactor("B", None)]),
182
chip("heart", vec![reactor("C", None)]),
183
];
184
let tabs = reaction_tabs(&two);
185
assert_eq!(tabs.len(), 3);
186
assert_eq!((tabs[0].glyph.clone(), tabs[0].count), (None, 3));
187
assert_eq!(tabs[1].count, 2);
188
assert_eq!(tabs[2].count, 1);
189
}
190
191
#[test]
192
fn entries_are_newest_first_and_filtered_by_tab() {
193
let chips = vec![
194
chip(
195
"like",
196
vec![
197
reactor("old", Some(utc(1, 9, 0))),
198
reactor("none", None),
199
reactor("new", Some(utc(1, 9, 0) + Duration::hours(2))),
200
],
201
),
202
chip("heart", vec![reactor("mid", Some(utc(1, 10, 0)))]),
203
];
204
let names = |entries: Vec<ReactionEntry>| -> Vec<String> {
205
entries
206
.into_iter()
207
.map(|entry| entry.reactor.name)
208
.collect()
209
};
210
assert_eq!(
211
names(reaction_entries(&chips, None)),
212
["new", "mid", "old", "none"]
213
);
214
let like = chips[0].glyph();
215
assert_eq!(
216
names(reaction_entries(&chips, Some(&like))),
217
["new", "old", "none"]
218
);
219
}
220
}
@@ -0,0 +1,220 @@1
use std::fmt::Display;2
3
use chrono::{DateTime, Datelike, TimeZone, Utc};4
5
use crate::rows::ReactionChip;6
7
const FACE_LIMIT: usize = 3;8
const TOOLTIP_NAME_LIMIT: usize = 3;9
const TOOLTIP_LEAD_NAMES: usize = 2;10
pub const UNKNOWN_REACTOR: &str = "Unknown";11
12
#[derive(Debug, Clone, PartialEq, Eq)]13
pub struct Reactor {14
pub user_id: Option<String>,15
pub name: String,16
pub created_at: Option<DateTime<Utc>>,17
}18
19
#[derive(Debug, Clone, PartialEq, Eq)]20
pub struct ReactionTab {21
pub glyph: Option<String>,22
pub label: String,23
pub count: usize,24
}25
26
#[derive(Debug, Clone, PartialEq, Eq)]27
pub struct ReactionEntry {28
pub reactor: Reactor,29
pub label: String,30
}31
32
pub fn shows_faces(count: usize) -> bool {33
(1..=FACE_LIMIT).contains(&count)34
}35
36
pub fn tooltip_text(names: &[&str]) -> String {37
match names {38
[] => String::new(),39
[only] => (*only).to_owned(),40
names if names.len() <= TOOLTIP_NAME_LIMIT => {41
let (last, lead) = names.split_last().expect("not empty");42
format!("{} and {last}", lead.join(", "))43
}44
names => format!(45
"{} and {} others",46
names[..TOOLTIP_LEAD_NAMES].join(", "),47
names.len() - TOOLTIP_LEAD_NAMES48
),49
}50
}51
52
pub fn chip_tooltip(chip: &ReactionChip) -> String {53
let names: Vec<&str> = chip54
.reactors55
.iter()56
.map(|reactor| reactor.name.as_str())57
.collect();58
tooltip_text(&names)59
}60
61
pub fn reaction_time_label<Zone>(time: DateTime<Utc>, now: &DateTime<Zone>) -> String62
where63
Zone: TimeZone,64
Zone::Offset: Display,65
{66
let local = time.with_timezone(&now.timezone());67
let day = local.date_naive();68
let today = now.date_naive();69
let clock = local.format("%H:%M");70
if day == today {71
format!("today at {clock}")72
} else if today.pred_opt() == Some(day) {73
format!("yesterday at {clock}")74
} else if day.year() == today.year() {75
format!("{} at {clock}", local.format("%b %-d"))76
} else {77
format!("{} at {clock}", local.format("%b %-d, %Y"))78
}79
}80
81
pub fn reaction_tabs(chips: &[ReactionChip]) -> Vec<ReactionTab> {82
if chips.len() < 2 {83
return Vec::new();84
}85
let total = chips.iter().map(|chip| chip.reactors.len()).sum();86
std::iter::once(ReactionTab {87
glyph: None,88
label: "All".to_owned(),89
count: total,90
})91
.chain(chips.iter().map(|chip| ReactionTab {92
glyph: Some(chip.glyph()),93
label: chip.label.clone(),94
count: chip.reactors.len(),95
}))96
.collect()97
}98
99
pub fn reaction_entries(chips: &[ReactionChip], tab: Option<&str>) -> Vec<ReactionEntry> {100
let mut entries: Vec<ReactionEntry> = chips101
.iter()102
.filter(|chip| tab.is_none_or(|glyph| chip.glyph() == glyph))103
.flat_map(|chip| {104
chip.reactors.iter().map(|reactor| ReactionEntry {105
reactor: reactor.clone(),106
label: chip.label.clone(),107
})108
})109
.collect();110
entries.sort_by_key(|entry| std::cmp::Reverse(entry.reactor.created_at));111
entries112
}113
114
#[cfg(test)]115
mod tests {116
use chrono::{Duration, FixedOffset};117
118
use super::*;119
120
fn reactor(name: &str, created_at: Option<DateTime<Utc>>) -> Reactor {121
Reactor {122
user_id: None,123
name: name.to_owned(),124
created_at,125
}126
}127
128
fn chip(reaction_type: &str, reactors: Vec<Reactor>) -> ReactionChip {129
ReactionChip {130
reaction_type: reaction_type.to_owned(),131
label: crate::rows::reaction_label(reaction_type),132
count: reactors.len(),133
mine: false,134
reactors,135
}136
}137
138
fn utc(day: u32, hour: u32, minute: u32) -> DateTime<Utc> {139
Utc.with_ymd_and_hms(2026, 10, day, hour, minute, 0)140
.unwrap()141
}142
143
#[test]144
fn faces_show_up_to_three_people_then_a_count() {145
assert!(!shows_faces(0));146
assert!(shows_faces(1));147
assert!(shows_faces(3));148
assert!(!shows_faces(4));149
}150
151
#[test]152
fn tooltip_lists_names_then_others() {153
assert_eq!(tooltip_text(&["Priya Nair"]), "Priya Nair");154
assert_eq!(tooltip_text(&["Priya Nair", "Lea"]), "Priya Nair and Lea");155
assert_eq!(tooltip_text(&["A", "B", "C"]), "A, B and C");156
assert_eq!(157
tooltip_text(&["Jonas Ortega", "Tobias Klein", "C", "D", "E"]),158
"Jonas Ortega, Tobias Klein and 3 others"159
);160
}161
162
#[test]163
fn time_label_reads_today_yesterday_or_date() {164
let now = FixedOffset::east_opt(0)165
.unwrap()166
.with_ymd_and_hms(2026, 10, 8, 12, 0, 0)167
.unwrap();168
assert_eq!(reaction_time_label(utc(8, 1, 5), &now), "today at 01:05");169
assert_eq!(170
reaction_time_label(utc(7, 17, 31), &now),171
"yesterday at 17:31"172
);173
assert_eq!(reaction_time_label(utc(4, 17, 31), &now), "Oct 4 at 17:31");174
}175
176
#[test]177
fn tabs_appear_only_for_several_kinds() {178
let one = vec![chip("like", vec![reactor("A", None)])];179
assert!(reaction_tabs(&one).is_empty());180
let two = vec![181
chip("like", vec![reactor("A", None), reactor("B", None)]),182
chip("heart", vec![reactor("C", None)]),183
];184
let tabs = reaction_tabs(&two);185
assert_eq!(tabs.len(), 3);186
assert_eq!((tabs[0].glyph.clone(), tabs[0].count), (None, 3));187
assert_eq!(tabs[1].count, 2);188
assert_eq!(tabs[2].count, 1);189
}190
191
#[test]192
fn entries_are_newest_first_and_filtered_by_tab() {193
let chips = vec![194
chip(195
"like",196
vec![197
reactor("old", Some(utc(1, 9, 0))),198
reactor("none", None),199
reactor("new", Some(utc(1, 9, 0) + Duration::hours(2))),200
],201
),202
chip("heart", vec![reactor("mid", Some(utc(1, 10, 0)))]),203
];204
let names = |entries: Vec<ReactionEntry>| -> Vec<String> {205
entries206
.into_iter()207
.map(|entry| entry.reactor.name)208
.collect()209
};210
assert_eq!(211
names(reaction_entries(&chips, None)),212
["new", "mid", "old", "none"]213
);214
let like = chips[0].glyph();215
assert_eq!(216
names(reaction_entries(&chips, Some(&like))),217
["new", "old", "none"]218
);219
}220
}@@ -1,4 +1,4 @@
1
use std::collections::BTreeMap;
1
use std::collections::{BTreeMap, HashMap};
2
2
use std::ops::Range;
3
3
use std::sync::Arc;
4
4
@@ -8,6 +8,7 @@ use store::MessageRecord;
8
8
use teams_core::{FileCard, ImageRef, ReactionInfo, Span, files, images, message_spans, reactions};
9
9
10
10
use crate::format;
11
use crate::reaction_model::{Reactor, UNKNOWN_REACTOR};
11
12
use crate::render::blocks::{Inline, strip_image_placeholders};
12
13
use crate::render::{Block, layout_blocks};
13
14
use crate::sidebar_model::Face;
@@ -27,6 +28,13 @@ pub struct ReactionChip {
27
28
pub label: String,
28
29
pub count: usize,
29
30
pub mine: bool,
31
pub reactors: Vec<Reactor>,
32
}
33
34
impl ReactionChip {
35
pub fn glyph(&self) -> String {
36
reaction_glyph(&self.reaction_type)
37
}
30
38
}
31
39
32
40
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
@@ -290,29 +298,47 @@ pub fn reaction_type_for(glyph: &str) -> String {
290
298
.map_or_else(|| bare.to_owned(), str::to_owned)
291
299
}
292
300
293
pub fn reaction_chips(reactions: &[ReactionInfo], my_user_id: Option<&str>) -> Vec<ReactionChip> {
294
let mut counts: BTreeMap<&str, usize> = BTreeMap::new();
295
let mut mine: BTreeMap<&str, bool> = BTreeMap::new();
296
let mut order: Vec<&str> = Vec::new();
301
pub fn reaction_chips(reactions: &[ReactionInfo], context: &RowContext) -> Vec<ReactionChip> {
302
let my_user_id = context.my_user_id.as_deref();
303
let mut chips: Vec<ReactionChip> = Vec::new();
297
304
for reaction in reactions {
298
let entry = counts.entry(reaction.reaction_type.as_str()).or_insert(0);
299
if *entry == 0 {
300
order.push(reaction.reaction_type.as_str());
301
}
302
*entry += 1;
303
if my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id {
304
mine.insert(reaction.reaction_type.as_str(), true);
305
}
305
let glyph = reaction_glyph(&reaction.reaction_type);
306
let position = match chips.iter().position(|chip| chip.glyph() == glyph) {
307
Some(position) => position,
308
None => {
309
chips.push(ReactionChip {
310
reaction_type: reaction.reaction_type.clone(),
311
label: reaction_label(&reaction.reaction_type),
312
count: 0,
313
mine: false,
314
reactors: Vec::new(),
315
});
316
chips.len() - 1
317
}
318
};
319
let chip = &mut chips[position];
320
chip.count += 1;
321
chip.mine |= my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id;
322
chip.reactors.push(Reactor {
323
user_id: reaction.user_id.clone(),
324
name: reactor_name(reaction, context),
325
created_at: reaction.created_at,
326
});
306
327
}
307
order
308
.into_iter()
309
.map(|reaction_type| ReactionChip {
310
reaction_type: reaction_type.to_owned(),
311
label: reaction_label(reaction_type),
312
count: counts[reaction_type],
313
mine: mine.contains_key(reaction_type),
328
chips
329
}
330
331
fn reactor_name(reaction: &ReactionInfo, context: &RowContext) -> String {
332
reaction
333
.user_name
334
.clone()
335
.or_else(|| {
336
reaction
337
.user_id
338
.as_ref()
339
.and_then(|user_id| context.names.get(user_id).cloned())
314
340
})
315
.collect()
341
.unwrap_or_else(|| UNKNOWN_REACTOR.to_owned())
316
342
}
317
343
318
344
const REPLY_EXCERPT_CHARS: usize = 90;
@@ -359,6 +385,7 @@ pub struct RowContext {
359
385
pub offset: FixedOffset,
360
386
pub today: NaiveDate,
361
387
pub my_user_id: Option<String>,
388
pub names: HashMap<String, String>,
362
389
}
363
390
364
391
pub fn message_row(record: &MessageRecord, context: &RowContext) -> MessageRow {
@@ -389,7 +416,7 @@ pub fn message_row(record: &MessageRecord, context: &RowContext) -> MessageRow {
389
416
blocks,
390
417
edited: record.edited_at.is_some() && !record.deleted,
391
418
deleted: record.deleted,
392
reactions: reaction_chips(&reactions(record), context.my_user_id.as_deref()),
419
reactions: reaction_chips(&reactions(record), context),
393
420
images,
394
421
local_images: Vec::new(),
395
422
files: files(record),
@@ -643,6 +670,7 @@ mod tests {
643
670
offset: FixedOffset::east_opt(0).unwrap(),
644
671
today: NaiveDate::from_ymd_opt(2026, 10, 7).unwrap(),
645
672
my_user_id: None,
673
names: HashMap::new(),
646
674
}
647
675
}
648
676
@@ -731,16 +759,45 @@ mod tests {
731
759
reaction_type: kind.into(),
732
760
user_id: None,
733
761
user_name: None,
762
created_at: None,
734
763
};
735
764
let chips = reaction_chips(
736
765
&[reaction("heart"), reaction("like"), reaction("heart")],
737
None,
766
&context(),
738
767
);
739
768
assert_eq!(chips.len(), 2);
740
769
assert_eq!(chips[0].count, 2);
741
770
assert_eq!(chips[1].label, reaction_label("like"));
742
771
}
743
772
773
#[test]
774
fn legacy_and_emoji_reactions_share_a_chip() {
775
let reaction = |kind: &str| ReactionInfo {
776
reaction_type: kind.into(),
777
user_id: None,
778
user_name: Some("Lea".into()),
779
created_at: None,
780
};
781
let chips = reaction_chips(&[reaction("like"), reaction("\u{1F44D}")], &context());
782
assert_eq!(chips.len(), 1);
783
assert_eq!(chips[0].count, 2);
784
}
785
786
#[test]
787
fn reactor_name_falls_back_to_directory_then_unknown() {
788
let reaction = |user: &str| ReactionInfo {
789
reaction_type: "like".into(),
790
user_id: Some(user.into()),
791
user_name: None,
792
created_at: None,
793
};
794
let mut context = context();
795
context.names.insert("known".into(), "Priya Nair".into());
796
let chips = reaction_chips(&[reaction("known"), reaction("other")], &context);
797
assert_eq!(chips[0].reactors[0].name, "Priya Nair");
798
assert_eq!(chips[0].reactors[1].name, "Unknown");
799
}
800
744
801
fn record_by(id: &str, sender: &str, hour: u32, minute: u32, day: u32) -> MessageRecord {
745
802
let mut record = record(id, None, hour, day);
746
803
record.sender_id = Some(sender.into());
@@ -848,10 +905,13 @@ mod tests {
848
905
reaction_type: "like".into(),
849
906
user_id: Some(user.into()),
850
907
user_name: None,
908
created_at: None,
851
909
};
852
let chips = reaction_chips(&[reaction("x"), reaction("me")], Some("me"));
910
let mut context = context();
911
context.my_user_id = Some("me".into());
912
let chips = reaction_chips(&[reaction("x"), reaction("me")], &context);
853
913
assert!(chips[0].mine);
854
assert!(!reaction_chips(&[reaction("x")], Some("me"))[0].mine);
914
assert!(!reaction_chips(&[reaction("x")], &context)[0].mine);
855
915
}
856
916
857
917
fn strings(values: &[&str]) -> Vec<String> {
@@ -1,4 +1,4 @@1
use std::collections::BTreeMap;1
use std::collections::{BTreeMap, HashMap};2
use std::ops::Range;2
use std::ops::Range;3
use std::sync::Arc;3
use std::sync::Arc;4
4
@@ -8,6 +8,7 @@ use store::MessageRecord;8
use teams_core::{FileCard, ImageRef, ReactionInfo, Span, files, images, message_spans, reactions};8
use teams_core::{FileCard, ImageRef, ReactionInfo, Span, files, images, message_spans, reactions};9
9
10
use crate::format;10
use crate::format;11
use crate::reaction_model::{Reactor, UNKNOWN_REACTOR};11
use crate::render::blocks::{Inline, strip_image_placeholders};12
use crate::render::blocks::{Inline, strip_image_placeholders};12
use crate::render::{Block, layout_blocks};13
use crate::render::{Block, layout_blocks};13
use crate::sidebar_model::Face;14
use crate::sidebar_model::Face;@@ -27,6 +28,13 @@ pub struct ReactionChip {27
pub label: String,28
pub label: String,28
pub count: usize,29
pub count: usize,29
pub mine: bool,30
pub mine: bool,31
pub reactors: Vec<Reactor>,32
}33
34
impl ReactionChip {35
pub fn glyph(&self) -> String {36
reaction_glyph(&self.reaction_type)37
}30
}38
}31
39
32
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]40
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]@@ -290,29 +298,47 @@ pub fn reaction_type_for(glyph: &str) -> String {290
.map_or_else(|| bare.to_owned(), str::to_owned)298
.map_or_else(|| bare.to_owned(), str::to_owned)291
}299
}292
300
293
pub fn reaction_chips(reactions: &[ReactionInfo], my_user_id: Option<&str>) -> Vec<ReactionChip> {301
pub fn reaction_chips(reactions: &[ReactionInfo], context: &RowContext) -> Vec<ReactionChip> {294
let mut counts: BTreeMap<&str, usize> = BTreeMap::new();302
let my_user_id = context.my_user_id.as_deref();295
let mut mine: BTreeMap<&str, bool> = BTreeMap::new();303
let mut chips: Vec<ReactionChip> = Vec::new();296
let mut order: Vec<&str> = Vec::new();297
for reaction in reactions {304
for reaction in reactions {298
let entry = counts.entry(reaction.reaction_type.as_str()).or_insert(0);305
let glyph = reaction_glyph(&reaction.reaction_type);299
if *entry == 0 {306
let position = match chips.iter().position(|chip| chip.glyph() == glyph) {300
order.push(reaction.reaction_type.as_str());307
Some(position) => position,301
}308
None => {302
*entry += 1;309
chips.push(ReactionChip {303
if my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id {310
reaction_type: reaction.reaction_type.clone(),304
mine.insert(reaction.reaction_type.as_str(), true);311
label: reaction_label(&reaction.reaction_type),305
}312
count: 0,313
mine: false,314
reactors: Vec::new(),315
});316
chips.len() - 1317
}318
};319
let chip = &mut chips[position];320
chip.count += 1;321
chip.mine |= my_user_id.is_some() && reaction.user_id.as_deref() == my_user_id;322
chip.reactors.push(Reactor {323
user_id: reaction.user_id.clone(),324
name: reactor_name(reaction, context),325
created_at: reaction.created_at,326
});306
}327
}307
order328
chips308
.into_iter()329
}309
.map(|reaction_type| ReactionChip {330
310
reaction_type: reaction_type.to_owned(),331
fn reactor_name(reaction: &ReactionInfo, context: &RowContext) -> String {311
label: reaction_label(reaction_type),332
reaction312
count: counts[reaction_type],333
.user_name313
mine: mine.contains_key(reaction_type),334
.clone()335
.or_else(|| {336
reaction337
.user_id338
.as_ref()339
.and_then(|user_id| context.names.get(user_id).cloned())314
})340
})315
.collect()341
.unwrap_or_else(|| UNKNOWN_REACTOR.to_owned())316
}342
}317
343
318
const REPLY_EXCERPT_CHARS: usize = 90;344
const REPLY_EXCERPT_CHARS: usize = 90;@@ -359,6 +385,7 @@ pub struct RowContext {359
pub offset: FixedOffset,385
pub offset: FixedOffset,360
pub today: NaiveDate,386
pub today: NaiveDate,361
pub my_user_id: Option<String>,387
pub my_user_id: Option<String>,388
pub names: HashMap<String, String>,362
}389
}363
390
364
pub fn message_row(record: &MessageRecord, context: &RowContext) -> MessageRow {391
pub fn message_row(record: &MessageRecord, context: &RowContext) -> MessageRow {@@ -389,7 +416,7 @@ pub fn message_row(record: &MessageRecord, context: &RowContext) -> MessageRow {389
blocks,416
blocks,390
edited: record.edited_at.is_some() && !record.deleted,417
edited: record.edited_at.is_some() && !record.deleted,391
deleted: record.deleted,418
deleted: record.deleted,392
reactions: reaction_chips(&reactions(record), context.my_user_id.as_deref()),419
reactions: reaction_chips(&reactions(record), context),393
images,420
images,394
local_images: Vec::new(),421
local_images: Vec::new(),395
files: files(record),422
files: files(record),@@ -643,6 +670,7 @@ mod tests {643
offset: FixedOffset::east_opt(0).unwrap(),670
offset: FixedOffset::east_opt(0).unwrap(),644
today: NaiveDate::from_ymd_opt(2026, 10, 7).unwrap(),671
today: NaiveDate::from_ymd_opt(2026, 10, 7).unwrap(),645
my_user_id: None,672
my_user_id: None,673
names: HashMap::new(),646
}674
}647
}675
}648
676
@@ -731,16 +759,45 @@ mod tests {731
reaction_type: kind.into(),759
reaction_type: kind.into(),732
user_id: None,760
user_id: None,733
user_name: None,761
user_name: None,762
created_at: None,734
};763
};735
let chips = reaction_chips(764
let chips = reaction_chips(736
&[reaction("heart"), reaction("like"), reaction("heart")],765
&[reaction("heart"), reaction("like"), reaction("heart")],737
None,766
&context(),738
);767
);739
assert_eq!(chips.len(), 2);768
assert_eq!(chips.len(), 2);740
assert_eq!(chips[0].count, 2);769
assert_eq!(chips[0].count, 2);741
assert_eq!(chips[1].label, reaction_label("like"));770
assert_eq!(chips[1].label, reaction_label("like"));742
}771
}743
772
773
#[test]774
fn legacy_and_emoji_reactions_share_a_chip() {775
let reaction = |kind: &str| ReactionInfo {776
reaction_type: kind.into(),777
user_id: None,778
user_name: Some("Lea".into()),779
created_at: None,780
};781
let chips = reaction_chips(&[reaction("like"), reaction("\u{1F44D}")], &context());782
assert_eq!(chips.len(), 1);783
assert_eq!(chips[0].count, 2);784
}785
786
#[test]787
fn reactor_name_falls_back_to_directory_then_unknown() {788
let reaction = |user: &str| ReactionInfo {789
reaction_type: "like".into(),790
user_id: Some(user.into()),791
user_name: None,792
created_at: None,793
};794
let mut context = context();795
context.names.insert("known".into(), "Priya Nair".into());796
let chips = reaction_chips(&[reaction("known"), reaction("other")], &context);797
assert_eq!(chips[0].reactors[0].name, "Priya Nair");798
assert_eq!(chips[0].reactors[1].name, "Unknown");799
}800
744
fn record_by(id: &str, sender: &str, hour: u32, minute: u32, day: u32) -> MessageRecord {801
fn record_by(id: &str, sender: &str, hour: u32, minute: u32, day: u32) -> MessageRecord {745
let mut record = record(id, None, hour, day);802
let mut record = record(id, None, hour, day);746
record.sender_id = Some(sender.into());803
record.sender_id = Some(sender.into());@@ -848,10 +905,13 @@ mod tests {848
reaction_type: "like".into(),905
reaction_type: "like".into(),849
user_id: Some(user.into()),906
user_id: Some(user.into()),850
user_name: None,907
user_name: None,908
created_at: None,851
};909
};852
let chips = reaction_chips(&[reaction("x"), reaction("me")], Some("me"));910
let mut context = context();911
context.my_user_id = Some("me".into());912
let chips = reaction_chips(&[reaction("x"), reaction("me")], &context);853
assert!(chips[0].mine);913
assert!(chips[0].mine);854
assert!(!reaction_chips(&[reaction("x")], Some("me"))[0].mine);914
assert!(!reaction_chips(&[reaction("x")], &context)[0].mine);855
}915
}856
916
857
fn strings(values: &[&str]) -> Vec<String> {917
fn strings(values: &[&str]) -> Vec<String> {@@ -27,10 +27,11 @@ const TEXT_FAINT: u32 = 0x8e8e93;
27
27
const ACCENT: u32 = 0xce6a3b;
28
28
const ACCENT_TEXT: u32 = 0xe08a5c;
29
29
const ACCENT_SOFT: u32 = 0xf5c4a5;
30
const ACCENT_TINT: u32 = 0xf5c4a5;
31
30
const ACCENT_STRONG: u32 = 0xa84f27;
32
31
const BUBBLE_OWN: u32 = 0x4f2a1b;
33
32
const BUBBLE_OTHER: u32 = 0x232325;
33
const REACTION_ON_OWN: u32 = 0x6b3a26;
34
const WHITE: u32 = 0xffffff;
34
35
const MENTION_BACKGROUND: u32 = 0x3a2a23;
35
36
const MENTION_BACKGROUND_OWN: u32 = 0x3b1d11;
36
37
const OWN_META: u32 = 0xc9a28c;
@@ -199,10 +200,6 @@ pub fn accent_soft() -> Hsla {
199
200
color(ACCENT_SOFT)
200
201
}
201
202
202
pub fn accent_tint() -> Hsla {
203
color(ACCENT_TINT)
204
}
205
206
203
pub fn on_accent() -> Hsla {
207
204
color(BACKGROUND)
208
205
}
@@ -215,6 +212,14 @@ pub fn bubble_other() -> Hsla {
215
212
color(BUBBLE_OTHER)
216
213
}
217
214
215
pub fn reaction_on_own() -> Hsla {
216
color(REACTION_ON_OWN)
217
}
218
219
pub fn white() -> Hsla {
220
color(WHITE)
221
}
222
218
223
pub fn mention_background(own: bool) -> Hsla {
219
224
color(if own {
220
225
MENTION_BACKGROUND_OWN
@@ -27,10 +27,11 @@ const TEXT_FAINT: u32 = 0x8e8e93;27
const ACCENT: u32 = 0xce6a3b;27
const ACCENT: u32 = 0xce6a3b;28
const ACCENT_TEXT: u32 = 0xe08a5c;28
const ACCENT_TEXT: u32 = 0xe08a5c;29
const ACCENT_SOFT: u32 = 0xf5c4a5;29
const ACCENT_SOFT: u32 = 0xf5c4a5;30
const ACCENT_TINT: u32 = 0xf5c4a5;31
const ACCENT_STRONG: u32 = 0xa84f27;30
const ACCENT_STRONG: u32 = 0xa84f27;32
const BUBBLE_OWN: u32 = 0x4f2a1b;31
const BUBBLE_OWN: u32 = 0x4f2a1b;33
const BUBBLE_OTHER: u32 = 0x232325;32
const BUBBLE_OTHER: u32 = 0x232325;33
const REACTION_ON_OWN: u32 = 0x6b3a26;34
const WHITE: u32 = 0xffffff;34
const MENTION_BACKGROUND: u32 = 0x3a2a23;35
const MENTION_BACKGROUND: u32 = 0x3a2a23;35
const MENTION_BACKGROUND_OWN: u32 = 0x3b1d11;36
const MENTION_BACKGROUND_OWN: u32 = 0x3b1d11;36
const OWN_META: u32 = 0xc9a28c;37
const OWN_META: u32 = 0xc9a28c;@@ -199,10 +200,6 @@ pub fn accent_soft() -> Hsla {199
color(ACCENT_SOFT)200
color(ACCENT_SOFT)200
}201
}201
202
202
pub fn accent_tint() -> Hsla {203
color(ACCENT_TINT)204
}205
206
pub fn on_accent() -> Hsla {203
pub fn on_accent() -> Hsla {207
color(BACKGROUND)204
color(BACKGROUND)208
}205
}@@ -215,6 +212,14 @@ pub fn bubble_other() -> Hsla {215
color(BUBBLE_OTHER)212
color(BUBBLE_OTHER)216
}213
}217
214
215
pub fn reaction_on_own() -> Hsla {216
color(REACTION_ON_OWN)217
}218
219
pub fn white() -> Hsla {220
color(WHITE)221
}222
218
pub fn mention_background(own: bool) -> Hsla {223
pub fn mention_background(own: bool) -> Hsla {219
color(if own {224
color(if own {220
MENTION_BACKGROUND_OWN225
MENTION_BACKGROUND_OWN@@ -23,9 +23,11 @@ use super::message_actions::{Action, MessageMenu};
23
23
use super::message_row::{RowActions, render_message_row, render_skeleton_row};
24
24
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};
25
25
use super::reaction_picker::{PickHandler, ReactionPicker};
26
use super::reaction_pills::{ReactionControls, ReactionPopover};
26
27
use super::widgets::{icon, symbol};
27
28
use crate::app_state::{AppEvent, AppState, Selection, selection_title};
28
29
use crate::data::{is_one_on_one, others};
30
use crate::reaction_model::UNKNOWN_REACTOR;
29
31
use crate::read_state::{ReadTrigger, plan_read};
30
32
use crate::render::Block;
31
33
use crate::render::blocks::Inline;
@@ -102,6 +104,12 @@ struct Current {
102
104
sync: SyncProgress,
103
105
}
104
106
107
struct ReactionDetails {
108
message_key: String,
109
anchor_glyph: String,
110
tab: Option<String>,
111
}
112
105
113
pub struct ConversationView {
106
114
app: Entity<AppState>,
107
115
scroller: Entity<MessageScrollerState>,
@@ -119,6 +127,7 @@ pub struct ConversationView {
119
127
toolbar_hovered: Option<String>,
120
128
toolbar_pinned: Option<String>,
121
129
picker: Entity<ReactionPicker>,
130
reaction_details: Option<ReactionDetails>,
122
131
highlighted_message: Option<String>,
123
132
notice: Option<String>,
124
133
drag_file_count: usize,
@@ -180,6 +189,11 @@ impl ConversationView {
180
189
cx.subscribe_in(&composer, window, Self::on_composer_event),
181
190
cx.subscribe_in(&draft, window, Self::on_draft_event),
182
191
cx.observe_window_activation(window, Self::on_window_activation),
192
cx.observe_keystrokes(|this, event, _, cx| {
193
if event.keystroke.key == "escape" {
194
this.close_reaction_details(cx);
195
}
196
}),
183
197
];
184
198
let mut view = ConversationView {
185
199
app,
@@ -198,6 +212,7 @@ impl ConversationView {
198
212
toolbar_hovered: None,
199
213
toolbar_pinned: None,
200
214
picker,
215
reaction_details: None,
201
216
highlighted_message: None,
202
217
notice: None,
203
218
drag_file_count: 0,
@@ -237,6 +252,7 @@ impl ConversationView {
237
252
) {
238
253
match event {
239
254
AppEvent::Selection => {
255
self.reaction_details = None;
240
256
let (new_chat, selection) = {
241
257
let state = self.app.read(cx);
242
258
(state.new_chat, state.selection.clone())
@@ -284,9 +300,13 @@ impl ConversationView {
284
300
}
285
301
self.start_fetch(cx)
286
302
}
287
AppEvent::Directory => cx.notify(),
303
AppEvent::Directory => {
304
self.refresh_reactor_names(cx);
305
cx.notify();
306
}
288
307
AppEvent::Sidebar => {
289
308
self.mark_read(ReadTrigger::Incoming, cx);
309
self.refresh_reactor_names(cx);
290
310
if self.draft_active {
291
311
self.on_draft_changed(window, cx);
292
312
} else if let Some(current) = self.current.as_mut() {
@@ -650,10 +670,132 @@ impl ConversationView {
650
670
651
671
fn row_context(&self, cx: &App) -> RowContext {
652
672
let now = Local::now();
673
let app = self.app.read(cx);
674
let mut names: HashMap<String, String> = HashMap::new();
675
let known_people = app
676
.directory
677
.me
678
.iter()
679
.map(|me| (me.user_id.clone(), me.display_name.clone()))
680
.chain(
681
app.sidebar
682
.chats
683
.iter()
684
.flat_map(|chat| chat.members.iter())
685
.filter_map(|member| {
686
Some((member.user_id.clone()?, member.display_name.clone()))
687
}),
688
);
689
for (user_id, name) in known_people {
690
names.entry(user_id).or_insert(name);
691
}
653
692
RowContext {
654
693
offset: now.offset().fix(),
655
694
today: now.date_naive(),
656
my_user_id: self.app.read(cx).store.meta(META_USER_ID).ok().flatten(),
695
my_user_id: app.store.meta(META_USER_ID).ok().flatten(),
696
names,
697
}
698
}
699
700
fn unknown_reactor_ids(&self) -> Vec<String> {
701
self.rows
702
.borrow()
703
.iter()
704
.filter_map(|row| match row {
705
Row::Message(message) => Some(message),
706
_ => None,
707
})
708
.flat_map(|message| message.reactions.iter())
709
.flat_map(|chip| chip.reactors.iter())
710
.filter(|reactor| reactor.name == UNKNOWN_REACTOR)
711
.filter_map(|reactor| reactor.user_id.clone())
712
.collect()
713
}
714
715
fn refresh_reactor_names(&mut self, cx: &mut Context<Self>) {
716
if self.current.is_none() {
717
return;
718
}
719
let unknown = self.unknown_reactor_ids();
720
if unknown.is_empty() {
721
return;
722
}
723
let names = self.row_context(cx).names;
724
if unknown.iter().any(|user_id| names.contains_key(user_id)) {
725
self.rebuild(false, cx);
726
}
727
}
728
729
fn drop_stale_reaction_details(&mut self) {
730
let Some(details) = self.reaction_details.as_ref() else {
731
return;
732
};
733
let present = self.rows.borrow().iter().any(|row| {
734
matches!(row, Row::Message(message) if message.key == details.message_key
735
&& message.reactions.iter().any(|chip| chip.glyph() == details.anchor_glyph))
736
});
737
if !present {
738
self.reaction_details = None;
739
}
740
}
741
742
fn open_reaction_details(&mut self, message_key: &str, glyph: &str, cx: &mut Context<Self>) {
743
let multiple_kinds = self.rows.borrow().iter().any(|row| {
744
matches!(row, Row::Message(message) if message.key == message_key && message.reactions.len() > 1)
745
});
746
self.reaction_details = Some(ReactionDetails {
747
message_key: message_key.to_owned(),
748
anchor_glyph: glyph.to_owned(),
749
tab: multiple_kinds.then(|| glyph.to_owned()),
750
});
751
cx.notify();
752
}
753
754
fn select_reaction_tab(&mut self, tab: Option<String>, cx: &mut Context<Self>) {
755
if let Some(details) = self.reaction_details.as_mut() {
756
details.tab = tab;
757
cx.notify();
758
}
759
}
760
761
fn close_reaction_details(&mut self, cx: &mut Context<Self>) {
762
if self.reaction_details.take().is_some() {
763
cx.notify();
764
}
765
}
766
767
fn reaction_controls(&self, key: &str, view: WeakEntity<Self>) -> ReactionControls {
768
let open = {
769
let (view, key) = (view.clone(), key.to_owned());
770
Rc::new(move |glyph: &str, cx: &mut App| {
771
view.update(cx, |this, cx| this.open_reaction_details(&key, glyph, cx))
772
.ok();
773
})
774
};
775
let select_tab = {
776
let view = view.clone();
777
Rc::new(move |tab: Option<String>, cx: &mut App| {
778
view.update(cx, |this, cx| this.select_reaction_tab(tab, cx))
779
.ok();
780
})
781
};
782
let close = Rc::new(move |cx: &mut App| {
783
view.update(cx, |this, cx| this.close_reaction_details(cx))
784
.ok();
785
});
786
let popover = self
787
.reaction_details
788
.as_ref()
789
.filter(|details| details.message_key == key)
790
.map(|details| ReactionPopover {
791
anchor_glyph: details.anchor_glyph.clone(),
792
tab: details.tab.clone(),
793
});
794
ReactionControls {
795
open,
796
select_tab,
797
close,
798
popover,
657
799
}
658
800
}
659
801
@@ -706,7 +848,15 @@ impl ConversationView {
706
848
.ok()
707
849
.flatten()
708
850
.is_none_or(|state| state.has_more);
709
let context = self.row_context(cx);
851
let mut context = self.row_context(cx);
852
for record in &records {
853
if let (Some(user_id), Some(name)) = (&record.sender_id, &record.sender_name) {
854
context
855
.names
856
.entry(user_id.clone())
857
.or_insert_with(|| name.clone());
858
}
859
}
710
860
let can_load_older = self.app.read(cx).engine.is_some();
711
861
let start = self.start_info(cx);
712
862
let current = self.current.as_mut().expect("checked above");
@@ -772,6 +922,7 @@ impl ConversationView {
772
922
773
923
fn apply_rows(&mut self, new_rows: Vec<Row>, reset: bool, cx: &mut Context<Self>) {
774
924
let old_rows = std::mem::replace(&mut *self.rows.borrow_mut(), new_rows);
925
self.drop_stale_reaction_details();
775
926
let new_len = self.rows.borrow().len();
776
927
if reset {
777
928
let marker_index = self
@@ -1584,6 +1735,7 @@ impl ConversationView {
1584
1735
reaction_type: reaction_type.clone(),
1585
1736
user_id: my_user_id.clone(),
1586
1737
user_name: Some("You".to_owned()),
1738
created_at: Some(Utc::now()),
1587
1739
});
1588
1740
}
1589
1741
record.reactions_json = serde_json::to_string(&reactions).unwrap_or_default();
@@ -2147,14 +2299,23 @@ impl Render for ConversationView {
2147
2299
.ok();
2148
2300
}) as Box<dyn Fn(&mut App)>
2149
2301
});
2150
let sender = (!message.own && !message.series.has_prev)
2302
let senders: Vec<String> = (!message.own && !message.series.has_prev)
2151
2303
.then(|| message.sender_id.clone())
2152
2304
.flatten()
2153
.filter(|sender| app.read(cx).directory.avatar(sender).is_none());
2154
if let Some(sender) = sender {
2305
.into_iter()
2306
.chain(
2307
message
2308
.reactions
2309
.iter()
2310
.flat_map(|chip| chip.reactors.iter())
2311
.filter_map(|reactor| reactor.user_id.clone()),
2312
)
2313
.filter(|sender| app.read(cx).directory.avatar(sender).is_none())
2314
.collect();
2315
if !senders.is_empty() {
2155
2316
let app = app.clone();
2156
2317
cx.defer(move |cx| {
2157
app.update(cx, |state, cx| state.request_avatars(vec![sender], cx));
2318
app.update(cx, |state, cx| state.request_avatars(senders, cx));
2158
2319
});
2159
2320
}
2160
2321
let missing_images: Vec<ImageRef> = message
@@ -2182,7 +2343,7 @@ impl Render for ConversationView {
2182
2343
}) as Rc<dyn Fn(bool, &mut App)>
2183
2344
});
2184
2345
let actionable = is_real && !message.deleted && !message.card;
2185
let (menu, react) = view
2346
let (menu, react, reaction_controls) = view
2186
2347
.upgrade()
2187
2348
.filter(|_| actionable)
2188
2349
.map(|entity| {
@@ -2191,9 +2352,11 @@ impl Render for ConversationView {
2191
2352
this.message_menu(&message.key, message.own, view.clone());
2192
2353
let react = menu.react.clone();
2193
2354
let visible = this.toolbar_visible(&message.key);
2194
(visible.then_some(menu), Some(react))
2355
let controls = (!message.reactions.is_empty())
2356
.then(|| this.reaction_controls(&message.key, view.clone()));
2357
(visible.then_some(menu), Some(react), controls)
2195
2358
})
2196
.unwrap_or((None, None));
2359
.unwrap_or((None, None, None));
2197
2360
let reply = (is_real && !message.deleted).then(|| {
2198
2361
let (view, key, handle) =
2199
2362
(view.clone(), message.key.clone(), window.window_handle());
@@ -2220,6 +2383,7 @@ impl Render for ConversationView {
2220
2383
hovered,
2221
2384
menu,
2222
2385
react,
2386
reaction_controls,
2223
2387
highlighted: highlighted.as_deref() == Some(message.key.as_str()),
2224
2388
},
2225
2389
&state.directory,
@@ -2336,11 +2500,25 @@ impl Render for ConversationView {
2336
2500
.relative()
2337
2501
.flex_1()
2338
2502
.min_h_0()
2339
.child(div().flex_1().min_h_0().child(body))
2503
.child(
2504
div()
2505
.flex_1()
2506
.min_h_0()
2507
.on_scroll_wheel(
2508
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),
2509
)
2510
.child(body),
2511
)
2340
2512
.children(self.render_draft_error(cx))
2341
2513
.child(self.composer.clone())
2342
2514
.child(self.render_drop_overlay(cx)),
2343
2515
)
2516
.capture_action(cx.listener(|this, _: &Escape, _, cx| {
2517
if this.reaction_details.is_some() {
2518
this.close_reaction_details(cx);
2519
cx.stop_propagation();
2520
}
2521
}))
2344
2522
.when(drafting, |root| {
2345
2523
root.on_action(cx.listener(|this, _: &Escape, window, cx| {
2346
2524
if this.draft.read(cx).has_focus(window, cx) {
@@ -23,9 +23,11 @@ use super::message_actions::{Action, MessageMenu};23
use super::message_row::{RowActions, render_message_row, render_skeleton_row};23
use super::message_row::{RowActions, render_message_row, render_skeleton_row};24
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};24
use super::new_chat::{NewChatDraft, NewChatEvent, composer_placeholder, existing_one_on_one};25
use super::reaction_picker::{PickHandler, ReactionPicker};25
use super::reaction_picker::{PickHandler, ReactionPicker};26
use super::reaction_pills::{ReactionControls, ReactionPopover};26
use super::widgets::{icon, symbol};27
use super::widgets::{icon, symbol};27
use crate::app_state::{AppEvent, AppState, Selection, selection_title};28
use crate::app_state::{AppEvent, AppState, Selection, selection_title};28
use crate::data::{is_one_on_one, others};29
use crate::data::{is_one_on_one, others};30
use crate::reaction_model::UNKNOWN_REACTOR;29
use crate::read_state::{ReadTrigger, plan_read};31
use crate::read_state::{ReadTrigger, plan_read};30
use crate::render::Block;32
use crate::render::Block;31
use crate::render::blocks::Inline;33
use crate::render::blocks::Inline;@@ -102,6 +104,12 @@ struct Current {102
sync: SyncProgress,104
sync: SyncProgress,103
}105
}104
106
107
struct ReactionDetails {108
message_key: String,109
anchor_glyph: String,110
tab: Option<String>,111
}112
105
pub struct ConversationView {113
pub struct ConversationView {106
app: Entity<AppState>,114
app: Entity<AppState>,107
scroller: Entity<MessageScrollerState>,115
scroller: Entity<MessageScrollerState>,@@ -119,6 +127,7 @@ pub struct ConversationView {119
toolbar_hovered: Option<String>,127
toolbar_hovered: Option<String>,120
toolbar_pinned: Option<String>,128
toolbar_pinned: Option<String>,121
picker: Entity<ReactionPicker>,129
picker: Entity<ReactionPicker>,130
reaction_details: Option<ReactionDetails>,122
highlighted_message: Option<String>,131
highlighted_message: Option<String>,123
notice: Option<String>,132
notice: Option<String>,124
drag_file_count: usize,133
drag_file_count: usize,@@ -180,6 +189,11 @@ impl ConversationView {180
cx.subscribe_in(&composer, window, Self::on_composer_event),189
cx.subscribe_in(&composer, window, Self::on_composer_event),181
cx.subscribe_in(&draft, window, Self::on_draft_event),190
cx.subscribe_in(&draft, window, Self::on_draft_event),182
cx.observe_window_activation(window, Self::on_window_activation),191
cx.observe_window_activation(window, Self::on_window_activation),192
cx.observe_keystrokes(|this, event, _, cx| {193
if event.keystroke.key == "escape" {194
this.close_reaction_details(cx);195
}196
}),183
];197
];184
let mut view = ConversationView {198
let mut view = ConversationView {185
app,199
app,@@ -198,6 +212,7 @@ impl ConversationView {198
toolbar_hovered: None,212
toolbar_hovered: None,199
toolbar_pinned: None,213
toolbar_pinned: None,200
picker,214
picker,215
reaction_details: None,201
highlighted_message: None,216
highlighted_message: None,202
notice: None,217
notice: None,203
drag_file_count: 0,218
drag_file_count: 0,@@ -237,6 +252,7 @@ impl ConversationView {237
) {252
) {238
match event {253
match event {239
AppEvent::Selection => {254
AppEvent::Selection => {255
self.reaction_details = None;240
let (new_chat, selection) = {256
let (new_chat, selection) = {241
let state = self.app.read(cx);257
let state = self.app.read(cx);242
(state.new_chat, state.selection.clone())258
(state.new_chat, state.selection.clone())@@ -284,9 +300,13 @@ impl ConversationView {284
}300
}285
self.start_fetch(cx)301
self.start_fetch(cx)286
}302
}287
AppEvent::Directory => cx.notify(),303
AppEvent::Directory => {304
self.refresh_reactor_names(cx);305
cx.notify();306
}288
AppEvent::Sidebar => {307
AppEvent::Sidebar => {289
self.mark_read(ReadTrigger::Incoming, cx);308
self.mark_read(ReadTrigger::Incoming, cx);309
self.refresh_reactor_names(cx);290
if self.draft_active {310
if self.draft_active {291
self.on_draft_changed(window, cx);311
self.on_draft_changed(window, cx);292
} else if let Some(current) = self.current.as_mut() {312
} else if let Some(current) = self.current.as_mut() {@@ -650,10 +670,132 @@ impl ConversationView {650
670
651
fn row_context(&self, cx: &App) -> RowContext {671
fn row_context(&self, cx: &App) -> RowContext {652
let now = Local::now();672
let now = Local::now();673
let app = self.app.read(cx);674
let mut names: HashMap<String, String> = HashMap::new();675
let known_people = app676
.directory677
.me678
.iter()679
.map(|me| (me.user_id.clone(), me.display_name.clone()))680
.chain(681
app.sidebar682
.chats683
.iter()684
.flat_map(|chat| chat.members.iter())685
.filter_map(|member| {686
Some((member.user_id.clone()?, member.display_name.clone()))687
}),688
);689
for (user_id, name) in known_people {690
names.entry(user_id).or_insert(name);691
}653
RowContext {692
RowContext {654
offset: now.offset().fix(),693
offset: now.offset().fix(),655
today: now.date_naive(),694
today: now.date_naive(),656
my_user_id: self.app.read(cx).store.meta(META_USER_ID).ok().flatten(),695
my_user_id: app.store.meta(META_USER_ID).ok().flatten(),696
names,697
}698
}699
700
fn unknown_reactor_ids(&self) -> Vec<String> {701
self.rows702
.borrow()703
.iter()704
.filter_map(|row| match row {705
Row::Message(message) => Some(message),706
_ => None,707
})708
.flat_map(|message| message.reactions.iter())709
.flat_map(|chip| chip.reactors.iter())710
.filter(|reactor| reactor.name == UNKNOWN_REACTOR)711
.filter_map(|reactor| reactor.user_id.clone())712
.collect()713
}714
715
fn refresh_reactor_names(&mut self, cx: &mut Context<Self>) {716
if self.current.is_none() {717
return;718
}719
let unknown = self.unknown_reactor_ids();720
if unknown.is_empty() {721
return;722
}723
let names = self.row_context(cx).names;724
if unknown.iter().any(|user_id| names.contains_key(user_id)) {725
self.rebuild(false, cx);726
}727
}728
729
fn drop_stale_reaction_details(&mut self) {730
let Some(details) = self.reaction_details.as_ref() else {731
return;732
};733
let present = self.rows.borrow().iter().any(|row| {734
matches!(row, Row::Message(message) if message.key == details.message_key735
&& message.reactions.iter().any(|chip| chip.glyph() == details.anchor_glyph))736
});737
if !present {738
self.reaction_details = None;739
}740
}741
742
fn open_reaction_details(&mut self, message_key: &str, glyph: &str, cx: &mut Context<Self>) {743
let multiple_kinds = self.rows.borrow().iter().any(|row| {744
matches!(row, Row::Message(message) if message.key == message_key && message.reactions.len() > 1)745
});746
self.reaction_details = Some(ReactionDetails {747
message_key: message_key.to_owned(),748
anchor_glyph: glyph.to_owned(),749
tab: multiple_kinds.then(|| glyph.to_owned()),750
});751
cx.notify();752
}753
754
fn select_reaction_tab(&mut self, tab: Option<String>, cx: &mut Context<Self>) {755
if let Some(details) = self.reaction_details.as_mut() {756
details.tab = tab;757
cx.notify();758
}759
}760
761
fn close_reaction_details(&mut self, cx: &mut Context<Self>) {762
if self.reaction_details.take().is_some() {763
cx.notify();764
}765
}766
767
fn reaction_controls(&self, key: &str, view: WeakEntity<Self>) -> ReactionControls {768
let open = {769
let (view, key) = (view.clone(), key.to_owned());770
Rc::new(move |glyph: &str, cx: &mut App| {771
view.update(cx, |this, cx| this.open_reaction_details(&key, glyph, cx))772
.ok();773
})774
};775
let select_tab = {776
let view = view.clone();777
Rc::new(move |tab: Option<String>, cx: &mut App| {778
view.update(cx, |this, cx| this.select_reaction_tab(tab, cx))779
.ok();780
})781
};782
let close = Rc::new(move |cx: &mut App| {783
view.update(cx, |this, cx| this.close_reaction_details(cx))784
.ok();785
});786
let popover = self787
.reaction_details788
.as_ref()789
.filter(|details| details.message_key == key)790
.map(|details| ReactionPopover {791
anchor_glyph: details.anchor_glyph.clone(),792
tab: details.tab.clone(),793
});794
ReactionControls {795
open,796
select_tab,797
close,798
popover,657
}799
}658
}800
}659
801
@@ -706,7 +848,15 @@ impl ConversationView {706
.ok()848
.ok()707
.flatten()849
.flatten()708
.is_none_or(|state| state.has_more);850
.is_none_or(|state| state.has_more);709
let context = self.row_context(cx);851
let mut context = self.row_context(cx);852
for record in &records {853
if let (Some(user_id), Some(name)) = (&record.sender_id, &record.sender_name) {854
context855
.names856
.entry(user_id.clone())857
.or_insert_with(|| name.clone());858
}859
}710
let can_load_older = self.app.read(cx).engine.is_some();860
let can_load_older = self.app.read(cx).engine.is_some();711
let start = self.start_info(cx);861
let start = self.start_info(cx);712
let current = self.current.as_mut().expect("checked above");862
let current = self.current.as_mut().expect("checked above");@@ -772,6 +922,7 @@ impl ConversationView {772
922
773
fn apply_rows(&mut self, new_rows: Vec<Row>, reset: bool, cx: &mut Context<Self>) {923
fn apply_rows(&mut self, new_rows: Vec<Row>, reset: bool, cx: &mut Context<Self>) {774
let old_rows = std::mem::replace(&mut *self.rows.borrow_mut(), new_rows);924
let old_rows = std::mem::replace(&mut *self.rows.borrow_mut(), new_rows);925
self.drop_stale_reaction_details();775
let new_len = self.rows.borrow().len();926
let new_len = self.rows.borrow().len();776
if reset {927
if reset {777
let marker_index = self928
let marker_index = self@@ -1584,6 +1735,7 @@ impl ConversationView {1584
reaction_type: reaction_type.clone(),1735
reaction_type: reaction_type.clone(),1585
user_id: my_user_id.clone(),1736
user_id: my_user_id.clone(),1586
user_name: Some("You".to_owned()),1737
user_name: Some("You".to_owned()),1738
created_at: Some(Utc::now()),1587
});1739
});1588
}1740
}1589
record.reactions_json = serde_json::to_string(&reactions).unwrap_or_default();1741
record.reactions_json = serde_json::to_string(&reactions).unwrap_or_default();@@ -2147,14 +2299,23 @@ impl Render for ConversationView {2147
.ok();2299
.ok();2148
}) as Box<dyn Fn(&mut App)>2300
}) as Box<dyn Fn(&mut App)>2149
});2301
});2150
let sender = (!message.own && !message.series.has_prev)2302
let senders: Vec<String> = (!message.own && !message.series.has_prev)2151
.then(|| message.sender_id.clone())2303
.then(|| message.sender_id.clone())2152
.flatten()2304
.flatten()2153
.filter(|sender| app.read(cx).directory.avatar(sender).is_none());2305
.into_iter()2154
if let Some(sender) = sender {2306
.chain(2307
message2308
.reactions2309
.iter()2310
.flat_map(|chip| chip.reactors.iter())2311
.filter_map(|reactor| reactor.user_id.clone()),2312
)2313
.filter(|sender| app.read(cx).directory.avatar(sender).is_none())2314
.collect();2315
if !senders.is_empty() {2155
let app = app.clone();2316
let app = app.clone();2156
cx.defer(move |cx| {2317
cx.defer(move |cx| {2157
app.update(cx, |state, cx| state.request_avatars(vec![sender], cx));2318
app.update(cx, |state, cx| state.request_avatars(senders, cx));2158
});2319
});2159
}2320
}2160
let missing_images: Vec<ImageRef> = message2321
let missing_images: Vec<ImageRef> = message@@ -2182,7 +2343,7 @@ impl Render for ConversationView {2182
}) as Rc<dyn Fn(bool, &mut App)>2343
}) as Rc<dyn Fn(bool, &mut App)>2183
});2344
});2184
let actionable = is_real && !message.deleted && !message.card;2345
let actionable = is_real && !message.deleted && !message.card;2185
let (menu, react) = view2346
let (menu, react, reaction_controls) = view2186
.upgrade()2347
.upgrade()2187
.filter(|_| actionable)2348
.filter(|_| actionable)2188
.map(|entity| {2349
.map(|entity| {@@ -2191,9 +2352,11 @@ impl Render for ConversationView {2191
this.message_menu(&message.key, message.own, view.clone());2352
this.message_menu(&message.key, message.own, view.clone());2192
let react = menu.react.clone();2353
let react = menu.react.clone();2193
let visible = this.toolbar_visible(&message.key);2354
let visible = this.toolbar_visible(&message.key);2194
(visible.then_some(menu), Some(react))2355
let controls = (!message.reactions.is_empty())2356
.then(|| this.reaction_controls(&message.key, view.clone()));2357
(visible.then_some(menu), Some(react), controls)2195
})2358
})2196
.unwrap_or((None, None));2359
.unwrap_or((None, None, None));2197
let reply = (is_real && !message.deleted).then(|| {2360
let reply = (is_real && !message.deleted).then(|| {2198
let (view, key, handle) =2361
let (view, key, handle) =2199
(view.clone(), message.key.clone(), window.window_handle());2362
(view.clone(), message.key.clone(), window.window_handle());@@ -2220,6 +2383,7 @@ impl Render for ConversationView {2220
hovered,2383
hovered,2221
menu,2384
menu,2222
react,2385
react,2386
reaction_controls,2223
highlighted: highlighted.as_deref() == Some(message.key.as_str()),2387
highlighted: highlighted.as_deref() == Some(message.key.as_str()),2224
},2388
},2225
&state.directory,2389
&state.directory,@@ -2336,11 +2500,25 @@ impl Render for ConversationView {2336
.relative()2500
.relative()2337
.flex_1()2501
.flex_1()2338
.min_h_0()2502
.min_h_0()2339
.child(div().flex_1().min_h_0().child(body))2503
.child(2504
div()2505
.flex_1()2506
.min_h_0()2507
.on_scroll_wheel(2508
cx.listener(|this, _, _, cx| this.close_reaction_details(cx)),2509
)2510
.child(body),2511
)2340
.children(self.render_draft_error(cx))2512
.children(self.render_draft_error(cx))2341
.child(self.composer.clone())2513
.child(self.composer.clone())2342
.child(self.render_drop_overlay(cx)),2514
.child(self.render_drop_overlay(cx)),2343
)2515
)2516
.capture_action(cx.listener(|this, _: &Escape, _, cx| {2517
if this.reaction_details.is_some() {2518
this.close_reaction_details(cx);2519
cx.stop_propagation();2520
}2521
}))2344
.when(drafting, |root| {2522
.when(drafting, |root| {2345
root.on_action(cx.listener(|this, _: &Escape, window, cx| {2523
root.on_action(cx.listener(|this, _: &Escape, window, cx| {2346
if this.draft.read(cx).has_focus(window, cx) {2524
if this.draft.read(cx).has_focus(window, cx) {@@ -1,5 +1,5 @@
1
1
use gpui_kit::assets::IconName;
2
use gpui_kit::base::{GlobalState, TextSelection};
2
use gpui_kit::base::TextSelection;
3
3
use gpui_kit::component::{h_flex, v_flex};
4
4
use gpui_kit::prelude::FluentBuilder as _;
5
5
use gpui_kit::*;
@@ -9,10 +9,11 @@ use super::attachments::attachments_view;
9
9
use super::avatar::{member_stack, person_avatar};
10
10
use super::message_actions::{HoverChange, MessageMenu, message_toolbar};
11
11
use super::reaction_picker::PickHandler;
12
use super::reaction_pills::{ReactionControls, reaction_pills};
12
13
use super::widgets::{icon, symbol};
13
14
use crate::data::Directory;
14
15
use crate::render::{Block, render_blocks};
15
use crate::rows::{Delivery, MessageRow, ReactionChip, Receipt, Skeleton, bubble_corners};
16
use crate::rows::{Delivery, MessageRow, Receipt, Skeleton, bubble_corners};
16
17
use crate::sidebar_model::DELETED_PREVIEW;
17
18
use crate::theme;
18
19
@@ -24,7 +25,7 @@ const SERIES_START_GAP: f32 = 8.;
24
25
const BODY_SIZE: f32 = 13.5;
25
26
const MAX_WIDTH_RATIO: f32 = 0.7;
26
27
const SENDING_OPACITY: f32 = 0.6;
27
const REACTION_OVERHANG: f32 = 12.;
28
const REACTION_FOOTER_HEIGHT: f32 = 24.;
28
29
const CARD_AVATAR_SIZE: f32 = 32.;
29
30
const CARD_GAP: f32 = 12.;
30
31
const META_SIZE: f32 = 11.;
@@ -40,47 +41,12 @@ pub struct RowActions {
40
41
pub hovered: Option<HoverChange>,
41
42
pub menu: Option<MessageMenu>,
42
43
pub react: Option<PickHandler>,
44
pub reaction_controls: Option<ReactionControls>,
43
45
pub highlighted: bool,
44
46
}
45
47
46
48
const TOOLBAR_LIFT: f32 = 22.;
47
49
48
fn reaction_chip(chip: &ReactionChip, index: usize, react: Option<PickHandler>) -> Stateful<Div> {
49
let (background, border, foreground) = if chip.mine {
50
(theme::bubble_own(), theme::accent(), theme::accent_tint())
51
} else {
52
(theme::surface(), theme::border_strong(), theme::text_soft())
53
};
54
let glyph = chip.label.clone();
55
h_flex()
56
.id(ElementId::Name(
57
format!("reaction-{index}-{}", chip.reaction_type).into(),
58
))
59
.h(px(22.))
60
.px(px(8.))
61
.gap(px(4.))
62
.items_center()
63
.rounded(px(11.))
64
.bg(background)
65
.border_1()
66
.border_color(border)
67
.text_size(px(12.))
68
.text_color(foreground)
69
.child(chip.label.clone())
70
.child(chip.count.to_string())
71
.when_some(react, |chip, react| {
72
chip.cursor_pointer()
73
.hover(|chip| chip.border_color(theme::accent()))
74
.on_mouse_down(MouseButton::Left, |_, _, cx| {
75
GlobalState::suppress_text_selection(cx)
76
})
77
.on_click(move |_, window, cx| {
78
cx.stop_propagation();
79
react(&glyph, window, cx);
80
})
81
})
82
}
83
84
50
fn labeled_divider(label: &str, line_color: Hsla, text_color: Hsla) -> Div {
85
51
h_flex()
86
52
.w_full()
@@ -148,12 +114,14 @@ fn bubble(
148
114
})
149
115
.when(row.delivery == Delivery::Sending, |bubble| {
150
116
bubble.opacity(SENDING_OPACITY)
151
})
152
.when(!row.reactions.is_empty(), |bubble| {
153
bubble.mb(px(REACTION_OVERHANG))
154
117
});
118
let has_reactions = !row.reactions.is_empty();
155
119
let mut content = v_flex().gap(px(6.));
156
let padded_blocks = with_meta_room(&row.blocks, meta_room(row, own));
120
let padded_blocks = if has_reactions {
121
None
122
} else {
123
with_meta_room(&row.blocks, meta_room(row, own))
124
};
157
125
let meta_inline = has_text(row) && padded_blocks.is_some();
158
126
if has_text(row) {
159
127
content = content.child(render_blocks(
@@ -170,7 +138,31 @@ fn bubble(
170
138
&format!("message-{index}"),
171
139
directory,
172
140
));
173
if !meta_inline {
141
if has_reactions {
142
content = content.child(
143
h_flex()
144
.gap(px(8.))
145
.items_end()
146
.child(
147
reaction_pills(
148
&row.reactions,
149
index,
150
own,
151
directory,
152
extras.react.clone(),
153
extras.controls.as_ref(),
154
)
155
.flex_auto(),
156
)
157
.child(
158
h_flex()
159
.h(px(REACTION_FOOTER_HEIGHT))
160
.flex_none()
161
.items_center()
162
.child(bubble_meta(row, own)),
163
),
164
);
165
} else if !meta_inline {
174
166
content = content.child(h_flex().justify_end().child(bubble_meta(row, own)));
175
167
}
176
168
element = element.child(content);
@@ -183,21 +175,6 @@ fn bubble(
183
175
.child(bubble_meta(row, own)),
184
176
);
185
177
}
186
if !row.reactions.is_empty() {
187
element = element.child(
188
h_flex()
189
.absolute()
190
.when(own, |chips| chips.right(px(11.)))
191
.when(!own, |chips| chips.left(px(11.)))
192
.bottom(px(-14.))
193
.gap(px(4.))
194
.children(
195
row.reactions
196
.iter()
197
.map(|chip| reaction_chip(chip, index, extras.react.clone())),
198
),
199
);
200
}
201
178
if let Some(menu) = extras.menu {
202
179
element = element.child(
203
180
div()
@@ -214,6 +191,7 @@ fn bubble(
214
191
struct BubbleExtras {
215
192
menu: Option<MessageMenu>,
216
193
react: Option<PickHandler>,
194
controls: Option<ReactionControls>,
217
195
}
218
196
219
197
fn bubble_meta(row: &MessageRow, own: bool) -> Div {
@@ -477,13 +455,14 @@ fn post_card(row: &MessageRow, index: usize, directory: &Directory, cx: &App) ->
477
455
directory,
478
456
));
479
457
if !row.reactions.is_empty() {
480
body = body.child(
481
h_flex().gap(px(4.)).flex_wrap().children(
482
row.reactions
483
.iter()
484
.map(|chip| reaction_chip(chip, index, None)),
485
),
486
);
458
body = body.child(reaction_pills(
459
&row.reactions,
460
index,
461
false,
462
directory,
463
None,
464
None,
465
));
487
466
}
488
467
}
489
468
v_flex()
@@ -582,9 +561,14 @@ pub fn render_message_row(
582
561
hovered,
583
562
menu,
584
563
react,
564
reaction_controls,
585
565
highlighted,
586
566
} = actions;
587
let extras = BubbleExtras { menu, react };
567
let extras = BubbleExtras {
568
menu,
569
react,
570
controls: reaction_controls,
571
};
588
572
let own = row.own && !row.card;
589
573
let spacing = if row.card {
590
574
px(CARD_GAP)
@@ -1,5 +1,5 @@1
use gpui_kit::assets::IconName;1
use gpui_kit::assets::IconName;2
use gpui_kit::base::{GlobalState, TextSelection};2
use gpui_kit::base::TextSelection;3
use gpui_kit::component::{h_flex, v_flex};3
use gpui_kit::component::{h_flex, v_flex};4
use gpui_kit::prelude::FluentBuilder as _;4
use gpui_kit::prelude::FluentBuilder as _;5
use gpui_kit::*;5
use gpui_kit::*;@@ -9,10 +9,11 @@ use super::attachments::attachments_view;9
use super::avatar::{member_stack, person_avatar};9
use super::avatar::{member_stack, person_avatar};10
use super::message_actions::{HoverChange, MessageMenu, message_toolbar};10
use super::message_actions::{HoverChange, MessageMenu, message_toolbar};11
use super::reaction_picker::PickHandler;11
use super::reaction_picker::PickHandler;12
use super::reaction_pills::{ReactionControls, reaction_pills};12
use super::widgets::{icon, symbol};13
use super::widgets::{icon, symbol};13
use crate::data::Directory;14
use crate::data::Directory;14
use crate::render::{Block, render_blocks};15
use crate::render::{Block, render_blocks};15
use crate::rows::{Delivery, MessageRow, ReactionChip, Receipt, Skeleton, bubble_corners};16
use crate::rows::{Delivery, MessageRow, Receipt, Skeleton, bubble_corners};16
use crate::sidebar_model::DELETED_PREVIEW;17
use crate::sidebar_model::DELETED_PREVIEW;17
use crate::theme;18
use crate::theme;18
19
@@ -24,7 +25,7 @@ const SERIES_START_GAP: f32 = 8.;24
const BODY_SIZE: f32 = 13.5;25
const BODY_SIZE: f32 = 13.5;25
const MAX_WIDTH_RATIO: f32 = 0.7;26
const MAX_WIDTH_RATIO: f32 = 0.7;26
const SENDING_OPACITY: f32 = 0.6;27
const SENDING_OPACITY: f32 = 0.6;27
const REACTION_OVERHANG: f32 = 12.;28
const REACTION_FOOTER_HEIGHT: f32 = 24.;28
const CARD_AVATAR_SIZE: f32 = 32.;29
const CARD_AVATAR_SIZE: f32 = 32.;29
const CARD_GAP: f32 = 12.;30
const CARD_GAP: f32 = 12.;30
const META_SIZE: f32 = 11.;31
const META_SIZE: f32 = 11.;@@ -40,47 +41,12 @@ pub struct RowActions {40
pub hovered: Option<HoverChange>,41
pub hovered: Option<HoverChange>,41
pub menu: Option<MessageMenu>,42
pub menu: Option<MessageMenu>,42
pub react: Option<PickHandler>,43
pub react: Option<PickHandler>,44
pub reaction_controls: Option<ReactionControls>,43
pub highlighted: bool,45
pub highlighted: bool,44
}46
}45
47
46
const TOOLBAR_LIFT: f32 = 22.;48
const TOOLBAR_LIFT: f32 = 22.;47
49
48
fn reaction_chip(chip: &ReactionChip, index: usize, react: Option<PickHandler>) -> Stateful<Div> {49
let (background, border, foreground) = if chip.mine {50
(theme::bubble_own(), theme::accent(), theme::accent_tint())51
} else {52
(theme::surface(), theme::border_strong(), theme::text_soft())53
};54
let glyph = chip.label.clone();55
h_flex()56
.id(ElementId::Name(57
format!("reaction-{index}-{}", chip.reaction_type).into(),58
))59
.h(px(22.))60
.px(px(8.))61
.gap(px(4.))62
.items_center()63
.rounded(px(11.))64
.bg(background)65
.border_1()66
.border_color(border)67
.text_size(px(12.))68
.text_color(foreground)69
.child(chip.label.clone())70
.child(chip.count.to_string())71
.when_some(react, |chip, react| {72
chip.cursor_pointer()73
.hover(|chip| chip.border_color(theme::accent()))74
.on_mouse_down(MouseButton::Left, |_, _, cx| {75
GlobalState::suppress_text_selection(cx)76
})77
.on_click(move |_, window, cx| {78
cx.stop_propagation();79
react(&glyph, window, cx);80
})81
})82
}83
84
fn labeled_divider(label: &str, line_color: Hsla, text_color: Hsla) -> Div {50
fn labeled_divider(label: &str, line_color: Hsla, text_color: Hsla) -> Div {85
h_flex()51
h_flex()86
.w_full()52
.w_full()@@ -148,12 +114,14 @@ fn bubble(148
})114
})149
.when(row.delivery == Delivery::Sending, |bubble| {115
.when(row.delivery == Delivery::Sending, |bubble| {150
bubble.opacity(SENDING_OPACITY)116
bubble.opacity(SENDING_OPACITY)151
})152
.when(!row.reactions.is_empty(), |bubble| {153
bubble.mb(px(REACTION_OVERHANG))154
});117
});118
let has_reactions = !row.reactions.is_empty();155
let mut content = v_flex().gap(px(6.));119
let mut content = v_flex().gap(px(6.));156
let padded_blocks = with_meta_room(&row.blocks, meta_room(row, own));120
let padded_blocks = if has_reactions {121
None122
} else {123
with_meta_room(&row.blocks, meta_room(row, own))124
};157
let meta_inline = has_text(row) && padded_blocks.is_some();125
let meta_inline = has_text(row) && padded_blocks.is_some();158
if has_text(row) {126
if has_text(row) {159
content = content.child(render_blocks(127
content = content.child(render_blocks(@@ -170,7 +138,31 @@ fn bubble(170
&format!("message-{index}"),138
&format!("message-{index}"),171
directory,139
directory,172
));140
));173
if !meta_inline {141
if has_reactions {142
content = content.child(143
h_flex()144
.gap(px(8.))145
.items_end()146
.child(147
reaction_pills(148
&row.reactions,149
index,150
own,151
directory,152
extras.react.clone(),153
extras.controls.as_ref(),154
)155
.flex_auto(),156
)157
.child(158
h_flex()159
.h(px(REACTION_FOOTER_HEIGHT))160
.flex_none()161
.items_center()162
.child(bubble_meta(row, own)),163
),164
);165
} else if !meta_inline {174
content = content.child(h_flex().justify_end().child(bubble_meta(row, own)));166
content = content.child(h_flex().justify_end().child(bubble_meta(row, own)));175
}167
}176
element = element.child(content);168
element = element.child(content);@@ -183,21 +175,6 @@ fn bubble(183
.child(bubble_meta(row, own)),175
.child(bubble_meta(row, own)),184
);176
);185
}177
}186
if !row.reactions.is_empty() {187
element = element.child(188
h_flex()189
.absolute()190
.when(own, |chips| chips.right(px(11.)))191
.when(!own, |chips| chips.left(px(11.)))192
.bottom(px(-14.))193
.gap(px(4.))194
.children(195
row.reactions196
.iter()197
.map(|chip| reaction_chip(chip, index, extras.react.clone())),198
),199
);200
}201
if let Some(menu) = extras.menu {178
if let Some(menu) = extras.menu {202
element = element.child(179
element = element.child(203
div()180
div()@@ -214,6 +191,7 @@ fn bubble(214
struct BubbleExtras {191
struct BubbleExtras {215
menu: Option<MessageMenu>,192
menu: Option<MessageMenu>,216
react: Option<PickHandler>,193
react: Option<PickHandler>,194
controls: Option<ReactionControls>,217
}195
}218
196
219
fn bubble_meta(row: &MessageRow, own: bool) -> Div {197
fn bubble_meta(row: &MessageRow, own: bool) -> Div {@@ -477,13 +455,14 @@ fn post_card(row: &MessageRow, index: usize, directory: &Directory, cx: &App) ->477
directory,455
directory,478
));456
));479
if !row.reactions.is_empty() {457
if !row.reactions.is_empty() {480
body = body.child(458
body = body.child(reaction_pills(481
h_flex().gap(px(4.)).flex_wrap().children(459
&row.reactions,482
row.reactions460
index,483
.iter()461
false,484
.map(|chip| reaction_chip(chip, index, None)),462
directory,485
),463
None,486
);464
None,465
));487
}466
}488
}467
}489
v_flex()468
v_flex()@@ -582,9 +561,14 @@ pub fn render_message_row(582
hovered,561
hovered,583
menu,562
menu,584
react,563
react,564
reaction_controls,585
highlighted,565
highlighted,586
} = actions;566
} = actions;587
let extras = BubbleExtras { menu, react };567
let extras = BubbleExtras {568
menu,569
react,570
controls: reaction_controls,571
};588
let own = row.own && !row.card;572
let own = row.own && !row.card;589
let spacing = if row.card {573
let spacing = if row.card {590
px(CARD_GAP)574
px(CARD_GAP)@@ -8,6 +8,7 @@ pub mod message_actions;
8
8
pub mod message_row;
9
9
pub mod new_chat;
10
10
pub mod reaction_picker;
11
pub mod reaction_pills;
11
12
pub mod shell;
12
13
pub mod sidebar;
13
14
pub mod status_bar;
@@ -8,6 +8,7 @@ pub mod message_actions;8
pub mod message_row;8
pub mod message_row;9
pub mod new_chat;9
pub mod new_chat;10
pub mod reaction_picker;10
pub mod reaction_picker;11
pub mod reaction_pills;11
pub mod shell;12
pub mod shell;12
pub mod sidebar;13
pub mod sidebar;13
pub mod status_bar;14
pub mod status_bar;@@ -0,0 +1,314 @@
1
use std::rc::Rc;
2
3
use chrono::Local;
4
use gpui_kit::base::GlobalState;
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::avatar::person_avatar;
10
use super::reaction_picker::PickHandler;
11
use crate::data::Directory;
12
use crate::reaction_model::{
13
ReactionEntry, ReactionTab, Reactor, chip_tooltip, reaction_entries, reaction_tabs,
14
reaction_time_label, shows_faces,
15
};
16
use crate::rows::ReactionChip;
17
use crate::theme;
18
19
const PILL_HEIGHT: f32 = 24.;
20
const PILL_EMOJI_SIZE: f32 = 14.;
21
const PILL_TEXT_SIZE: f32 = 12.;
22
const PILL_GAP: f32 = 3.;
23
const FACE_SIZE: f32 = 18.;
24
const FACE_RING: f32 = 1.5;
25
const FACE_OVERLAP: f32 = 6.;
26
const POPOVER_WIDTH: f32 = 290.;
27
const POPOVER_MAX_HEIGHT: f32 = 320.;
28
const POPOVER_GAP: f32 = 4.;
29
const TAB_HEIGHT: f32 = 26.;
30
const ENTRY_HEIGHT: f32 = 48.;
31
const ENTRY_AVATAR_SIZE: f32 = 32.;
32
33
type OpenReaction = Rc<dyn Fn(&str, &mut App)>;
34
type SelectTab = Rc<dyn Fn(Option<String>, &mut App)>;
35
36
#[derive(Clone)]
37
pub struct ReactionPopover {
38
pub anchor_glyph: String,
39
pub tab: Option<String>,
40
}
41
42
#[derive(Clone)]
43
pub struct ReactionControls {
44
pub open: OpenReaction,
45
pub select_tab: SelectTab,
46
pub close: Rc<dyn Fn(&mut App)>,
47
pub popover: Option<ReactionPopover>,
48
}
49
50
fn face(position: usize, reactor: &Reactor, ring: Hsla, directory: &Directory) -> Div {
51
let step = FACE_SIZE + 2. * FACE_RING - FACE_OVERLAP;
52
div()
53
.absolute()
54
.top_0()
55
.left(px(position as f32 * step))
56
.size(px(FACE_SIZE + 2. * FACE_RING))
57
.p(px(FACE_RING))
58
.rounded_full()
59
.bg(ring)
60
.child(person_avatar(
61
directory,
62
reactor.user_id.as_deref(),
63
&reactor.name,
64
FACE_SIZE,
65
))
66
}
67
68
fn faces_width(count: usize) -> f32 {
69
let diameter = FACE_SIZE + 2. * FACE_RING;
70
diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)
71
}
72
73
fn pill_content(chip: &ReactionChip, background: Hsla, directory: &Directory) -> Div {
74
let content = h_flex().items_center().child(
75
div()
76
.text_size(px(PILL_EMOJI_SIZE))
77
.child(chip.label.clone()),
78
);
79
if shows_faces(chip.reactors.len()) {
80
content.child(
81
div()
82
.relative()
83
.flex_none()
84
.ml(px(PILL_GAP - FACE_RING))
85
.w(px(faces_width(chip.reactors.len())))
86
.h(px(FACE_SIZE + 2. * FACE_RING))
87
.children(
88
chip.reactors
89
.iter()
90
.enumerate()
91
.map(|(position, reactor)| face(position, reactor, background, directory)),
92
),
93
)
94
} else {
95
content
96
.gap(px(PILL_GAP))
97
.pr(px(1.))
98
.child(chip.count.to_string())
99
}
100
}
101
102
fn pill(
103
chip: &ReactionChip,
104
index: usize,
105
own: bool,
106
directory: &Directory,
107
react: Option<PickHandler>,
108
controls: Option<&ReactionControls>,
109
) -> Stateful<Div> {
110
let (background, foreground) = if chip.mine {
111
(theme::accent(), theme::white())
112
} else if own {
113
(theme::reaction_on_own(), theme::text_soft())
114
} else {
115
(theme::border_strong(), theme::text_soft())
116
};
117
let glyph = chip.label.clone();
118
let tooltip_text = chip_tooltip(chip);
119
let toggle = controls.map(|controls| {
120
let is_open = controls
121
.popover
122
.as_ref()
123
.is_some_and(|state| state.anchor_glyph == chip.glyph());
124
(
125
controls.open.clone(),
126
controls.close.clone(),
127
chip.glyph(),
128
is_open,
129
)
130
});
131
h_flex()
132
.id(ElementId::Name(
133
format!("reaction-{index}-{}", chip.reaction_type).into(),
134
))
135
.h(px(PILL_HEIGHT))
136
.flex_none()
137
.pl(px(5.))
138
.pr(px(2.))
139
.items_center()
140
.rounded(px(PILL_HEIGHT / 2.))
141
.bg(background)
142
.text_size(px(PILL_TEXT_SIZE))
143
.line_height(px(PILL_HEIGHT))
144
.text_color(foreground)
145
.child(pill_content(chip, background, directory))
146
.tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))
147
.when_some(toggle, |pill, (open, close, glyph, is_open)| {
148
pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {
149
cx.stop_propagation();
150
if is_open {
151
close(cx);
152
} else {
153
open(&glyph, cx);
154
}
155
})
156
})
157
.when_some(react, |pill, react| {
158
pill.cursor_pointer()
159
.on_mouse_down(MouseButton::Left, |_, _, cx| {
160
GlobalState::suppress_text_selection(cx)
161
})
162
.on_click(move |_, window, cx| {
163
cx.stop_propagation();
164
react(&glyph, window, cx);
165
})
166
})
167
}
168
169
fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Stateful<Div> {
170
let glyph = tab.glyph.clone();
171
h_flex()
172
.id(ElementId::Name(
173
format!("reaction-tab-{}", glyph.as_deref().unwrap_or("all")).into(),
174
))
175
.h(px(TAB_HEIGHT))
176
.px(px(10.))
177
.gap(px(4.))
178
.items_center()
179
.rounded(px(7.))
180
.cursor_pointer()
181
.text_size(px(12.5))
182
.text_color(if active {
183
theme::text()
184
} else {
185
theme::text_muted()
186
})
187
.when(active, |button| button.bg(theme::border_strong()))
188
.child(tab.label.clone())
189
.child(tab.count.to_string())
190
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())
191
.on_click(move |_, _, cx| {
192
cx.stop_propagation();
193
select_tab(glyph.clone(), cx);
194
})
195
}
196
197
fn entry_row(entry: &ReactionEntry, directory: &Directory) -> Div {
198
h_flex()
199
.h(px(ENTRY_HEIGHT))
200
.px(px(8.))
201
.gap(px(10.))
202
.items_center()
203
.child(person_avatar(
204
directory,
205
entry.reactor.user_id.as_deref(),
206
&entry.reactor.name,
207
ENTRY_AVATAR_SIZE,
208
))
209
.child(
210
v_flex()
211
.flex_1()
212
.min_w_0()
213
.child(
214
div()
215
.text_size(px(13.5))
216
.text_color(theme::text())
217
.truncate()
218
.child(entry.reactor.name.clone()),
219
)
220
.children(
221
entry
222
.reactor
223
.created_at
224
.map(|time| reaction_time_label(time, &Local::now()))
225
.map(|time| {
226
div()
227
.text_size(px(11.5))
228
.text_color(theme::text_muted())
229
.child(time)
230
}),
231
),
232
)
233
.child(div().text_size(px(17.)).child(entry.label.clone()))
234
}
235
236
fn popover(
237
chips: &[ReactionChip],
238
selected: Option<&str>,
239
directory: &Directory,
240
controls: &ReactionControls,
241
) -> AnyElement {
242
let selected = selected.filter(|glyph| chips.iter().any(|chip| chip.glyph() == *glyph));
243
let tabs = reaction_tabs(chips);
244
let entries = reaction_entries(chips, selected);
245
let close = controls.close.clone();
246
let panel = v_flex()
247
.id("reaction-popover")
248
.w(px(POPOVER_WIDTH))
249
.p(px(6.))
250
.gap(px(4.))
251
.rounded(px(12.))
252
.border_1()
253
.border_color(theme::border_strong())
254
.bg(theme::surface_raised())
255
.shadow_lg()
256
.occlude()
257
.on_mouse_down_out(move |_, _, cx| close(cx))
258
.on_mouse_down(MouseButton::Left, |_, _, cx| {
259
GlobalState::suppress_text_selection(cx);
260
cx.stop_propagation();
261
})
262
.on_mouse_down(MouseButton::Right, |_, _, cx| cx.stop_propagation())
263
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())
264
.when(!tabs.is_empty(), |panel| {
265
panel.child(h_flex().gap(px(2.)).children(tabs.iter().map(|tab| {
266
tab_button(
267
tab,
268
tab.glyph.as_deref() == selected,
269
controls.select_tab.clone(),
270
)
271
})))
272
})
273
.child(
274
v_flex()
275
.id("reaction-popover-entries")
276
.max_h(px(POPOVER_MAX_HEIGHT))
277
.overflow_y_scroll()
278
.children(entries.iter().map(|entry| entry_row(entry, directory))),
279
);
280
deferred(
281
anchored()
282
.anchor(Anchor::TopLeft)
283
.offset(point(px(0.), px(PILL_HEIGHT + POPOVER_GAP)))
284
.snap_to_window_with_margin(px(8.))
285
.child(panel),
286
)
287
.with_priority(2)
288
.into_any_element()
289
}
290
291
pub fn reaction_pills(
292
chips: &[ReactionChip],
293
index: usize,
294
own: bool,
295
directory: &Directory,
296
react: Option<PickHandler>,
297
controls: Option<&ReactionControls>,
298
) -> Div {
299
h_flex()
300
.gap(px(4.))
301
.flex_wrap()
302
.children(chips.iter().map(|chip| {
303
let open_here = controls
304
.and_then(|controls| controls.popover.as_ref().map(|state| (controls, state)))
305
.filter(|(_, state)| state.anchor_glyph == chip.glyph());
306
div()
307
.relative()
308
.flex_none()
309
.child(pill(chip, index, own, directory, react.clone(), controls))
310
.when_some(open_here, |wrapper, (controls, state)| {
311
wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))
312
})
313
}))
314
}
@@ -0,0 +1,314 @@1
use std::rc::Rc;2
3
use chrono::Local;4
use gpui_kit::base::GlobalState;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::avatar::person_avatar;10
use super::reaction_picker::PickHandler;11
use crate::data::Directory;12
use crate::reaction_model::{13
ReactionEntry, ReactionTab, Reactor, chip_tooltip, reaction_entries, reaction_tabs,14
reaction_time_label, shows_faces,15
};16
use crate::rows::ReactionChip;17
use crate::theme;18
19
const PILL_HEIGHT: f32 = 24.;20
const PILL_EMOJI_SIZE: f32 = 14.;21
const PILL_TEXT_SIZE: f32 = 12.;22
const PILL_GAP: f32 = 3.;23
const FACE_SIZE: f32 = 18.;24
const FACE_RING: f32 = 1.5;25
const FACE_OVERLAP: f32 = 6.;26
const POPOVER_WIDTH: f32 = 290.;27
const POPOVER_MAX_HEIGHT: f32 = 320.;28
const POPOVER_GAP: f32 = 4.;29
const TAB_HEIGHT: f32 = 26.;30
const ENTRY_HEIGHT: f32 = 48.;31
const ENTRY_AVATAR_SIZE: f32 = 32.;32
33
type OpenReaction = Rc<dyn Fn(&str, &mut App)>;34
type SelectTab = Rc<dyn Fn(Option<String>, &mut App)>;35
36
#[derive(Clone)]37
pub struct ReactionPopover {38
pub anchor_glyph: String,39
pub tab: Option<String>,40
}41
42
#[derive(Clone)]43
pub struct ReactionControls {44
pub open: OpenReaction,45
pub select_tab: SelectTab,46
pub close: Rc<dyn Fn(&mut App)>,47
pub popover: Option<ReactionPopover>,48
}49
50
fn face(position: usize, reactor: &Reactor, ring: Hsla, directory: &Directory) -> Div {51
let step = FACE_SIZE + 2. * FACE_RING - FACE_OVERLAP;52
div()53
.absolute()54
.top_0()55
.left(px(position as f32 * step))56
.size(px(FACE_SIZE + 2. * FACE_RING))57
.p(px(FACE_RING))58
.rounded_full()59
.bg(ring)60
.child(person_avatar(61
directory,62
reactor.user_id.as_deref(),63
&reactor.name,64
FACE_SIZE,65
))66
}67
68
fn faces_width(count: usize) -> f32 {69
let diameter = FACE_SIZE + 2. * FACE_RING;70
diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)71
}72
73
fn pill_content(chip: &ReactionChip, background: Hsla, directory: &Directory) -> Div {74
let content = h_flex().items_center().child(75
div()76
.text_size(px(PILL_EMOJI_SIZE))77
.child(chip.label.clone()),78
);79
if shows_faces(chip.reactors.len()) {80
content.child(81
div()82
.relative()83
.flex_none()84
.ml(px(PILL_GAP - FACE_RING))85
.w(px(faces_width(chip.reactors.len())))86
.h(px(FACE_SIZE + 2. * FACE_RING))87
.children(88
chip.reactors89
.iter()90
.enumerate()91
.map(|(position, reactor)| face(position, reactor, background, directory)),92
),93
)94
} else {95
content96
.gap(px(PILL_GAP))97
.pr(px(1.))98
.child(chip.count.to_string())99
}100
}101
102
fn pill(103
chip: &ReactionChip,104
index: usize,105
own: bool,106
directory: &Directory,107
react: Option<PickHandler>,108
controls: Option<&ReactionControls>,109
) -> Stateful<Div> {110
let (background, foreground) = if chip.mine {111
(theme::accent(), theme::white())112
} else if own {113
(theme::reaction_on_own(), theme::text_soft())114
} else {115
(theme::border_strong(), theme::text_soft())116
};117
let glyph = chip.label.clone();118
let tooltip_text = chip_tooltip(chip);119
let toggle = controls.map(|controls| {120
let is_open = controls121
.popover122
.as_ref()123
.is_some_and(|state| state.anchor_glyph == chip.glyph());124
(125
controls.open.clone(),126
controls.close.clone(),127
chip.glyph(),128
is_open,129
)130
});131
h_flex()132
.id(ElementId::Name(133
format!("reaction-{index}-{}", chip.reaction_type).into(),134
))135
.h(px(PILL_HEIGHT))136
.flex_none()137
.pl(px(5.))138
.pr(px(2.))139
.items_center()140
.rounded(px(PILL_HEIGHT / 2.))141
.bg(background)142
.text_size(px(PILL_TEXT_SIZE))143
.line_height(px(PILL_HEIGHT))144
.text_color(foreground)145
.child(pill_content(chip, background, directory))146
.tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))147
.when_some(toggle, |pill, (open, close, glyph, is_open)| {148
pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {149
cx.stop_propagation();150
if is_open {151
close(cx);152
} else {153
open(&glyph, cx);154
}155
})156
})157
.when_some(react, |pill, react| {158
pill.cursor_pointer()159
.on_mouse_down(MouseButton::Left, |_, _, cx| {160
GlobalState::suppress_text_selection(cx)161
})162
.on_click(move |_, window, cx| {163
cx.stop_propagation();164
react(&glyph, window, cx);165
})166
})167
}168
169
fn tab_button(tab: &ReactionTab, active: bool, select_tab: SelectTab) -> Stateful<Div> {170
let glyph = tab.glyph.clone();171
h_flex()172
.id(ElementId::Name(173
format!("reaction-tab-{}", glyph.as_deref().unwrap_or("all")).into(),174
))175
.h(px(TAB_HEIGHT))176
.px(px(10.))177
.gap(px(4.))178
.items_center()179
.rounded(px(7.))180
.cursor_pointer()181
.text_size(px(12.5))182
.text_color(if active {183
theme::text()184
} else {185
theme::text_muted()186
})187
.when(active, |button| button.bg(theme::border_strong()))188
.child(tab.label.clone())189
.child(tab.count.to_string())190
.on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation())191
.on_click(move |_, _, cx| {192
cx.stop_propagation();193
select_tab(glyph.clone(), cx);194
})195
}196
197
fn entry_row(entry: &ReactionEntry, directory: &Directory) -> Div {198
h_flex()199
.h(px(ENTRY_HEIGHT))200
.px(px(8.))201
.gap(px(10.))202
.items_center()203
.child(person_avatar(204
directory,205
entry.reactor.user_id.as_deref(),206
&entry.reactor.name,207
ENTRY_AVATAR_SIZE,208
))209
.child(210
v_flex()211
.flex_1()212
.min_w_0()213
.child(214
div()215
.text_size(px(13.5))216
.text_color(theme::text())217
.truncate()218
.child(entry.reactor.name.clone()),219
)220
.children(221
entry222
.reactor223
.created_at224
.map(|time| reaction_time_label(time, &Local::now()))225
.map(|time| {226
div()227
.text_size(px(11.5))228
.text_color(theme::text_muted())229
.child(time)230
}),231
),232
)233
.child(div().text_size(px(17.)).child(entry.label.clone()))234
}235
236
fn popover(237
chips: &[ReactionChip],238
selected: Option<&str>,239
directory: &Directory,240
controls: &ReactionControls,241
) -> AnyElement {242
let selected = selected.filter(|glyph| chips.iter().any(|chip| chip.glyph() == *glyph));243
let tabs = reaction_tabs(chips);244
let entries = reaction_entries(chips, selected);245
let close = controls.close.clone();246
let panel = v_flex()247
.id("reaction-popover")248
.w(px(POPOVER_WIDTH))249
.p(px(6.))250
.gap(px(4.))251
.rounded(px(12.))252
.border_1()253
.border_color(theme::border_strong())254
.bg(theme::surface_raised())255
.shadow_lg()256
.occlude()257
.on_mouse_down_out(move |_, _, cx| close(cx))258
.on_mouse_down(MouseButton::Left, |_, _, cx| {259
GlobalState::suppress_text_selection(cx);260
cx.stop_propagation();261
})262
.on_mouse_down(MouseButton::Right, |_, _, cx| cx.stop_propagation())263
.on_scroll_wheel(|_, _, cx| cx.stop_propagation())264
.when(!tabs.is_empty(), |panel| {265
panel.child(h_flex().gap(px(2.)).children(tabs.iter().map(|tab| {266
tab_button(267
tab,268
tab.glyph.as_deref() == selected,269
controls.select_tab.clone(),270
)271
})))272
})273
.child(274
v_flex()275
.id("reaction-popover-entries")276
.max_h(px(POPOVER_MAX_HEIGHT))277
.overflow_y_scroll()278
.children(entries.iter().map(|entry| entry_row(entry, directory))),279
);280
deferred(281
anchored()282
.anchor(Anchor::TopLeft)283
.offset(point(px(0.), px(PILL_HEIGHT + POPOVER_GAP)))284
.snap_to_window_with_margin(px(8.))285
.child(panel),286
)287
.with_priority(2)288
.into_any_element()289
}290
291
pub fn reaction_pills(292
chips: &[ReactionChip],293
index: usize,294
own: bool,295
directory: &Directory,296
react: Option<PickHandler>,297
controls: Option<&ReactionControls>,298
) -> Div {299
h_flex()300
.gap(px(4.))301
.flex_wrap()302
.children(chips.iter().map(|chip| {303
let open_here = controls304
.and_then(|controls| controls.popover.as_ref().map(|state| (controls, state)))305
.filter(|(_, state)| state.anchor_glyph == chip.glyph());306
div()307
.relative()308
.flex_none()309
.child(pill(chip, index, own, directory, react.clone(), controls))310
.when_some(open_here, |wrapper, (controls, state)| {311
wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))312
})313
}))314
}@@ -247,6 +247,7 @@ fn reaction_info(reaction: &Reaction) -> ReactionInfo {
247
247
.as_ref()
248
248
.and_then(|sender| sender.display_name())
249
249
.map(str::to_owned),
250
created_at: reaction.created_date_time,
250
251
}
251
252
}
252
253
@@ -247,6 +247,7 @@ fn reaction_info(reaction: &Reaction) -> ReactionInfo {247
.as_ref()247
.as_ref()248
.and_then(|sender| sender.display_name())248
.and_then(|sender| sender.display_name())249
.map(str::to_owned),249
.map(str::to_owned),250
created_at: reaction.created_date_time,250
}251
}251
}252
}252
253
@@ -1,3 +1,4 @@
1
use chrono::{DateTime, Utc};
1
2
use scraper::{ElementRef, Html};
2
3
use serde::{Deserialize, Serialize};
3
4
use store::MessageRecord;
@@ -106,6 +107,8 @@ pub struct ReactionInfo {
106
107
pub reaction_type: String,
107
108
pub user_id: Option<String>,
108
109
pub user_name: Option<String>,
110
#[serde(default)]
111
pub created_at: Option<DateTime<Utc>>,
109
112
}
110
113
111
114
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -424,6 +427,16 @@ mod tests {
424
427
}
425
428
}
426
429
430
#[test]
431
fn reaction_without_created_at_still_parses() {
432
let mut stored = record("", "[]");
433
stored.reactions_json =
434
r#"[{"reaction_type":"like","user_id":"u","user_name":null}]"#.to_owned();
435
let parsed = reactions(&stored);
436
assert_eq!(parsed.len(), 1);
437
assert_eq!(parsed[0].created_at, None);
438
}
439
427
440
#[test]
428
441
fn images_cover_hosted_contents_and_ams_and_skip_emoji() {
429
442
let html = concat!(
@@ -1,3 +1,4 @@1
use chrono::{DateTime, Utc};1
use scraper::{ElementRef, Html};2
use scraper::{ElementRef, Html};2
use serde::{Deserialize, Serialize};3
use serde::{Deserialize, Serialize};3
use store::MessageRecord;4
use store::MessageRecord;@@ -106,6 +107,8 @@ pub struct ReactionInfo {106
pub reaction_type: String,107
pub reaction_type: String,107
pub user_id: Option<String>,108
pub user_id: Option<String>,108
pub user_name: Option<String>,109
pub user_name: Option<String>,110
#[serde(default)]111
pub created_at: Option<DateTime<Utc>>,109
}112
}110
113
111
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]114
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]@@ -424,6 +427,16 @@ mod tests {424
}427
}425
}428
}426
429
430
#[test]431
fn reaction_without_created_at_still_parses() {432
let mut stored = record("", "[]");433
stored.reactions_json =434
r#"[{"reaction_type":"like","user_id":"u","user_name":null}]"#.to_owned();435
let parsed = reactions(&stored);436
assert_eq!(parsed.len(), 1);437
assert_eq!(parsed[0].created_at, None);438
}439
427
#[test]440
#[test]428
fn images_cover_hosted_contents_and_ams_and_skip_emoji() {441
fn images_cover_hosted_contents_and_ams_and_skip_emoji() {429
let html = concat!(442
let html = concat!(