feat(channels): post card like Teams, scroll edge under New post
- code alone on its line is one framed, wrapping block (Teams inline-block code), red code text and Teams frame colour, also in chats; pre blocks get the frame; card monospace text stays plain - post header: avatar with presence, name over date; subject and body start at the avatar edge at full width - reactions in posts: emoji + count pill and an add-reaction button - footer: own avatar + "Reply in thread" (Teams compose placeholder), inline reply placeholder too - reply with quote on a root post keeps the quote; channel quote replies send a messageReference attachment (Graph instead of Teams' chatsvc blockquote, same quote for readers) - post and list times follow the account display language (en-GB "24/09 20:54") - scroll edge line under the New post row while the feed is scrolled, and under the channel details and call people headers - demo post with a code line, reactions and a reply; layout_guard checks body/avatar edge, one code frame, feed edge line Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -1,9 +1,59 @@
1
use std::cell::Cell;
2
1
3
use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, Utc, Weekday};
2
4
3
5
use crate::theme;
4
6
5
7
const BADGE_CAP: u32 = 99;
6
8
const WEEKDAY_WINDOW_DAYS: i64 = 6;
9
const TWELVE_HOUR_LOCALES: [&str; 6] = ["en-us", "en-ca", "en-ph", "en-au", "en-nz", "en-in"];
10
const DOTTED_LOCALES: [&str; 7] = ["de", "da", "nb", "no", "fi", "cs", "sk"];
11
const PADDED_DOT_LOCALES: [&str; 4] = ["ru", "pl", "tr", "uk"];
12
13
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14
pub struct DateStyle {
15
day_month: &'static str,
16
day_month_year: &'static str,
17
clock: &'static str,
18
}
19
20
thread_local! {
21
static DATE_STYLE: Cell<Option<DateStyle>> = const { Cell::new(None) };
22
}
23
24
pub fn set_date_locale(locale: Option<&str>) {
25
DATE_STYLE.with(|style| style.set(locale.map(date_style)));
26
}
27
28
fn current_date_style() -> Option<DateStyle> {
29
DATE_STYLE.with(Cell::get)
30
}
31
32
/// Numeric day and month in the order of the account's display language, as `Intl.DateTimeFormat` does in Teams.
33
pub fn date_style(locale: &str) -> DateStyle {
34
let locale = locale.to_ascii_lowercase();
35
let language = locale.split(['-', '_']).next().unwrap_or_default();
36
let twelve_hour = TWELVE_HOUR_LOCALES.contains(&locale.as_str());
37
let clock = match language {
38
_ if !twelve_hour => "%H:%M",
39
_ if locale == "en-au" || locale == "en-nz" || locale == "en-in" => "%-I:%M %P",
40
_ => "%-I:%M %p",
41
};
42
let (day_month, day_month_year) = match language {
43
_ if locale == "en-us" || locale == "en-ph" || locale == "en-ca" => ("%-m/%-d", "%-m/%-d/%Y"),
44
"ja" | "zh" => ("%-m/%-d", "%Y/%-m/%-d"),
45
"nl" => ("%-d-%-m", "%-d-%-m-%Y"),
46
"sv" => ("%-d/%-m", "%Y-%m-%d"),
47
language if DOTTED_LOCALES.contains(&language) => ("%-d.%-m.", "%-d.%-m.%Y"),
48
language if PADDED_DOT_LOCALES.contains(&language) => ("%d.%m", "%d.%m.%Y"),
49
_ => ("%d/%m", "%d/%m/%Y"),
50
};
51
DateStyle {
52
day_month,
53
day_month_year,
54
clock,
55
}
56
}
7
57
8
58
pub fn palette_index(key: &str) -> usize {
9
59
let mut hash: u32 = 0x811c_9dc5;
@@ -69,30 +119,58 @@ pub fn short_version(build_id: &str, package_version: &str) -> String {
69
119
}
70
120
71
121
pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
122
list_time_label_in(current_date_style(), time, today, offset)
123
}
124
125
pub fn list_time_label_in(
126
style: Option<DateStyle>,
127
time: DateTime<Utc>,
128
today: NaiveDate,
129
offset: FixedOffset,
130
) -> String {
72
131
let local = time.with_timezone(&offset);
73
132
let day = local.date_naive();
74
133
let days_ago = (today - day).num_days();
75
134
if days_ago <= 0 {
76
local.format("%H:%M").to_string()
135
local.format(style.map_or("%H:%M", |style| style.clock)).to_string()
77
136
} else if days_ago <= WEEKDAY_WINDOW_DAYS {
78
137
weekday_label(local.weekday()).to_owned()
79
138
} else {
80
local.format("%b %-d").to_string()
139
local
140
.format(style.map_or("%b %-d", |style| style.day_month))
141
.to_string()
81
142
}
82
143
}
83
144
84
145
pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
146
post_time_label_in(current_date_style(), time, today, offset)
147
}
148
149
pub fn post_time_label_in(
150
style: Option<DateStyle>,
151
time: DateTime<Utc>,
152
today: NaiveDate,
153
offset: FixedOffset,
154
) -> String {
85
155
let local = time.with_timezone(&offset);
86
156
let day = local.date_naive();
87
157
let days_ago = (today - day).num_days();
88
let clock = local.format("%H:%M");
158
let clock = local.format(style.map_or("%H:%M", |style| style.clock));
159
let same_year = day.year() == today.year();
89
160
if days_ago <= 0 {
90
161
clock.to_string()
91
162
} else if days_ago == 1 {
92
163
format!("Yesterday {clock}")
93
164
} else if days_ago <= WEEKDAY_WINDOW_DAYS {
94
165
format!("{} {clock}", weekday_label(local.weekday()))
95
} else if day.year() == today.year() {
166
} else if let Some(style) = style {
167
let date = if same_year {
168
style.day_month
169
} else {
170
style.day_month_year
171
};
172
format!("{} {clock}", local.format(date))
173
} else if same_year {
96
174
format!("{} {clock}", local.format("%b %-d"))
97
175
} else {
98
176
format!("{} {clock}", local.format("%b %-d, %Y"))
@@ -225,6 +303,30 @@ mod tests {
225
303
);
226
304
}
227
305
306
#[test]
307
fn post_time_follows_the_display_language_like_teams() {
308
let september = Utc.with_ymd_and_hms(2026, 9, 24, 20, 54, 0).unwrap();
309
let label = |locale: &str| {
310
post_time_label_in(Some(date_style(locale)), september, today(), zero())
311
};
312
assert_eq!(label("en-GB"), "24/09 20:54");
313
assert_eq!(label("de-DE"), "24.9. 20:54");
314
assert_eq!(label("en-US"), "9/24 8:54 PM");
315
let last_year = Utc.with_ymd_and_hms(2020, 5, 2, 8, 42, 0).unwrap();
316
assert_eq!(
317
post_time_label_in(Some(date_style("en-GB")), last_year, today(), zero()),
318
"02/05/2020 08:42"
319
);
320
}
321
322
#[test]
323
fn list_time_follows_the_display_language_like_teams() {
324
let september = Utc.with_ymd_and_hms(2026, 9, 24, 20, 54, 0).unwrap();
325
let style = Some(date_style("en-GB"));
326
assert_eq!(list_time_label_in(style, september, today(), zero()), "24/09");
327
assert_eq!(list_time_label_in(style, utc(7, 13), today(), zero()), "13:05");
328
}
329
228
330
#[test]
229
331
fn day_labels() {
230
332
assert_eq!(day_label(today(), today()), "Today");
@@ -1,9 +1,59 @@1
use std::cell::Cell;2
1
use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, Utc, Weekday};3
use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, Utc, Weekday};2
4
3
use crate::theme;5
use crate::theme;4
6
5
const BADGE_CAP: u32 = 99;7
const BADGE_CAP: u32 = 99;6
const WEEKDAY_WINDOW_DAYS: i64 = 6;8
const WEEKDAY_WINDOW_DAYS: i64 = 6;9
const TWELVE_HOUR_LOCALES: [&str; 6] = ["en-us", "en-ca", "en-ph", "en-au", "en-nz", "en-in"];10
const DOTTED_LOCALES: [&str; 7] = ["de", "da", "nb", "no", "fi", "cs", "sk"];11
const PADDED_DOT_LOCALES: [&str; 4] = ["ru", "pl", "tr", "uk"];12
13
#[derive(Debug, Clone, Copy, PartialEq, Eq)]14
pub struct DateStyle {15
day_month: &'static str,16
day_month_year: &'static str,17
clock: &'static str,18
}19
20
thread_local! {21
static DATE_STYLE: Cell<Option<DateStyle>> = const { Cell::new(None) };22
}23
24
pub fn set_date_locale(locale: Option<&str>) {25
DATE_STYLE.with(|style| style.set(locale.map(date_style)));26
}27
28
fn current_date_style() -> Option<DateStyle> {29
DATE_STYLE.with(Cell::get)30
}31
32
/// Numeric day and month in the order of the account's display language, as `Intl.DateTimeFormat` does in Teams.33
pub fn date_style(locale: &str) -> DateStyle {34
let locale = locale.to_ascii_lowercase();35
let language = locale.split(['-', '_']).next().unwrap_or_default();36
let twelve_hour = TWELVE_HOUR_LOCALES.contains(&locale.as_str());37
let clock = match language {38
_ if !twelve_hour => "%H:%M",39
_ if locale == "en-au" || locale == "en-nz" || locale == "en-in" => "%-I:%M %P",40
_ => "%-I:%M %p",41
};42
let (day_month, day_month_year) = match language {43
_ if locale == "en-us" || locale == "en-ph" || locale == "en-ca" => ("%-m/%-d", "%-m/%-d/%Y"),44
"ja" | "zh" => ("%-m/%-d", "%Y/%-m/%-d"),45
"nl" => ("%-d-%-m", "%-d-%-m-%Y"),46
"sv" => ("%-d/%-m", "%Y-%m-%d"),47
language if DOTTED_LOCALES.contains(&language) => ("%-d.%-m.", "%-d.%-m.%Y"),48
language if PADDED_DOT_LOCALES.contains(&language) => ("%d.%m", "%d.%m.%Y"),49
_ => ("%d/%m", "%d/%m/%Y"),50
};51
DateStyle {52
day_month,53
day_month_year,54
clock,55
}56
}7
57
8
pub fn palette_index(key: &str) -> usize {58
pub fn palette_index(key: &str) -> usize {9
let mut hash: u32 = 0x811c_9dc5;59
let mut hash: u32 = 0x811c_9dc5;@@ -69,30 +119,58 @@ pub fn short_version(build_id: &str, package_version: &str) -> String {69
}119
}70
120
71
pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {121
pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {122
list_time_label_in(current_date_style(), time, today, offset)123
}124
125
pub fn list_time_label_in(126
style: Option<DateStyle>,127
time: DateTime<Utc>,128
today: NaiveDate,129
offset: FixedOffset,130
) -> String {72
let local = time.with_timezone(&offset);131
let local = time.with_timezone(&offset);73
let day = local.date_naive();132
let day = local.date_naive();74
let days_ago = (today - day).num_days();133
let days_ago = (today - day).num_days();75
if days_ago <= 0 {134
if days_ago <= 0 {76
local.format("%H:%M").to_string()135
local.format(style.map_or("%H:%M", |style| style.clock)).to_string()77
} else if days_ago <= WEEKDAY_WINDOW_DAYS {136
} else if days_ago <= WEEKDAY_WINDOW_DAYS {78
weekday_label(local.weekday()).to_owned()137
weekday_label(local.weekday()).to_owned()79
} else {138
} else {80
local.format("%b %-d").to_string()139
local140
.format(style.map_or("%b %-d", |style| style.day_month))141
.to_string()81
}142
}82
}143
}83
144
84
pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {145
pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {146
post_time_label_in(current_date_style(), time, today, offset)147
}148
149
pub fn post_time_label_in(150
style: Option<DateStyle>,151
time: DateTime<Utc>,152
today: NaiveDate,153
offset: FixedOffset,154
) -> String {85
let local = time.with_timezone(&offset);155
let local = time.with_timezone(&offset);86
let day = local.date_naive();156
let day = local.date_naive();87
let days_ago = (today - day).num_days();157
let days_ago = (today - day).num_days();88
let clock = local.format("%H:%M");158
let clock = local.format(style.map_or("%H:%M", |style| style.clock));159
let same_year = day.year() == today.year();89
if days_ago <= 0 {160
if days_ago <= 0 {90
clock.to_string()161
clock.to_string()91
} else if days_ago == 1 {162
} else if days_ago == 1 {92
format!("Yesterday {clock}")163
format!("Yesterday {clock}")93
} else if days_ago <= WEEKDAY_WINDOW_DAYS {164
} else if days_ago <= WEEKDAY_WINDOW_DAYS {94
format!("{} {clock}", weekday_label(local.weekday()))165
format!("{} {clock}", weekday_label(local.weekday()))95
} else if day.year() == today.year() {166
} else if let Some(style) = style {167
let date = if same_year {168
style.day_month169
} else {170
style.day_month_year171
};172
format!("{} {clock}", local.format(date))173
} else if same_year {96
format!("{} {clock}", local.format("%b %-d"))174
format!("{} {clock}", local.format("%b %-d"))97
} else {175
} else {98
format!("{} {clock}", local.format("%b %-d, %Y"))176
format!("{} {clock}", local.format("%b %-d, %Y"))@@ -225,6 +303,30 @@ mod tests {225
);303
);226
}304
}227
305
306
#[test]307
fn post_time_follows_the_display_language_like_teams() {308
let september = Utc.with_ymd_and_hms(2026, 9, 24, 20, 54, 0).unwrap();309
let label = |locale: &str| {310
post_time_label_in(Some(date_style(locale)), september, today(), zero())311
};312
assert_eq!(label("en-GB"), "24/09 20:54");313
assert_eq!(label("de-DE"), "24.9. 20:54");314
assert_eq!(label("en-US"), "9/24 8:54 PM");315
let last_year = Utc.with_ymd_and_hms(2020, 5, 2, 8, 42, 0).unwrap();316
assert_eq!(317
post_time_label_in(Some(date_style("en-GB")), last_year, today(), zero()),318
"02/05/2020 08:42"319
);320
}321
322
#[test]323
fn list_time_follows_the_display_language_like_teams() {324
let september = Utc.with_ymd_and_hms(2026, 9, 24, 20, 54, 0).unwrap();325
let style = Some(date_style("en-GB"));326
assert_eq!(list_time_label_in(style, september, today(), zero()), "24/09");327
assert_eq!(list_time_label_in(style, utc(7, 13), today(), zero()), "13:05");328
}329
228
#[test]330
#[test]229
fn day_labels() {331
fn day_labels() {230
assert_eq!(day_label(today(), today()), "Today");332
assert_eq!(day_label(today(), today()), "Today");@@ -323,6 +323,10 @@ pub fn inline_code_border() -> Hsla {
323
323
color_with_alpha(palette().inline_code_border)
324
324
}
325
325
326
pub fn code_frame() -> Hsla {
327
color_with_alpha(palette().code_frame)
328
}
329
326
330
pub fn table_header() -> Hsla {
327
331
color_with_alpha(palette().table_header)
328
332
}
@@ -323,6 +323,10 @@ pub fn inline_code_border() -> Hsla {323
color_with_alpha(palette().inline_code_border)323
color_with_alpha(palette().inline_code_border)324
}324
}325
325
326
pub fn code_frame() -> Hsla {327
color_with_alpha(palette().code_frame)328
}329
326
pub fn table_header() -> Hsla {330
pub fn table_header() -> Hsla {327
color_with_alpha(palette().table_header)331
color_with_alpha(palette().table_header)328
}332
}@@ -86,6 +86,7 @@ pub struct Palette {
86
86
pub inline_code_fill_own: u32,
87
87
pub quote_fill: u32,
88
88
pub inline_code_border: u32,
89
pub code_frame: u32,
89
90
pub table_header: u32,
90
91
}
91
92
@@ -161,6 +162,7 @@ const DARK_BASE: Palette = Palette {
161
162
inline_code_fill_own: 0x0000003d,
162
163
quote_fill: 0x00000052,
163
164
inline_code_border: 0xffffff1a,
165
code_frame: 0xffffff3d,
164
166
table_header: 0xffffff0d,
165
167
};
166
168
@@ -172,6 +174,7 @@ const LIGHT_BASE: Palette = Palette {
172
174
inline_code_fill_own: 0x0000000f,
173
175
quote_fill: 0x0000000a,
174
176
inline_code_border: 0x00000014,
177
code_frame: 0x0000002e,
175
178
table_header: 0x00000008,
176
179
..DARK_BASE
177
180
};
@@ -406,6 +409,7 @@ pub const HIGH_CONTRAST: Palette = Palette {
406
409
inline_code_fill_own: 0x000000ff,
407
410
quote_fill: 0x000000ff,
408
411
inline_code_border: 0xffffffff,
412
code_frame: 0xffffffff,
409
413
table_header: 0x000000ff,
410
414
..DARK_BASE
411
415
};
@@ -86,6 +86,7 @@ pub struct Palette {86
pub inline_code_fill_own: u32,86
pub inline_code_fill_own: u32,87
pub quote_fill: u32,87
pub quote_fill: u32,88
pub inline_code_border: u32,88
pub inline_code_border: u32,89
pub code_frame: u32,89
pub table_header: u32,90
pub table_header: u32,90
}91
}91
92
@@ -161,6 +162,7 @@ const DARK_BASE: Palette = Palette {161
inline_code_fill_own: 0x0000003d,162
inline_code_fill_own: 0x0000003d,162
quote_fill: 0x00000052,163
quote_fill: 0x00000052,163
inline_code_border: 0xffffff1a,164
inline_code_border: 0xffffff1a,165
code_frame: 0xffffff3d,164
table_header: 0xffffff0d,166
table_header: 0xffffff0d,165
};167
};166
168
@@ -172,6 +174,7 @@ const LIGHT_BASE: Palette = Palette {172
inline_code_fill_own: 0x0000000f,174
inline_code_fill_own: 0x0000000f,173
quote_fill: 0x0000000a,175
quote_fill: 0x0000000a,174
inline_code_border: 0x00000014,176
inline_code_border: 0x00000014,177
code_frame: 0x0000002e,175
table_header: 0x00000008,178
table_header: 0x00000008,176
..DARK_BASE179
..DARK_BASE177
};180
};@@ -406,6 +409,7 @@ pub const HIGH_CONTRAST: Palette = Palette {406
inline_code_fill_own: 0x000000ff,409
inline_code_fill_own: 0x000000ff,407
quote_fill: 0x000000ff,410
quote_fill: 0x000000ff,408
inline_code_border: 0xffffffff,411
inline_code_border: 0xffffffff,412
code_frame: 0xffffffff,409
table_header: 0x000000ff,413
table_header: 0x000000ff,410
..DARK_BASE414
..DARK_BASE411
};415
};@@ -57,6 +57,7 @@ pub struct ActiveCall {
57
57
pub chat_open: bool,
58
58
pub transcript_open: bool,
59
59
pub people_open: bool,
60
pub people_scroll: gpui_kit::ScrollHandle,
60
61
pub options_dialog: Option<OptionsDialog>,
61
62
pub meeting_target: Option<MeetingTarget>,
62
63
pub pending_move: Option<PendingMove>,
@@ -138,6 +139,7 @@ impl ActiveCall {
138
139
chat_open: false,
139
140
transcript_open: false,
140
141
people_open: false,
142
people_scroll: gpui_kit::ScrollHandle::new(),
141
143
options_dialog: None,
142
144
meeting_target: None,
143
145
pending_move: None,
@@ -57,6 +57,7 @@ pub struct ActiveCall {57
pub chat_open: bool,57
pub chat_open: bool,58
pub transcript_open: bool,58
pub transcript_open: bool,59
pub people_open: bool,59
pub people_open: bool,60
pub people_scroll: gpui_kit::ScrollHandle,60
pub options_dialog: Option<OptionsDialog>,61
pub options_dialog: Option<OptionsDialog>,61
pub meeting_target: Option<MeetingTarget>,62
pub meeting_target: Option<MeetingTarget>,62
pub pending_move: Option<PendingMove>,63
pub pending_move: Option<PendingMove>,@@ -138,6 +139,7 @@ impl ActiveCall {138
chat_open: false,139
chat_open: false,139
transcript_open: false,140
transcript_open: false,140
people_open: false,141
people_open: false,142
people_scroll: gpui_kit::ScrollHandle::new(),141
options_dialog: None,143
options_dialog: None,142
meeting_target: None,144
meeting_target: None,143
pending_move: None,145
pending_move: None,@@ -916,6 +916,7 @@ pub fn seed_directory(state: &mut AppState) {
916
916
state.own_email = DEMO_USER_EMAIL.to_owned();
917
917
state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());
918
918
state.translation.settings = Some(language_settings());
919
state.apply_date_locale();
919
920
state.translation.languages = language_list();
920
921
let directory = &mut state.directory;
921
922
directory.me = Some(Person {
@@ -2080,10 +2081,46 @@ fn channel_messages() -> Vec<MessageRecord> {
2080
2081
),
2081
2082
];
2082
2083
records.extend(rollout_replies);
2084
records.extend(code_post(channel, tobias));
2083
2085
records.extend(shared_channel_messages(channel, mara, tobias));
2084
2086
records
2085
2087
}
2086
2088
2089
fn code_post(channel: &str, tobias: (&str, &str)) -> Vec<MessageRecord> {
2090
let laughs = reactions_json(vec![reaction(
2091
"laugh",
2092
&[
2093
(PRIYA_ID, "Priya Nair", at(0, 11, 20)),
2094
(JONAS_ID, "Jonas Ortega", at(0, 11, 22)),
2095
],
2096
)]);
2097
vec![
2098
with_subject(
2099
message(
2100
channel,
2101
"t8",
2102
None,
2103
tobias,
2104
at(0, 11, 5),
2105
"<p>I got this error message when running \"Invoke-WebRequest\" in the build script:</p><p> </p><p><code>Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.</code></p>",
2106
&laughs,
2107
false,
2108
),
2109
"Build script error",
2110
),
2111
message(
2112
channel,
2113
"t8r1",
2114
Some("t8"),
2115
(JONAS_ID, "Jonas Ortega"),
2116
at(0, 11, 30),
2117
"<p>Add <code>-UseBasicParsing</code> to the call, that fixes it.</p>",
2118
"[]",
2119
false,
2120
),
2121
]
2122
}
2123
2087
2124
fn shared_channel_messages(
2088
2125
channel: &str,
2089
2126
mara: (&str, &str),
@@ -916,6 +916,7 @@ pub fn seed_directory(state: &mut AppState) {916
state.own_email = DEMO_USER_EMAIL.to_owned();916
state.own_email = DEMO_USER_EMAIL.to_owned();917
state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());917
state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());918
state.translation.settings = Some(language_settings());918
state.translation.settings = Some(language_settings());919
state.apply_date_locale();919
state.translation.languages = language_list();920
state.translation.languages = language_list();920
let directory = &mut state.directory;921
let directory = &mut state.directory;921
directory.me = Some(Person {922
directory.me = Some(Person {@@ -2080,10 +2081,46 @@ fn channel_messages() -> Vec<MessageRecord> {2080
),2081
),2081
];2082
];2082
records.extend(rollout_replies);2083
records.extend(rollout_replies);2084
records.extend(code_post(channel, tobias));2083
records.extend(shared_channel_messages(channel, mara, tobias));2085
records.extend(shared_channel_messages(channel, mara, tobias));2084
records2086
records2085
}2087
}2086
2088
2089
fn code_post(channel: &str, tobias: (&str, &str)) -> Vec<MessageRecord> {2090
let laughs = reactions_json(vec![reaction(2091
"laugh",2092
&[2093
(PRIYA_ID, "Priya Nair", at(0, 11, 20)),2094
(JONAS_ID, "Jonas Ortega", at(0, 11, 22)),2095
],2096
)]);2097
vec![2098
with_subject(2099
message(2100
channel,2101
"t8",2102
None,2103
tobias,2104
at(0, 11, 5),2105
"<p>I got this error message when running \"Invoke-WebRequest\" in the build script:</p><p> </p><p><code>Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.</code></p>",2106
&laughs,2107
false,2108
),2109
"Build script error",2110
),2111
message(2112
channel,2113
"t8r1",2114
Some("t8"),2115
(JONAS_ID, "Jonas Ortega"),2116
at(0, 11, 30),2117
"<p>Add <code>-UseBasicParsing</code> to the call, that fixes it.</p>",2118
"[]",2119
false,2120
),2121
]2122
}2123
2087
fn shared_channel_messages(2124
fn shared_channel_messages(2088
channel: &str,2125
channel: &str,2089
mara: (&str, &str),2126
mara: (&str, &str),@@ -27,6 +27,15 @@ const META_USER_ID: &str = "me_user_id";
27
27
type TranslationOutcome = Result<Vec<Translation>, String>;
28
28
29
29
impl AppState {
30
pub fn apply_date_locale(&self) {
31
crate::format::set_date_locale(
32
self.translation
33
.settings
34
.as_ref()
35
.and_then(|settings| settings.display_locale.as_deref()),
36
);
37
}
38
30
39
pub fn load_cached_translation_settings(&mut self) {
31
40
self.translation.settings = self
32
41
.store
@@ -35,6 +44,7 @@ impl AppState {
35
44
.flatten()
36
45
.and_then(|text| serde_json::from_str::<Value>(&text).ok())
37
46
.and_then(|value| parse_language_settings(&value).ok());
47
self.apply_date_locale();
38
48
self.translation.languages = self
39
49
.store
40
50
.meta(LANGUAGES_META_KEY)
@@ -119,6 +129,7 @@ impl AppState {
119
129
this.update(cx, |state, cx| {
120
130
if let Ok(settings) = settings {
121
131
state.translation.settings = Some(settings);
132
state.apply_date_locale();
122
133
state.save_translation_settings();
123
134
}
124
135
if let Some(languages) = languages.filter(|languages| !languages.is_empty()) {
@@ -27,6 +27,15 @@ const META_USER_ID: &str = "me_user_id";27
type TranslationOutcome = Result<Vec<Translation>, String>;27
type TranslationOutcome = Result<Vec<Translation>, String>;28
28
29
impl AppState {29
impl AppState {30
pub fn apply_date_locale(&self) {31
crate::format::set_date_locale(32
self.translation33
.settings34
.as_ref()35
.and_then(|settings| settings.display_locale.as_deref()),36
);37
}38
30
pub fn load_cached_translation_settings(&mut self) {39
pub fn load_cached_translation_settings(&mut self) {31
self.translation.settings = self40
self.translation.settings = self32
.store41
.store@@ -35,6 +44,7 @@ impl AppState {35
.flatten()44
.flatten()36
.and_then(|text| serde_json::from_str::<Value>(&text).ok())45
.and_then(|text| serde_json::from_str::<Value>(&text).ok())37
.and_then(|value| parse_language_settings(&value).ok());46
.and_then(|value| parse_language_settings(&value).ok());47
self.apply_date_locale();38
self.translation.languages = self48
self.translation.languages = self39
.store49
.store40
.meta(LANGUAGES_META_KEY)50
.meta(LANGUAGES_META_KEY)@@ -119,6 +129,7 @@ impl AppState {119
this.update(cx, |state, cx| {129
this.update(cx, |state, cx| {120
if let Ok(settings) = settings {130
if let Ok(settings) = settings {121
state.translation.settings = Some(settings);131
state.translation.settings = Some(settings);132
state.apply_date_locale();122
state.save_translation_settings();133
state.save_translation_settings();123
}134
}124
if let Some(languages) = languages.filter(|languages| !languages.is_empty()) {135
if let Some(languages) = languages.filter(|languages| !languages.is_empty()) {@@ -122,6 +122,18 @@ impl Inline {
122
122
padded
123
123
}
124
124
125
fn slice(&self, range: Range<usize>) -> Inline {
126
let mut part = Inline::default();
127
for segment in &self.segments {
128
let start = segment.range.start.max(range.start);
129
let end = segment.range.end.min(range.end);
130
if start < end {
131
part.push(&self.text[start..end], segment.style, segment.link.as_deref());
132
}
133
}
134
part
135
}
136
125
137
pub fn is_blank(&self) -> bool {
126
138
self.text.trim().is_empty()
127
139
}
@@ -174,6 +186,9 @@ pub enum Block {
174
186
language: Option<String>,
175
187
code: String,
176
188
},
189
CodeLine {
190
code: String,
191
},
177
192
Reply {
178
193
message_id: Option<String>,
179
194
children: Vec<Block>,
@@ -206,6 +221,7 @@ impl Block {
206
221
match self {
207
222
Block::Paragraph(inline) | Block::Heading { inline, .. } => Some(inline.plain_text()),
208
223
Block::Code { code, .. } => Some(format!("```\n{code}\n```")),
224
Block::CodeLine { code } => Some(format!("`{code}`")),
209
225
Block::List {
210
226
ordered,
211
227
start,
@@ -240,7 +256,7 @@ impl Block {
240
256
pub fn first_line(&self) -> Option<String> {
241
257
match self {
242
258
Block::Paragraph(inline) | Block::Heading { inline, .. } => Some(inline.plain_text()),
243
Block::Code { code, .. } => Some(code.clone()),
259
Block::Code { code, .. } | Block::CodeLine { code } => Some(code.clone()),
244
260
Block::List { items, .. } => items.first()?.iter().find_map(Block::first_line),
245
261
Block::Table { rows, .. } => Some(rows.first()?.first()?.plain_text()),
246
262
Block::Quote(children) => children.iter().find_map(Block::first_line),
@@ -317,16 +333,20 @@ pub fn strip_image_placeholders(blocks: Vec<Block>) -> Vec<Block> {
317
333
}
318
334
319
335
pub fn layout_blocks(spans: &[Span]) -> Vec<Block> {
320
layout_blocks_with(spans, true)
336
layout_blocks_with(spans, true, true)
337
}
338
339
pub fn layout_card_blocks(spans: &[Span]) -> Vec<Block> {
340
layout_blocks_with(spans, true, false)
321
341
}
322
342
323
fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
343
fn layout_blocks_with(spans: &[Span], split_images: bool, frame_code: bool) -> Vec<Block> {
324
344
let mut blocks = Vec::new();
325
345
let mut current = Inline::default();
326
346
for span in spans {
327
347
match span {
328
348
Span::CodeBlock { language, code } => {
329
flush(&mut current, &mut blocks, Block::Paragraph);
349
flush(&mut current, &mut blocks, frame_code);
330
350
blocks.push(Block::Code {
331
351
language: language.clone(),
332
352
code: code.trim_end_matches('\n').to_owned(),
@@ -336,8 +356,8 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
336
356
message_id,
337
357
children,
338
358
} => {
339
flush(&mut current, &mut blocks, Block::Paragraph);
340
let mut inner = layout_blocks_with(children, false);
359
flush(&mut current, &mut blocks, frame_code);
360
let mut inner = layout_blocks_with(children, false, frame_code);
341
361
unlink(&mut inner);
342
362
if !inner.is_empty() {
343
363
blocks.push(Block::Reply {
@@ -347,8 +367,8 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
347
367
}
348
368
}
349
369
Span::BlockQuote(children) => {
350
flush(&mut current, &mut blocks, Block::Paragraph);
351
let inner = layout_blocks_with(children, false);
370
flush(&mut current, &mut blocks, frame_code);
371
let inner = layout_blocks_with(children, false, frame_code);
352
372
if !inner.is_empty() {
353
373
blocks.push(Block::Quote(inner));
354
374
}
@@ -358,10 +378,10 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
358
378
start,
359
379
items,
360
380
} => {
361
flush(&mut current, &mut blocks, Block::Paragraph);
381
flush(&mut current, &mut blocks, frame_code);
362
382
let items: Vec<Vec<Block>> = items
363
383
.iter()
364
.map(|item| layout_blocks_with(item, false))
384
.map(|item| layout_blocks_with(item, false, frame_code))
365
385
.filter(|item| !item.is_empty())
366
386
.collect();
367
387
if !items.is_empty() {
@@ -373,7 +393,7 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
373
393
}
374
394
}
375
395
Span::Table { header, rows } => {
376
flush(&mut current, &mut blocks, Block::Paragraph);
396
flush(&mut current, &mut blocks, frame_code);
377
397
let rows: Vec<Vec<Inline>> = rows
378
398
.iter()
379
399
.map(|row| row.iter().map(|cell| inline_of(cell)).collect())
@@ -386,7 +406,7 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
386
406
}
387
407
}
388
408
Span::Heading { level, children } => {
389
flush(&mut current, &mut blocks, Block::Paragraph);
409
flush(&mut current, &mut blocks, frame_code);
390
410
let inline = inline_of(children);
391
411
if !inline.is_blank() {
392
412
blocks.push(Block::Heading {
@@ -396,11 +416,11 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
396
416
}
397
417
}
398
418
Span::Rule => {
399
flush(&mut current, &mut blocks, Block::Paragraph);
419
flush(&mut current, &mut blocks, frame_code);
400
420
blocks.push(Block::Rule);
401
421
}
402
422
Span::Image { hosted_content_url } if split_images => {
403
flush(&mut current, &mut blocks, Block::Paragraph);
423
flush(&mut current, &mut blocks, frame_code);
404
424
blocks.push(Block::Image {
405
425
url: hosted_content_url.clone(),
406
426
});
@@ -413,7 +433,7 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {
413
433
),
414
434
}
415
435
}
416
flush(&mut current, &mut blocks, Block::Paragraph);
436
flush(&mut current, &mut blocks, frame_code);
417
437
blocks
418
438
}
419
439
@@ -424,8 +444,7 @@ fn inline_of(spans: &[Span]) -> Inline {
424
444
pad_code(inline)
425
445
}
426
446
427
fn flush(current: &mut Inline, blocks: &mut Vec<Block>, make: fn(Inline) -> Block) {
428
let mut inline = std::mem::take(current);
447
fn trimmed(mut inline: Inline) -> Inline {
429
448
inline.trim_end();
430
449
let leading = inline.text.len() - inline.text.trim_start().len();
431
450
if leading > 0 {
@@ -436,9 +455,62 @@ fn flush(current: &mut Inline, blocks: &mut Vec<Block>, make: fn(Inline) -> Bloc
436
455
segment.range.start < segment.range.end
437
456
});
438
457
}
439
if !inline.is_blank() {
440
blocks.push(make(pad_code(inline)));
458
inline
459
}
460
461
fn flush(current: &mut Inline, blocks: &mut Vec<Block>, frame_code: bool) {
462
let inline = trimmed(std::mem::take(current));
463
if inline.is_blank() {
464
return;
465
}
466
if !frame_code {
467
blocks.push(Block::Paragraph(pad_code(inline)));
468
return;
469
}
470
for piece in split_code_lines(inline) {
471
match piece {
472
LinePiece::Text(text) => {
473
let text = trimmed(text);
474
if !text.is_blank() {
475
blocks.push(Block::Paragraph(pad_code(text)));
476
}
477
}
478
LinePiece::Code(code) => blocks.push(Block::CodeLine { code }),
479
}
480
}
481
}
482
483
fn is_own_line(text: &str, range: &Range<usize>) -> bool {
484
let before = &text[..range.start];
485
let after = &text[range.end..];
486
let line_start = before.rfind('\n').map_or(0, |position| position + 1);
487
let line_end = after.find('\n').unwrap_or(after.len());
488
before[line_start..].trim().is_empty() && after[..line_end].trim().is_empty()
489
}
490
491
enum LinePiece {
492
Text(Inline),
493
Code(String),
494
}
495
496
fn split_code_lines(inline: Inline) -> Vec<LinePiece> {
497
let mut pieces = Vec::new();
498
let mut cursor = 0;
499
for segment in &inline.segments {
500
let code = &inline.text[segment.range.clone()];
501
if !segment.style.code
502
|| segment.link.is_some()
503
|| code.trim().is_empty()
504
|| !is_own_line(&inline.text, &segment.range)
505
{
506
continue;
507
}
508
pieces.push(LinePiece::Text(inline.slice(cursor..segment.range.start)));
509
pieces.push(LinePiece::Code(code.trim().to_owned()));
510
cursor = segment.range.end;
441
511
}
512
pieces.push(LinePiece::Text(inline.slice(cursor..inline.text.len())));
513
pieces
442
514
}
443
515
444
516
fn pad_code(inline: Inline) -> Inline {
@@ -961,6 +1033,28 @@ mod tests {
961
1033
assert_eq!(inline.segments[2].style.background, Some(0xffff00));
962
1034
}
963
1035
1036
#[test]
1037
fn code_alone_on_its_line_is_one_framed_block() {
1038
let blocks = layout_blocks(&[
1039
text("error:"),
1040
Span::LineBreak,
1041
Span::Code("a long line".into()),
1042
]);
1043
assert_eq!(
1044
blocks,
1045
vec![
1046
Block::Paragraph(Inline::plain("error:")),
1047
Block::CodeLine {
1048
code: "a long line".into()
1049
},
1050
]
1051
);
1052
assert!(matches!(
1053
layout_card_blocks(&[Span::Code("mono".into())]).as_slice(),
1054
[Block::Paragraph(_)]
1055
));
1056
}
1057
964
1058
#[test]
965
1059
fn inline_code_gets_room_next_to_text() {
966
1060
let inline = paragraph_inline(&[
@@ -122,6 +122,18 @@ impl Inline {122
padded122
padded123
}123
}124
124
125
fn slice(&self, range: Range<usize>) -> Inline {126
let mut part = Inline::default();127
for segment in &self.segments {128
let start = segment.range.start.max(range.start);129
let end = segment.range.end.min(range.end);130
if start < end {131
part.push(&self.text[start..end], segment.style, segment.link.as_deref());132
}133
}134
part135
}136
125
pub fn is_blank(&self) -> bool {137
pub fn is_blank(&self) -> bool {126
self.text.trim().is_empty()138
self.text.trim().is_empty()127
}139
}@@ -174,6 +186,9 @@ pub enum Block {174
language: Option<String>,186
language: Option<String>,175
code: String,187
code: String,176
},188
},189
CodeLine {190
code: String,191
},177
Reply {192
Reply {178
message_id: Option<String>,193
message_id: Option<String>,179
children: Vec<Block>,194
children: Vec<Block>,@@ -206,6 +221,7 @@ impl Block {206
match self {221
match self {207
Block::Paragraph(inline) | Block::Heading { inline, .. } => Some(inline.plain_text()),222
Block::Paragraph(inline) | Block::Heading { inline, .. } => Some(inline.plain_text()),208
Block::Code { code, .. } => Some(format!("```\n{code}\n```")),223
Block::Code { code, .. } => Some(format!("```\n{code}\n```")),224
Block::CodeLine { code } => Some(format!("`{code}`")),209
Block::List {225
Block::List {210
ordered,226
ordered,211
start,227
start,@@ -240,7 +256,7 @@ impl Block {240
pub fn first_line(&self) -> Option<String> {256
pub fn first_line(&self) -> Option<String> {241
match self {257
match self {242
Block::Paragraph(inline) | Block::Heading { inline, .. } => Some(inline.plain_text()),258
Block::Paragraph(inline) | Block::Heading { inline, .. } => Some(inline.plain_text()),243
Block::Code { code, .. } => Some(code.clone()),259
Block::Code { code, .. } | Block::CodeLine { code } => Some(code.clone()),244
Block::List { items, .. } => items.first()?.iter().find_map(Block::first_line),260
Block::List { items, .. } => items.first()?.iter().find_map(Block::first_line),245
Block::Table { rows, .. } => Some(rows.first()?.first()?.plain_text()),261
Block::Table { rows, .. } => Some(rows.first()?.first()?.plain_text()),246
Block::Quote(children) => children.iter().find_map(Block::first_line),262
Block::Quote(children) => children.iter().find_map(Block::first_line),@@ -317,16 +333,20 @@ pub fn strip_image_placeholders(blocks: Vec<Block>) -> Vec<Block> {317
}333
}318
334
319
pub fn layout_blocks(spans: &[Span]) -> Vec<Block> {335
pub fn layout_blocks(spans: &[Span]) -> Vec<Block> {320
layout_blocks_with(spans, true)336
layout_blocks_with(spans, true, true)337
}338
339
pub fn layout_card_blocks(spans: &[Span]) -> Vec<Block> {340
layout_blocks_with(spans, true, false)321
}341
}322
342
323
fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {343
fn layout_blocks_with(spans: &[Span], split_images: bool, frame_code: bool) -> Vec<Block> {324
let mut blocks = Vec::new();344
let mut blocks = Vec::new();325
let mut current = Inline::default();345
let mut current = Inline::default();326
for span in spans {346
for span in spans {327
match span {347
match span {328
Span::CodeBlock { language, code } => {348
Span::CodeBlock { language, code } => {329
flush(&mut current, &mut blocks, Block::Paragraph);349
flush(&mut current, &mut blocks, frame_code);330
blocks.push(Block::Code {350
blocks.push(Block::Code {331
language: language.clone(),351
language: language.clone(),332
code: code.trim_end_matches('\n').to_owned(),352
code: code.trim_end_matches('\n').to_owned(),@@ -336,8 +356,8 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {336
message_id,356
message_id,337
children,357
children,338
} => {358
} => {339
flush(&mut current, &mut blocks, Block::Paragraph);359
flush(&mut current, &mut blocks, frame_code);340
let mut inner = layout_blocks_with(children, false);360
let mut inner = layout_blocks_with(children, false, frame_code);341
unlink(&mut inner);361
unlink(&mut inner);342
if !inner.is_empty() {362
if !inner.is_empty() {343
blocks.push(Block::Reply {363
blocks.push(Block::Reply {@@ -347,8 +367,8 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {347
}367
}348
}368
}349
Span::BlockQuote(children) => {369
Span::BlockQuote(children) => {350
flush(&mut current, &mut blocks, Block::Paragraph);370
flush(&mut current, &mut blocks, frame_code);351
let inner = layout_blocks_with(children, false);371
let inner = layout_blocks_with(children, false, frame_code);352
if !inner.is_empty() {372
if !inner.is_empty() {353
blocks.push(Block::Quote(inner));373
blocks.push(Block::Quote(inner));354
}374
}@@ -358,10 +378,10 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {358
start,378
start,359
items,379
items,360
} => {380
} => {361
flush(&mut current, &mut blocks, Block::Paragraph);381
flush(&mut current, &mut blocks, frame_code);362
let items: Vec<Vec<Block>> = items382
let items: Vec<Vec<Block>> = items363
.iter()383
.iter()364
.map(|item| layout_blocks_with(item, false))384
.map(|item| layout_blocks_with(item, false, frame_code))365
.filter(|item| !item.is_empty())385
.filter(|item| !item.is_empty())366
.collect();386
.collect();367
if !items.is_empty() {387
if !items.is_empty() {@@ -373,7 +393,7 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {373
}393
}374
}394
}375
Span::Table { header, rows } => {395
Span::Table { header, rows } => {376
flush(&mut current, &mut blocks, Block::Paragraph);396
flush(&mut current, &mut blocks, frame_code);377
let rows: Vec<Vec<Inline>> = rows397
let rows: Vec<Vec<Inline>> = rows378
.iter()398
.iter()379
.map(|row| row.iter().map(|cell| inline_of(cell)).collect())399
.map(|row| row.iter().map(|cell| inline_of(cell)).collect())@@ -386,7 +406,7 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {386
}406
}387
}407
}388
Span::Heading { level, children } => {408
Span::Heading { level, children } => {389
flush(&mut current, &mut blocks, Block::Paragraph);409
flush(&mut current, &mut blocks, frame_code);390
let inline = inline_of(children);410
let inline = inline_of(children);391
if !inline.is_blank() {411
if !inline.is_blank() {392
blocks.push(Block::Heading {412
blocks.push(Block::Heading {@@ -396,11 +416,11 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {396
}416
}397
}417
}398
Span::Rule => {418
Span::Rule => {399
flush(&mut current, &mut blocks, Block::Paragraph);419
flush(&mut current, &mut blocks, frame_code);400
blocks.push(Block::Rule);420
blocks.push(Block::Rule);401
}421
}402
Span::Image { hosted_content_url } if split_images => {422
Span::Image { hosted_content_url } if split_images => {403
flush(&mut current, &mut blocks, Block::Paragraph);423
flush(&mut current, &mut blocks, frame_code);404
blocks.push(Block::Image {424
blocks.push(Block::Image {405
url: hosted_content_url.clone(),425
url: hosted_content_url.clone(),406
});426
});@@ -413,7 +433,7 @@ fn layout_blocks_with(spans: &[Span], split_images: bool) -> Vec<Block> {413
),433
),414
}434
}415
}435
}416
flush(&mut current, &mut blocks, Block::Paragraph);436
flush(&mut current, &mut blocks, frame_code);417
blocks437
blocks418
}438
}419
439
@@ -424,8 +444,7 @@ fn inline_of(spans: &[Span]) -> Inline {424
pad_code(inline)444
pad_code(inline)425
}445
}426
446
427
fn flush(current: &mut Inline, blocks: &mut Vec<Block>, make: fn(Inline) -> Block) {447
fn trimmed(mut inline: Inline) -> Inline {428
let mut inline = std::mem::take(current);429
inline.trim_end();448
inline.trim_end();430
let leading = inline.text.len() - inline.text.trim_start().len();449
let leading = inline.text.len() - inline.text.trim_start().len();431
if leading > 0 {450
if leading > 0 {@@ -436,9 +455,62 @@ fn flush(current: &mut Inline, blocks: &mut Vec<Block>, make: fn(Inline) -> Bloc436
segment.range.start < segment.range.end455
segment.range.start < segment.range.end437
});456
});438
}457
}439
if !inline.is_blank() {458
inline440
blocks.push(make(pad_code(inline)));459
}460
461
fn flush(current: &mut Inline, blocks: &mut Vec<Block>, frame_code: bool) {462
let inline = trimmed(std::mem::take(current));463
if inline.is_blank() {464
return;465
}466
if !frame_code {467
blocks.push(Block::Paragraph(pad_code(inline)));468
return;469
}470
for piece in split_code_lines(inline) {471
match piece {472
LinePiece::Text(text) => {473
let text = trimmed(text);474
if !text.is_blank() {475
blocks.push(Block::Paragraph(pad_code(text)));476
}477
}478
LinePiece::Code(code) => blocks.push(Block::CodeLine { code }),479
}480
}481
}482
483
fn is_own_line(text: &str, range: &Range<usize>) -> bool {484
let before = &text[..range.start];485
let after = &text[range.end..];486
let line_start = before.rfind('\n').map_or(0, |position| position + 1);487
let line_end = after.find('\n').unwrap_or(after.len());488
before[line_start..].trim().is_empty() && after[..line_end].trim().is_empty()489
}490
491
enum LinePiece {492
Text(Inline),493
Code(String),494
}495
496
fn split_code_lines(inline: Inline) -> Vec<LinePiece> {497
let mut pieces = Vec::new();498
let mut cursor = 0;499
for segment in &inline.segments {500
let code = &inline.text[segment.range.clone()];501
if !segment.style.code502
|| segment.link.is_some()503
|| code.trim().is_empty()504
|| !is_own_line(&inline.text, &segment.range)505
{506
continue;507
}508
pieces.push(LinePiece::Text(inline.slice(cursor..segment.range.start)));509
pieces.push(LinePiece::Code(code.trim().to_owned()));510
cursor = segment.range.end;441
}511
}512
pieces.push(LinePiece::Text(inline.slice(cursor..inline.text.len())));513
pieces442
}514
}443
515
444
fn pad_code(inline: Inline) -> Inline {516
fn pad_code(inline: Inline) -> Inline {@@ -961,6 +1033,28 @@ mod tests {961
assert_eq!(inline.segments[2].style.background, Some(0xffff00));1033
assert_eq!(inline.segments[2].style.background, Some(0xffff00));962
}1034
}963
1035
1036
#[test]1037
fn code_alone_on_its_line_is_one_framed_block() {1038
let blocks = layout_blocks(&[1039
text("error:"),1040
Span::LineBreak,1041
Span::Code("a long line".into()),1042
]);1043
assert_eq!(1044
blocks,1045
vec![1046
Block::Paragraph(Inline::plain("error:")),1047
Block::CodeLine {1048
code: "a long line".into()1049
},1050
]1051
);1052
assert!(matches!(1053
layout_card_blocks(&[Span::Code("mono".into())]).as_slice(),1054
[Block::Paragraph(_)]1055
));1056
}1057
964
#[test]1058
#[test]965
fn inline_code_gets_room_next_to_text() {1059
fn inline_code_gets_room_next_to_text() {966
let inline = paragraph_inline(&[1060
let inline = paragraph_inline(&[@@ -18,6 +18,11 @@ const CODE_HEADER_MIN_LINES: usize = 3;
18
18
const PLAIN_LANGUAGE: &str = "text";
19
19
const MIN_CONTRAST: f32 = 4.5;
20
20
const HIGHLIGHT_ALPHA: f32 = 0.3;
21
const CODE_LINE_PADDING_X: f32 = 6.;
22
const CODE_LINE_PADDING_Y: f32 = 4.;
23
const CODE_LINE_RADIUS: f32 = 4.;
24
pub const CODE_LINE_TAG: &str = "message/code-line";
25
pub const CODE_BLOCK_TAG: &str = "message/code-block";
21
26
22
27
pub fn render_blocks(blocks: &[Block], id: &str, own: bool, cx: &App) -> AnyElement {
23
28
render_block_list(blocks, id, own, 0, cx)
@@ -47,6 +52,7 @@ fn render_block(block: &Block, id: String, own: bool, depth: usize, cx: &App) ->
47
52
.child(render_inline(inline, id, own, cx))
48
53
.into_any_element(),
49
54
Block::Code { language, code } => render_code(language.as_deref(), code, id, own, cx),
55
Block::CodeLine { code } => render_code_line(code, id, own, cx),
50
56
Block::Reply {
51
57
message_id,
52
58
children,
@@ -125,9 +131,12 @@ fn render_code(language: Option<&str>, code: &str, id: String, own: bool, cx: &A
125
131
));
126
132
let show_header = language.is_some() || code.lines().count() >= CODE_HEADER_MIN_LINES;
127
133
v_flex()
134
.debug_selector(|| CODE_BLOCK_TAG.into())
128
135
.w_full()
129
136
.rounded(px(8.))
130
137
.overflow_hidden()
138
.border_1()
139
.border_color(theme::code_frame())
131
140
.bg(theme::code_surface())
132
141
.text_color(theme::text_strong())
133
142
.font_family(code_font(cx))
@@ -145,6 +154,40 @@ fn render_code(language: Option<&str>, code: &str, id: String, own: bool, cx: &A
145
154
.into_any_element()
146
155
}
147
156
157
fn render_code_line(code: &str, id: String, own: bool, cx: &App) -> AnyElement {
158
h_flex()
159
.w_full()
160
.child(
161
div()
162
.debug_selector(|| CODE_LINE_TAG.into())
163
.min_w_0()
164
.flex_shrink(1.)
165
.px(px(CODE_LINE_PADDING_X))
166
.py(px(CODE_LINE_PADDING_Y))
167
.rounded(px(CODE_LINE_RADIUS))
168
.border_1()
169
.border_color(theme::code_frame())
170
.font_family(code_font(cx))
171
.text_size(px(12.5))
172
.line_height(relative(1.5))
173
.text_color(code_text(own))
174
.child(SelectableRichText::new(
175
ElementId::Name(id.into()),
176
code.to_owned(),
177
Vec::new(),
178
)),
179
)
180
.into_any_element()
181
}
182
183
fn code_text(own: bool) -> Hsla {
184
if own {
185
theme::accent_soft()
186
} else {
187
theme::red_soft()
188
}
189
}
190
148
191
fn code_header(language: &str, code: &str, id: &str, own: bool) -> Div {
149
192
let muted = if own {
150
193
theme::own_meta()
@@ -371,7 +414,7 @@ fn pill_for(range: std::ops::Range<usize>, style: StyleFlags, own: bool) -> Opti
371
414
return Some(Pill {
372
415
range,
373
416
fill: theme::inline_code_fill(own),
374
border: Some(theme::inline_code_border()),
417
border: Some(theme::code_frame()),
375
418
radius: px(4.),
376
419
});
377
420
}
@@ -398,11 +441,7 @@ fn highlight_for(style: StyleFlags, own: bool) -> HighlightStyle {
398
441
highlight.color = Some(readable(color, own));
399
442
}
400
443
if style.code {
401
highlight.color = Some(if own {
402
theme::accent_soft()
403
} else {
404
theme::text_strong()
405
});
444
highlight.color = Some(code_text(own));
406
445
}
407
446
if style.underline {
408
447
highlight.underline = Some(UnderlineStyle {
@@ -18,6 +18,11 @@ const CODE_HEADER_MIN_LINES: usize = 3;18
const PLAIN_LANGUAGE: &str = "text";18
const PLAIN_LANGUAGE: &str = "text";19
const MIN_CONTRAST: f32 = 4.5;19
const MIN_CONTRAST: f32 = 4.5;20
const HIGHLIGHT_ALPHA: f32 = 0.3;20
const HIGHLIGHT_ALPHA: f32 = 0.3;21
const CODE_LINE_PADDING_X: f32 = 6.;22
const CODE_LINE_PADDING_Y: f32 = 4.;23
const CODE_LINE_RADIUS: f32 = 4.;24
pub const CODE_LINE_TAG: &str = "message/code-line";25
pub const CODE_BLOCK_TAG: &str = "message/code-block";21
26
22
pub fn render_blocks(blocks: &[Block], id: &str, own: bool, cx: &App) -> AnyElement {27
pub fn render_blocks(blocks: &[Block], id: &str, own: bool, cx: &App) -> AnyElement {23
render_block_list(blocks, id, own, 0, cx)28
render_block_list(blocks, id, own, 0, cx)@@ -47,6 +52,7 @@ fn render_block(block: &Block, id: String, own: bool, depth: usize, cx: &App) ->47
.child(render_inline(inline, id, own, cx))52
.child(render_inline(inline, id, own, cx))48
.into_any_element(),53
.into_any_element(),49
Block::Code { language, code } => render_code(language.as_deref(), code, id, own, cx),54
Block::Code { language, code } => render_code(language.as_deref(), code, id, own, cx),55
Block::CodeLine { code } => render_code_line(code, id, own, cx),50
Block::Reply {56
Block::Reply {51
message_id,57
message_id,52
children,58
children,@@ -125,9 +131,12 @@ fn render_code(language: Option<&str>, code: &str, id: String, own: bool, cx: &A125
));131
));126
let show_header = language.is_some() || code.lines().count() >= CODE_HEADER_MIN_LINES;132
let show_header = language.is_some() || code.lines().count() >= CODE_HEADER_MIN_LINES;127
v_flex()133
v_flex()134
.debug_selector(|| CODE_BLOCK_TAG.into())128
.w_full()135
.w_full()129
.rounded(px(8.))136
.rounded(px(8.))130
.overflow_hidden()137
.overflow_hidden()138
.border_1()139
.border_color(theme::code_frame())131
.bg(theme::code_surface())140
.bg(theme::code_surface())132
.text_color(theme::text_strong())141
.text_color(theme::text_strong())133
.font_family(code_font(cx))142
.font_family(code_font(cx))@@ -145,6 +154,40 @@ fn render_code(language: Option<&str>, code: &str, id: String, own: bool, cx: &A145
.into_any_element()154
.into_any_element()146
}155
}147
156
157
fn render_code_line(code: &str, id: String, own: bool, cx: &App) -> AnyElement {158
h_flex()159
.w_full()160
.child(161
div()162
.debug_selector(|| CODE_LINE_TAG.into())163
.min_w_0()164
.flex_shrink(1.)165
.px(px(CODE_LINE_PADDING_X))166
.py(px(CODE_LINE_PADDING_Y))167
.rounded(px(CODE_LINE_RADIUS))168
.border_1()169
.border_color(theme::code_frame())170
.font_family(code_font(cx))171
.text_size(px(12.5))172
.line_height(relative(1.5))173
.text_color(code_text(own))174
.child(SelectableRichText::new(175
ElementId::Name(id.into()),176
code.to_owned(),177
Vec::new(),178
)),179
)180
.into_any_element()181
}182
183
fn code_text(own: bool) -> Hsla {184
if own {185
theme::accent_soft()186
} else {187
theme::red_soft()188
}189
}190
148
fn code_header(language: &str, code: &str, id: &str, own: bool) -> Div {191
fn code_header(language: &str, code: &str, id: &str, own: bool) -> Div {149
let muted = if own {192
let muted = if own {150
theme::own_meta()193
theme::own_meta()@@ -371,7 +414,7 @@ fn pill_for(range: std::ops::Range<usize>, style: StyleFlags, own: bool) -> Opti371
return Some(Pill {414
return Some(Pill {372
range,415
range,373
fill: theme::inline_code_fill(own),416
fill: theme::inline_code_fill(own),374
border: Some(theme::inline_code_border()),417
border: Some(theme::code_frame()),375
radius: px(4.),418
radius: px(4.),376
});419
});377
}420
}@@ -398,11 +441,7 @@ fn highlight_for(style: StyleFlags, own: bool) -> HighlightStyle {398
highlight.color = Some(readable(color, own));441
highlight.color = Some(readable(color, own));399
}442
}400
if style.code {443
if style.code {401
highlight.color = Some(if own {444
highlight.color = Some(code_text(own));402
theme::accent_soft()403
} else {404
theme::text_strong()405
});406
}445
}407
if style.underline {446
if style.underline {408
highlight.underline = Some(UnderlineStyle {447
highlight.underline = Some(UnderlineStyle {@@ -5,5 +5,5 @@ pub mod hooks;
5
5
mod selectable;
6
6
mod syntax;
7
7
8
pub use blocks::{Block, layout_blocks};
9
pub use elements::render_blocks;
8
pub use blocks::{Block, layout_blocks, layout_card_blocks};
9
pub use elements::{CODE_BLOCK_TAG, CODE_LINE_TAG, render_blocks};
@@ -5,5 +5,5 @@ pub mod hooks;5
mod selectable;5
mod selectable;6
mod syntax;6
mod syntax;7
7
8
pub use blocks::{Block, layout_blocks};8
pub use blocks::{Block, layout_blocks, layout_card_blocks};9
pub use elements::render_blocks;9
pub use elements::{CODE_BLOCK_TAG, CODE_LINE_TAG, render_blocks};@@ -184,7 +184,11 @@ mod frames {
184
184
CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
185
185
CHANNEL_DETAILS_TAG,
186
186
};
187
use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG};
187
use crate::render::{CODE_BLOCK_TAG, CODE_LINE_TAG};
188
use crate::views::conversation::{FEED_EDGE_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG};
189
use crate::views::post_card::{
190
POST_AVATAR_TAG, POST_BODY_TAG, POST_CARD_TAG, POST_FOOTER_AVATAR_TAG,
191
};
188
192
use crate::views::find_panel::{
189
193
FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,
190
194
};
@@ -1533,6 +1537,83 @@ mod frames {
1533
1537
assert!(visual.debug_bounds(PIN_BANNER_TAG).is_none());
1534
1538
}
1535
1539
1540
fn open_channel(cx: &mut TestAppContext, awaited: &'static str) -> VisualTestContext {
1541
let (handle, state) = mount(cx);
1542
let mut visual = VisualTestContext::from_window(handle, cx);
1543
visual.simulate_resize(size(px(1280.), px(800.)));
1544
visual.update(|_, cx| {
1545
state.update(cx, |state, cx| {
1546
state.select(Selection::Channel(PINNED_CHANNEL.to_owned()), cx)
1547
})
1548
});
1549
collect(&mut visual, Some(awaited));
1550
visual
1551
}
1552
1553
#[gpui_kit::test]
1554
fn channel_posts_start_the_body_at_the_avatar_edge_like_teams(cx: &mut TestAppContext) {
1555
let mut visual = open_channel(cx, POST_FOOTER_AVATAR_TAG);
1556
let bounds_of = |visual: &mut VisualTestContext, path: &'static str| {
1557
visual
1558
.debug_bounds(path)
1559
.unwrap_or_else(|| panic!("{path} rendered"))
1560
};
1561
let card = bounds_of(&mut visual, POST_CARD_TAG);
1562
let avatar = bounds_of(&mut visual, POST_AVATAR_TAG);
1563
let body = bounds_of(&mut visual, POST_BODY_TAG);
1564
let footer_avatar = bounds_of(&mut visual, POST_FOOTER_AVATAR_TAG);
1565
let side = f32::from(avatar.left() - card.left());
1566
let checks = [
1567
("body left", f32::from(body.left() - avatar.left())),
1568
("footer avatar left", f32::from(footer_avatar.left() - avatar.left())),
1569
("body right inset", f32::from(card.right() - body.right()) - side),
1570
];
1571
for (name, gap) in checks {
1572
assert!(
1573
gap.abs() < INSET_TOLERANCE,
1574
"{name} off by {gap}: card {card:?} avatar {avatar:?} body {body:?} footer {footer_avatar:?}"
1575
);
1576
}
1577
}
1578
1579
#[gpui_kit::test]
1580
fn a_code_line_is_one_frame_inside_the_post_body(cx: &mut TestAppContext) {
1581
let mut visual = open_channel(cx, CODE_LINE_TAG);
1582
let code = visual.debug_bounds(CODE_LINE_TAG).expect("code line");
1583
let body = visual.debug_bounds(POST_BODY_TAG).expect("post body");
1584
assert!(
1585
f32::from(code.size.height) > 40.,
1586
"the long code line wraps inside one frame: {code:?}"
1587
);
1588
assert!(
1589
(f32::from(code.left() - body.left())).abs() < INSET_TOLERANCE
1590
&& code.right() <= body.right() + px(INSET_TOLERANCE),
1591
"code {code:?} sits inside the body {body:?}"
1592
);
1593
assert!(visual.debug_bounds(CODE_BLOCK_TAG).is_none());
1594
}
1595
1596
#[gpui_kit::test]
1597
fn the_new_post_row_shows_a_scroll_edge_only_while_scrolled(cx: &mut TestAppContext) {
1598
let mut visual = open_channel(cx, POST_CARD_TAG);
1599
assert!(visual.debug_bounds(FEED_EDGE_TAG).is_none());
1600
let timeline = visual.debug_bounds(TIMELINE_TAG).expect("timeline");
1601
visual.simulate_event(ScrollWheelEvent {
1602
position: timeline.center(),
1603
delta: ScrollDelta::Pixels(point(px(0.), px(-400.))),
1604
..Default::default()
1605
});
1606
collect(&mut visual, Some(FEED_EDGE_TAG));
1607
let edge = visual.debug_bounds(FEED_EDGE_TAG).expect("feed edge");
1608
let timeline = visual.debug_bounds(TIMELINE_TAG).expect("timeline");
1609
assert!(
1610
(f32::from(edge.top() - timeline.top())).abs() < INSET_TOLERANCE
1611
&& (f32::from(edge.left() - timeline.left())).abs() < INSET_TOLERANCE
1612
&& (f32::from(timeline.right() - edge.right())).abs() < INSET_TOLERANCE,
1613
"edge {edge:?} runs across the top of the timeline {timeline:?}"
1614
);
1615
}
1616
1536
1617
#[gpui_kit::test]
1537
1618
fn the_channel_details_pane_lists_pinned_posts_inside_the_main_island(cx: &mut TestAppContext) {
1538
1619
let (handle, state) = mount(cx);
@@ -1821,6 +1902,11 @@ const OUTLINE_ALLOWLIST: &[(&str, &str, &str)] = &[
1821
1902
"theme::code_header_border()",
1822
1903
"message content drawn as Teams renders it",
1823
1904
),
1905
(
1906
"render/elements.rs",
1907
"theme::code_frame()",
1908
"message content drawn as Teams renders it",
1909
),
1824
1910
("views/call_transcript.rs", "theme::border()", "input field"),
1825
1911
(
1826
1912
"views/conversation.rs",
@@ -184,7 +184,11 @@ mod frames {184
CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,184
CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,185
CHANNEL_DETAILS_TAG,185
CHANNEL_DETAILS_TAG,186
};186
};187
use crate::views::conversation::{HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG};187
use crate::render::{CODE_BLOCK_TAG, CODE_LINE_TAG};188
use crate::views::conversation::{FEED_EDGE_TAG, HEADER_DIVIDER, MEMBERS_BUTTON, TIMELINE_TAG};189
use crate::views::post_card::{190
POST_AVATAR_TAG, POST_BODY_TAG, POST_CARD_TAG, POST_FOOTER_AVATAR_TAG,191
};188
use crate::views::find_panel::{192
use crate::views::find_panel::{189
FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,193
FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,190
};194
};@@ -1533,6 +1537,83 @@ mod frames {1533
assert!(visual.debug_bounds(PIN_BANNER_TAG).is_none());1537
assert!(visual.debug_bounds(PIN_BANNER_TAG).is_none());1534
}1538
}1535
1539
1540
fn open_channel(cx: &mut TestAppContext, awaited: &'static str) -> VisualTestContext {1541
let (handle, state) = mount(cx);1542
let mut visual = VisualTestContext::from_window(handle, cx);1543
visual.simulate_resize(size(px(1280.), px(800.)));1544
visual.update(|_, cx| {1545
state.update(cx, |state, cx| {1546
state.select(Selection::Channel(PINNED_CHANNEL.to_owned()), cx)1547
})1548
});1549
collect(&mut visual, Some(awaited));1550
visual1551
}1552
1553
#[gpui_kit::test]1554
fn channel_posts_start_the_body_at_the_avatar_edge_like_teams(cx: &mut TestAppContext) {1555
let mut visual = open_channel(cx, POST_FOOTER_AVATAR_TAG);1556
let bounds_of = |visual: &mut VisualTestContext, path: &'static str| {1557
visual1558
.debug_bounds(path)1559
.unwrap_or_else(|| panic!("{path} rendered"))1560
};1561
let card = bounds_of(&mut visual, POST_CARD_TAG);1562
let avatar = bounds_of(&mut visual, POST_AVATAR_TAG);1563
let body = bounds_of(&mut visual, POST_BODY_TAG);1564
let footer_avatar = bounds_of(&mut visual, POST_FOOTER_AVATAR_TAG);1565
let side = f32::from(avatar.left() - card.left());1566
let checks = [1567
("body left", f32::from(body.left() - avatar.left())),1568
("footer avatar left", f32::from(footer_avatar.left() - avatar.left())),1569
("body right inset", f32::from(card.right() - body.right()) - side),1570
];1571
for (name, gap) in checks {1572
assert!(1573
gap.abs() < INSET_TOLERANCE,1574
"{name} off by {gap}: card {card:?} avatar {avatar:?} body {body:?} footer {footer_avatar:?}"1575
);1576
}1577
}1578
1579
#[gpui_kit::test]1580
fn a_code_line_is_one_frame_inside_the_post_body(cx: &mut TestAppContext) {1581
let mut visual = open_channel(cx, CODE_LINE_TAG);1582
let code = visual.debug_bounds(CODE_LINE_TAG).expect("code line");1583
let body = visual.debug_bounds(POST_BODY_TAG).expect("post body");1584
assert!(1585
f32::from(code.size.height) > 40.,1586
"the long code line wraps inside one frame: {code:?}"1587
);1588
assert!(1589
(f32::from(code.left() - body.left())).abs() < INSET_TOLERANCE1590
&& code.right() <= body.right() + px(INSET_TOLERANCE),1591
"code {code:?} sits inside the body {body:?}"1592
);1593
assert!(visual.debug_bounds(CODE_BLOCK_TAG).is_none());1594
}1595
1596
#[gpui_kit::test]1597
fn the_new_post_row_shows_a_scroll_edge_only_while_scrolled(cx: &mut TestAppContext) {1598
let mut visual = open_channel(cx, POST_CARD_TAG);1599
assert!(visual.debug_bounds(FEED_EDGE_TAG).is_none());1600
let timeline = visual.debug_bounds(TIMELINE_TAG).expect("timeline");1601
visual.simulate_event(ScrollWheelEvent {1602
position: timeline.center(),1603
delta: ScrollDelta::Pixels(point(px(0.), px(-400.))),1604
..Default::default()1605
});1606
collect(&mut visual, Some(FEED_EDGE_TAG));1607
let edge = visual.debug_bounds(FEED_EDGE_TAG).expect("feed edge");1608
let timeline = visual.debug_bounds(TIMELINE_TAG).expect("timeline");1609
assert!(1610
(f32::from(edge.top() - timeline.top())).abs() < INSET_TOLERANCE1611
&& (f32::from(edge.left() - timeline.left())).abs() < INSET_TOLERANCE1612
&& (f32::from(timeline.right() - edge.right())).abs() < INSET_TOLERANCE,1613
"edge {edge:?} runs across the top of the timeline {timeline:?}"1614
);1615
}1616
1536
#[gpui_kit::test]1617
#[gpui_kit::test]1537
fn the_channel_details_pane_lists_pinned_posts_inside_the_main_island(cx: &mut TestAppContext) {1618
fn the_channel_details_pane_lists_pinned_posts_inside_the_main_island(cx: &mut TestAppContext) {1538
let (handle, state) = mount(cx);1619
let (handle, state) = mount(cx);@@ -1821,6 +1902,11 @@ const OUTLINE_ALLOWLIST: &[(&str, &str, &str)] = &[1821
"theme::code_header_border()",1902
"theme::code_header_border()",1822
"message content drawn as Teams renders it",1903
"message content drawn as Teams renders it",1823
),1904
),1905
(1906
"render/elements.rs",1907
"theme::code_frame()",1908
"message content drawn as Teams renders it",1909
),1824
("views/call_transcript.rs", "theme::border()", "input field"),1910
("views/call_transcript.rs", "theme::border()", "input field"),1825
(1911
(1826
"views/conversation.rs",1912
"views/conversation.rs",@@ -24,7 +24,7 @@ use super::card_widgets::{
24
24
use super::widgets::symbol;
25
25
use crate::app_state::{AppHandle, AppState};
26
26
use crate::card_state::{ActionPhase, CardScope, CardState};
27
use crate::render::{layout_blocks, render_blocks};
27
use crate::render::{layout_card_blocks, render_blocks};
28
28
use crate::theme;
29
29
30
30
const CARD_WIDTH: f32 = 480.;
@@ -491,7 +491,7 @@ fn text_view(text: &CardText, id: &str, cx: &App) -> AnyElement {
491
491
(true, Some(lines)) => element.text_ellipsis().line_clamp(lines),
492
492
(true, None) => element,
493
493
})
494
.child(render_blocks(&layout_blocks(&text.spans), id, false, cx))
494
.child(render_blocks(&layout_card_blocks(&text.spans), id, false, cx))
495
495
.into_any_element()
496
496
}
497
497
@@ -515,7 +515,7 @@ fn facts_view(facts: &[CardFact], id: &str, cx: &App) -> AnyElement {
515
515
.child(fact.title.clone()),
516
516
)
517
517
.child(div().flex_1().min_w(px(0.)).child(render_blocks(
518
&layout_blocks(&fact.value),
518
&layout_card_blocks(&fact.value),
519
519
&format!("{id}-{index}"),
520
520
false,
521
521
cx,
@@ -24,7 +24,7 @@ use super::card_widgets::{24
use super::widgets::symbol;24
use super::widgets::symbol;25
use crate::app_state::{AppHandle, AppState};25
use crate::app_state::{AppHandle, AppState};26
use crate::card_state::{ActionPhase, CardScope, CardState};26
use crate::card_state::{ActionPhase, CardScope, CardState};27
use crate::render::{layout_blocks, render_blocks};27
use crate::render::{layout_card_blocks, render_blocks};28
use crate::theme;28
use crate::theme;29
29
30
const CARD_WIDTH: f32 = 480.;30
const CARD_WIDTH: f32 = 480.;@@ -491,7 +491,7 @@ fn text_view(text: &CardText, id: &str, cx: &App) -> AnyElement {491
(true, Some(lines)) => element.text_ellipsis().line_clamp(lines),491
(true, Some(lines)) => element.text_ellipsis().line_clamp(lines),492
(true, None) => element,492
(true, None) => element,493
})493
})494
.child(render_blocks(&layout_blocks(&text.spans), id, false, cx))494
.child(render_blocks(&layout_card_blocks(&text.spans), id, false, cx))495
.into_any_element()495
.into_any_element()496
}496
}497
497
@@ -515,7 +515,7 @@ fn facts_view(facts: &[CardFact], id: &str, cx: &App) -> AnyElement {515
.child(fact.title.clone()),515
.child(fact.title.clone()),516
)516
)517
.child(div().flex_1().min_w(px(0.)).child(render_blocks(517
.child(div().flex_1().min_w(px(0.)).child(render_blocks(518
&layout_blocks(&fact.value),518
&layout_card_blocks(&fact.value),519
&format!("{id}-{index}"),519
&format!("{id}-{index}"),520
false,520
false,521
cx,521
cx,@@ -16,6 +16,7 @@ use super::call_extras::open_invite_picker;
16
16
use super::call_organizer::{pill, tile_menu};
17
17
use super::call_view::{BANNER_HEIGHT, CHAT_PANEL_WIDTH, MENU_WIDTH, round_control};
18
18
use super::widgets::{Corner, corner_badge, count_badge, icon};
19
use super::scroll_edge::with_top_edge;
19
20
use crate::app_state::AppState;
20
21
use crate::call::{
21
22
ActiveCall, CallModel, OptionsDialog, PeopleSections, PersonRow, people_sections,
@@ -25,6 +26,7 @@ use crate::theme::{self, ElevatedSurface as _};
25
26
use calling::MeetingOptions;
26
27
27
28
const HEADER_HEIGHT: f32 = 48.;
29
const PEOPLE_SCROLL_DIVIDER: &str = "shell/islands/main/call-people/divider-scroll";
28
30
const ROW_HEIGHT: f32 = 44.;
29
31
const AVATAR_SIZE: f32 = 28.;
30
32
const MORE_SIZE: f32 = 24.;
@@ -440,6 +442,7 @@ pub fn people_panel(app: &Entity<AppState>, state: &AppState, call: &ActiveCall)
440
442
.min_h_0()
441
443
.w_full()
442
444
.overflow_y_scroll()
445
.track_scroll(&call.people_scroll)
443
446
.pb(px(12.))
444
447
.children(model.can_admit().then(|| lobby_section(app, state, §ions)).flatten())
445
448
.when(!sections.hands.is_empty(), |list| {
@@ -469,7 +472,7 @@ pub fn people_panel(app: &Entity<AppState>, state: &AppState, call: &ActiveCall)
469
472
.overflow_hidden()
470
473
.bg(theme::surface())
471
474
.child(panel_header(app, model, sections.count))
472
.child(body)
475
.child(with_top_edge(body, &call.people_scroll, PEOPLE_SCROLL_DIVIDER))
473
476
.into_any_element(),
474
477
)
475
478
}
@@ -16,6 +16,7 @@ use super::call_extras::open_invite_picker;16
use super::call_organizer::{pill, tile_menu};16
use super::call_organizer::{pill, tile_menu};17
use super::call_view::{BANNER_HEIGHT, CHAT_PANEL_WIDTH, MENU_WIDTH, round_control};17
use super::call_view::{BANNER_HEIGHT, CHAT_PANEL_WIDTH, MENU_WIDTH, round_control};18
use super::widgets::{Corner, corner_badge, count_badge, icon};18
use super::widgets::{Corner, corner_badge, count_badge, icon};19
use super::scroll_edge::with_top_edge;19
use crate::app_state::AppState;20
use crate::app_state::AppState;20
use crate::call::{21
use crate::call::{21
ActiveCall, CallModel, OptionsDialog, PeopleSections, PersonRow, people_sections,22
ActiveCall, CallModel, OptionsDialog, PeopleSections, PersonRow, people_sections,@@ -25,6 +26,7 @@ use crate::theme::{self, ElevatedSurface as _};25
use calling::MeetingOptions;26
use calling::MeetingOptions;26
27
27
const HEADER_HEIGHT: f32 = 48.;28
const HEADER_HEIGHT: f32 = 48.;29
const PEOPLE_SCROLL_DIVIDER: &str = "shell/islands/main/call-people/divider-scroll";28
const ROW_HEIGHT: f32 = 44.;30
const ROW_HEIGHT: f32 = 44.;29
const AVATAR_SIZE: f32 = 28.;31
const AVATAR_SIZE: f32 = 28.;30
const MORE_SIZE: f32 = 24.;32
const MORE_SIZE: f32 = 24.;@@ -440,6 +442,7 @@ pub fn people_panel(app: &Entity<AppState>, state: &AppState, call: &ActiveCall)440
.min_h_0()442
.min_h_0()441
.w_full()443
.w_full()442
.overflow_y_scroll()444
.overflow_y_scroll()445
.track_scroll(&call.people_scroll)443
.pb(px(12.))446
.pb(px(12.))444
.children(model.can_admit().then(|| lobby_section(app, state, §ions)).flatten())447
.children(model.can_admit().then(|| lobby_section(app, state, §ions)).flatten())445
.when(!sections.hands.is_empty(), |list| {448
.when(!sections.hands.is_empty(), |list| {@@ -469,7 +472,7 @@ pub fn people_panel(app: &Entity<AppState>, state: &AppState, call: &ActiveCall)469
.overflow_hidden()472
.overflow_hidden()470
.bg(theme::surface())473
.bg(theme::surface())471
.child(panel_header(app, model, sections.count))474
.child(panel_header(app, model, sections.count))472
.child(body)475
.child(with_top_edge(body, &call.people_scroll, PEOPLE_SCROLL_DIVIDER))473
.into_any_element(),476
.into_any_element(),474
)477
)475
}478
}@@ -100,6 +100,7 @@ use shared::SharedState;
100
100
pub const MEMBERS_BUTTON: &str = "shell/islands/main/members-button";
101
101
pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";
102
102
pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";
103
pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";
103
104
const HEADER_HEIGHT: f32 = 60.;
104
105
const HEADER_PADDING: f32 = 20.;
105
106
const HEADER_GAP: f32 = 12.;
@@ -224,6 +225,8 @@ pub struct ConversationView {
224
225
pin_index: usize,
225
226
channel_details_open: bool,
226
227
pinned_posts_expanded: bool,
228
channel_details_scroll: ScrollHandle,
229
scroller_watch: Option<(EntityId, Subscription)>,
227
230
pin_previews: HashMap<String, pins::PinPreview>,
228
231
pin_fetches: HashSet<String>,
229
232
notice: Option<String>,
@@ -557,6 +560,8 @@ impl ConversationView {
557
560
pin_index: 0,
558
561
channel_details_open: false,
559
562
pinned_posts_expanded: false,
563
channel_details_scroll: ScrollHandle::new(),
564
scroller_watch: None,
560
565
pin_previews: HashMap::new(),
561
566
pin_fetches: HashSet::new(),
562
567
notice: None,
@@ -1286,8 +1291,7 @@ impl ConversationView {
1286
1291
.reply_to_id
1287
1292
.clone()
1288
1293
.unwrap_or_else(|| record.message_id.clone());
1289
let quote = record.reply_to_id.is_some().then_some(preview);
1290
self.open_reply_editor(root_id, quote, window, cx);
1294
self.open_reply_editor(root_id, Some(preview), window, cx);
1291
1295
return;
1292
1296
}
1293
1297
self.composer.update(cx, |composer, cx| {
@@ -1467,6 +1471,23 @@ impl ConversationView {
1467
1471
})
1468
1472
}
1469
1473
1474
fn watch_feed_scroll(&mut self, cx: &mut Context<Self>) {
1475
let scroller_id = self.scroller.entity_id();
1476
if self
1477
.scroller_watch
1478
.as_ref()
1479
.is_some_and(|(watched, _)| *watched == scroller_id)
1480
{
1481
return;
1482
}
1483
let subscription = cx.observe(&self.scroller, |this, _, cx| {
1484
if this.in_feed() {
1485
cx.notify();
1486
}
1487
});
1488
self.scroller_watch = Some((scroller_id, subscription));
1489
}
1490
1470
1491
fn rebuild(&mut self, reset: bool, cx: &mut Context<Self>) {
1471
1492
let Some(current) = self.current.as_ref() else {
1472
1493
let mut rows: Vec<Row> = self
@@ -3708,6 +3729,8 @@ impl Render for ConversationView {
3708
3729
let recap_active = self.recap_active();
3709
3730
let empty_channel = in_feed && self.rows.borrow().is_empty();
3710
3731
let new_post = self.render_new_post(window, cx);
3732
self.watch_feed_scroll(cx);
3733
let feed_scrolled = new_post.is_some() && self.scroller.read(cx).is_scrolled_from_top();
3711
3734
let body = if drafting && self.current.is_none() && self.rows.borrow().is_empty() {
3712
3735
let draft = self.draft.read(cx);
3713
3736
let group_name = draft.group_name(cx);
@@ -3747,6 +3770,15 @@ impl Render for ConversationView {
3747
3770
.child(record_bounds(&self.timeline_bounds, timeline_top_inset))
3748
3771
.on_scroll_wheel(cx.listener(|this, _, _, cx| this.close_reaction_details(cx)))
3749
3772
.child(body)
3773
.when(feed_scrolled, |timeline| {
3774
timeline.child(
3775
edge_divider(FEED_EDGE_TAG)
3776
.absolute()
3777
.top_0()
3778
.left_0()
3779
.right_0(),
3780
)
3781
})
3750
3782
.children(pin_banner.map(pin_banner_overlay)),
3751
3783
)
3752
3784
.children(self.render_draft_error(cx))
@@ -100,6 +100,7 @@ use shared::SharedState;100
pub const MEMBERS_BUTTON: &str = "shell/islands/main/members-button";100
pub const MEMBERS_BUTTON: &str = "shell/islands/main/members-button";101
pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";101
pub const HEADER_DIVIDER: &str = "shell/islands/main/divider-header";102
pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";102
pub const TIMELINE_TAG: &str = "shell/islands/main/timeline";103
pub const FEED_EDGE_TAG: &str = "shell/islands/main/timeline/divider-feed";103
const HEADER_HEIGHT: f32 = 60.;104
const HEADER_HEIGHT: f32 = 60.;104
const HEADER_PADDING: f32 = 20.;105
const HEADER_PADDING: f32 = 20.;105
const HEADER_GAP: f32 = 12.;106
const HEADER_GAP: f32 = 12.;@@ -224,6 +225,8 @@ pub struct ConversationView {224
pin_index: usize,225
pin_index: usize,225
channel_details_open: bool,226
channel_details_open: bool,226
pinned_posts_expanded: bool,227
pinned_posts_expanded: bool,228
channel_details_scroll: ScrollHandle,229
scroller_watch: Option<(EntityId, Subscription)>,227
pin_previews: HashMap<String, pins::PinPreview>,230
pin_previews: HashMap<String, pins::PinPreview>,228
pin_fetches: HashSet<String>,231
pin_fetches: HashSet<String>,229
notice: Option<String>,232
notice: Option<String>,@@ -557,6 +560,8 @@ impl ConversationView {557
pin_index: 0,560
pin_index: 0,558
channel_details_open: false,561
channel_details_open: false,559
pinned_posts_expanded: false,562
pinned_posts_expanded: false,563
channel_details_scroll: ScrollHandle::new(),564
scroller_watch: None,560
pin_previews: HashMap::new(),565
pin_previews: HashMap::new(),561
pin_fetches: HashSet::new(),566
pin_fetches: HashSet::new(),562
notice: None,567
notice: None,@@ -1286,8 +1291,7 @@ impl ConversationView {1286
.reply_to_id1291
.reply_to_id1287
.clone()1292
.clone()1288
.unwrap_or_else(|| record.message_id.clone());1293
.unwrap_or_else(|| record.message_id.clone());1289
let quote = record.reply_to_id.is_some().then_some(preview);1294
self.open_reply_editor(root_id, Some(preview), window, cx);1290
self.open_reply_editor(root_id, quote, window, cx);1291
return;1295
return;1292
}1296
}1293
self.composer.update(cx, |composer, cx| {1297
self.composer.update(cx, |composer, cx| {@@ -1467,6 +1471,23 @@ impl ConversationView {1467
})1471
})1468
}1472
}1469
1473
1474
fn watch_feed_scroll(&mut self, cx: &mut Context<Self>) {1475
let scroller_id = self.scroller.entity_id();1476
if self1477
.scroller_watch1478
.as_ref()1479
.is_some_and(|(watched, _)| *watched == scroller_id)1480
{1481
return;1482
}1483
let subscription = cx.observe(&self.scroller, |this, _, cx| {1484
if this.in_feed() {1485
cx.notify();1486
}1487
});1488
self.scroller_watch = Some((scroller_id, subscription));1489
}1490
1470
fn rebuild(&mut self, reset: bool, cx: &mut Context<Self>) {1491
fn rebuild(&mut self, reset: bool, cx: &mut Context<Self>) {1471
let Some(current) = self.current.as_ref() else {1492
let Some(current) = self.current.as_ref() else {1472
let mut rows: Vec<Row> = self1493
let mut rows: Vec<Row> = self@@ -3708,6 +3729,8 @@ impl Render for ConversationView {3708
let recap_active = self.recap_active();3729
let recap_active = self.recap_active();3709
let empty_channel = in_feed && self.rows.borrow().is_empty();3730
let empty_channel = in_feed && self.rows.borrow().is_empty();3710
let new_post = self.render_new_post(window, cx);3731
let new_post = self.render_new_post(window, cx);3732
self.watch_feed_scroll(cx);3733
let feed_scrolled = new_post.is_some() && self.scroller.read(cx).is_scrolled_from_top();3711
let body = if drafting && self.current.is_none() && self.rows.borrow().is_empty() {3734
let body = if drafting && self.current.is_none() && self.rows.borrow().is_empty() {3712
let draft = self.draft.read(cx);3735
let draft = self.draft.read(cx);3713
let group_name = draft.group_name(cx);3736
let group_name = draft.group_name(cx);@@ -3747,6 +3770,15 @@ impl Render for ConversationView {3747
.child(record_bounds(&self.timeline_bounds, timeline_top_inset))3770
.child(record_bounds(&self.timeline_bounds, timeline_top_inset))3748
.on_scroll_wheel(cx.listener(|this, _, _, cx| this.close_reaction_details(cx)))3771
.on_scroll_wheel(cx.listener(|this, _, _, cx| this.close_reaction_details(cx)))3749
.child(body)3772
.child(body)3773
.when(feed_scrolled, |timeline| {3774
timeline.child(3775
edge_divider(FEED_EDGE_TAG)3776
.absolute()3777
.top_0()3778
.left_0()3779
.right_0(),3780
)3781
})3750
.children(pin_banner.map(pin_banner_overlay)),3782
.children(pin_banner.map(pin_banner_overlay)),3751
)3783
)3752
.children(self.render_draft_error(cx))3784
.children(self.render_draft_error(cx))@@ -15,11 +15,13 @@ use crate::rows::reply_excerpt;
15
15
use crate::theme;
16
16
use crate::views::attachments::file_badge;
17
17
use crate::views::avatar::person_avatar;
18
use crate::views::scroll_edge::with_top_edge;
18
19
19
20
pub const CHANNEL_DETAILS_TAG: &str = "shell/islands/main/channel-details";
20
21
pub const CHANNEL_DETAILS_BUTTON: &str = "shell/islands/main/channel-details-button";
21
22
pub const CHANNEL_DETAILS_PINNED_TAG: &str = "shell/islands/main/channel-details/pinned";
22
23
pub const CHANNEL_DETAILS_SHARED_TAG: &str = "shell/islands/main/channel-details/shared";
24
const CHANNEL_DETAILS_SCROLL_DIVIDER: &str = "shell/islands/main/channel-details/divider-scroll";
23
25
const OPEN_LABEL: &str = "Open channel details";
24
26
const CLOSE_LABEL: &str = "Close channel details";
25
27
const PINNED_TITLE: &str = "Pinned";
@@ -287,14 +289,17 @@ impl ConversationView {
287
289
})),
288
290
),
289
291
)
290
.child(
292
.child(with_top_edge(
291
293
div()
292
294
.id("channel-details-body")
293
295
.flex_1()
294
296
.min_h_0()
295
297
.overflow_y_scroll()
298
.track_scroll(&self.channel_details_scroll)
296
299
.child(body),
297
),
300
&self.channel_details_scroll,
301
CHANNEL_DETAILS_SCROLL_DIVIDER,
302
)),
298
303
)
299
304
.into_any_element(),
300
305
)
@@ -15,11 +15,13 @@ use crate::rows::reply_excerpt;15
use crate::theme;15
use crate::theme;16
use crate::views::attachments::file_badge;16
use crate::views::attachments::file_badge;17
use crate::views::avatar::person_avatar;17
use crate::views::avatar::person_avatar;18
use crate::views::scroll_edge::with_top_edge;18
19
19
pub const CHANNEL_DETAILS_TAG: &str = "shell/islands/main/channel-details";20
pub const CHANNEL_DETAILS_TAG: &str = "shell/islands/main/channel-details";20
pub const CHANNEL_DETAILS_BUTTON: &str = "shell/islands/main/channel-details-button";21
pub const CHANNEL_DETAILS_BUTTON: &str = "shell/islands/main/channel-details-button";21
pub const CHANNEL_DETAILS_PINNED_TAG: &str = "shell/islands/main/channel-details/pinned";22
pub const CHANNEL_DETAILS_PINNED_TAG: &str = "shell/islands/main/channel-details/pinned";22
pub const CHANNEL_DETAILS_SHARED_TAG: &str = "shell/islands/main/channel-details/shared";23
pub const CHANNEL_DETAILS_SHARED_TAG: &str = "shell/islands/main/channel-details/shared";24
const CHANNEL_DETAILS_SCROLL_DIVIDER: &str = "shell/islands/main/channel-details/divider-scroll";23
const OPEN_LABEL: &str = "Open channel details";25
const OPEN_LABEL: &str = "Open channel details";24
const CLOSE_LABEL: &str = "Close channel details";26
const CLOSE_LABEL: &str = "Close channel details";25
const PINNED_TITLE: &str = "Pinned";27
const PINNED_TITLE: &str = "Pinned";@@ -287,14 +289,17 @@ impl ConversationView {287
})),289
})),288
),290
),289
)291
)290
.child(292
.child(with_top_edge(291
div()293
div()292
.id("channel-details-body")294
.id("channel-details-body")293
.flex_1()295
.flex_1()294
.min_h_0()296
.min_h_0()295
.overflow_y_scroll()297
.overflow_y_scroll()298
.track_scroll(&self.channel_details_scroll)296
.child(body),299
.child(body),297
),300
&self.channel_details_scroll,301
CHANNEL_DETAILS_SCROLL_DIVIDER,302
)),298
)303
)299
.into_any_element(),304
.into_any_element(),300
)305
)@@ -20,7 +20,7 @@ use crate::views::channel_tabs::ChannelPane;
20
20
use crate::views::composer::{Composer, ComposerEvent, ReplyPreview};
21
21
use crate::views::widgets::icon;
22
22
23
const REPLY_PLACEHOLDER: &str = "Reply";
23
const REPLY_PLACEHOLDER: &str = "Reply in thread";
24
24
const SUBJECT_PLACEHOLDER: &str = "Add a subject";
25
25
26
26
pub(super) struct FeedStash {
@@ -20,7 +20,7 @@ use crate::views::channel_tabs::ChannelPane;20
use crate::views::composer::{Composer, ComposerEvent, ReplyPreview};20
use crate::views::composer::{Composer, ComposerEvent, ReplyPreview};21
use crate::views::widgets::icon;21
use crate::views::widgets::icon;22
22
23
const REPLY_PLACEHOLDER: &str = "Reply";23
const REPLY_PLACEHOLDER: &str = "Reply in thread";24
const SUBJECT_PLACEHOLDER: &str = "Add a subject";24
const SUBJECT_PLACEHOLDER: &str = "Add a subject";25
25
26
pub(super) struct FeedStash {26
pub(super) struct FeedStash {@@ -198,7 +198,7 @@ impl RenderEnv {
198
198
),
199
199
};
200
200
let actionable = is_real && !message.deleted;
201
let (menu, react, reaction_controls) = view
201
let (menu, react, reaction_controls, add_reaction) = view
202
202
.upgrade()
203
203
.filter(|_| actionable)
204
204
.map(|entity| {
@@ -224,9 +224,10 @@ impl RenderEnv {
224
224
let visible = this.toolbar_visible(&message.key);
225
225
let controls = (!message.reactions.is_empty())
226
226
.then(|| this.reaction_controls(&message.key, view.clone()));
227
(visible.then_some(menu), Some(react), controls)
227
let adder = (!message.reactions.is_empty()).then(|| menu.reaction_adder());
228
(visible.then_some(menu), Some(react), controls, adder)
228
229
})
229
.unwrap_or((None, None, None));
230
.unwrap_or((None, None, None, None));
230
231
let reply = (is_real && !message.deleted).then(|| {
231
232
let (view, key, handle) = (view.clone(), message.key.clone(), window.window_handle());
232
233
boxed(move |cx| {
@@ -297,6 +298,7 @@ impl RenderEnv {
297
298
scheduled_menu,
298
299
react,
299
300
reaction_controls,
301
add_reaction,
300
302
files,
301
303
open_image,
302
304
highlighted: self.highlighted.as_deref() == Some(message.key.as_str()),
@@ -431,7 +433,18 @@ impl RenderEnv {
431
433
})
432
434
}
433
435
436
fn request_author_presence(&self, message: &MessageRow, cx: &mut App) {
437
let Some(sender_id) = message.sender_id.clone().filter(|_| !message.own) else {
438
return;
439
};
440
let app = self.app.clone();
441
cx.defer(move |cx| {
442
app.update(cx, |state, cx| state.request_presence(vec![sender_id], cx));
443
});
444
}
445
434
446
pub fn post_actions(&self, post: &PostRow, window: &mut Window, cx: &mut App) -> PostActions {
447
self.request_author_presence(&post.root, cx);
435
448
let root_key = post.root.key.clone();
436
449
let is_local =
437
450
root_key.starts_with(PENDING_KEY_PREFIX) || root_key.starts_with(SCHEDULED_KEY_PREFIX);
@@ -198,7 +198,7 @@ impl RenderEnv {198
),198
),199
};199
};200
let actionable = is_real && !message.deleted;200
let actionable = is_real && !message.deleted;201
let (menu, react, reaction_controls) = view201
let (menu, react, reaction_controls, add_reaction) = view202
.upgrade()202
.upgrade()203
.filter(|_| actionable)203
.filter(|_| actionable)204
.map(|entity| {204
.map(|entity| {@@ -224,9 +224,10 @@ impl RenderEnv {224
let visible = this.toolbar_visible(&message.key);224
let visible = this.toolbar_visible(&message.key);225
let controls = (!message.reactions.is_empty())225
let controls = (!message.reactions.is_empty())226
.then(|| this.reaction_controls(&message.key, view.clone()));226
.then(|| this.reaction_controls(&message.key, view.clone()));227
(visible.then_some(menu), Some(react), controls)227
let adder = (!message.reactions.is_empty()).then(|| menu.reaction_adder());228
(visible.then_some(menu), Some(react), controls, adder)228
})229
})229
.unwrap_or((None, None, None));230
.unwrap_or((None, None, None, None));230
let reply = (is_real && !message.deleted).then(|| {231
let reply = (is_real && !message.deleted).then(|| {231
let (view, key, handle) = (view.clone(), message.key.clone(), window.window_handle());232
let (view, key, handle) = (view.clone(), message.key.clone(), window.window_handle());232
boxed(move |cx| {233
boxed(move |cx| {@@ -297,6 +298,7 @@ impl RenderEnv {297
scheduled_menu,298
scheduled_menu,298
react,299
react,299
reaction_controls,300
reaction_controls,301
add_reaction,300
files,302
files,301
open_image,303
open_image,302
highlighted: self.highlighted.as_deref() == Some(message.key.as_str()),304
highlighted: self.highlighted.as_deref() == Some(message.key.as_str()),@@ -431,7 +433,18 @@ impl RenderEnv {431
})433
})432
}434
}433
435
436
fn request_author_presence(&self, message: &MessageRow, cx: &mut App) {437
let Some(sender_id) = message.sender_id.clone().filter(|_| !message.own) else {438
return;439
};440
let app = self.app.clone();441
cx.defer(move |cx| {442
app.update(cx, |state, cx| state.request_presence(vec![sender_id], cx));443
});444
}445
434
pub fn post_actions(&self, post: &PostRow, window: &mut Window, cx: &mut App) -> PostActions {446
pub fn post_actions(&self, post: &PostRow, window: &mut Window, cx: &mut App) -> PostActions {447
self.request_author_presence(&post.root, cx);435
let root_key = post.root.key.clone();448
let root_key = post.root.key.clone();436
let is_local =449
let is_local =437
root_key.starts_with(PENDING_KEY_PREFIX) || root_key.starts_with(SCHEDULED_KEY_PREFIX);450
root_key.starts_with(PENDING_KEY_PREFIX) || root_key.starts_with(SCHEDULED_KEY_PREFIX);@@ -14,7 +14,7 @@ use gpui_kit::*;
14
14
15
15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};
16
16
use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};
17
use super::widgets::icon;
17
use super::widgets::{icon, symbol};
18
18
use crate::rows::reaction_glyph;
19
19
use crate::theme::{self, ElevatedSurface as _};
20
20
@@ -23,6 +23,8 @@ const BAR_PADDING: f32 = 3.;
23
23
const BAR_ICON: f32 = 16.;
24
24
const DELEGATE_ITEM_WIDTH: f32 = 188.;
25
25
const DELEGATE_AGENT_SIZE: f32 = 11.;
26
const ADD_REACTION_ICON: f32 = 15.;
27
const ADD_REACTION_EXTRA_WIDTH: f32 = 8.;
26
28
27
29
pub type Action = Rc<dyn Fn(&mut Window, &mut App)>;
28
30
pub type OpenChange = Rc<dyn Fn(bool, &mut Window, &mut App)>;
@@ -99,24 +101,42 @@ fn reaction_button(menu: &MessageMenu, glyph: &str, index: usize) -> AnyElement
99
101
.into_any_element()
100
102
}
101
103
102
fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {
103
let (picker, picker_reset, react, done, mine, pin) = (
104
menu.picker.clone(),
105
menu.picker.clone(),
106
menu.react.clone(),
107
menu.done.clone(),
108
menu.mine.clone(),
109
menu.pin.clone(),
110
);
111
Popover::new(element_id("reaction-picker", &menu.key))
112
.anchor(Anchor::TopRight)
113
.trigger(
114
Button::new(element_id("add-reaction", &menu.key))
115
.child(icon(IconName::Plus, BAR_ICON, theme::text_soft()))
116
.custom(bar_variant(cx))
117
.rounded(px(7.))
118
.size(px(BAR_BUTTON)),
119
)
104
#[derive(Clone)]
105
pub struct ReactionAdder {
106
pub key: String,
107
pub picker: Entity<ReactionPicker>,
108
pub react: PickHandler,
109
pub done: DoneHandler,
110
pub mine: HashSet<String>,
111
pub pin: OpenChange,
112
}
113
114
impl MessageMenu {
115
pub fn reaction_adder(&self) -> ReactionAdder {
116
ReactionAdder {
117
key: self.key.clone(),
118
picker: self.picker.clone(),
119
react: self.react.clone(),
120
done: self.done.clone(),
121
mine: self.mine.clone(),
122
pin: self.pin.clone(),
123
}
124
}
125
}
126
127
fn picker_popover(adder: ReactionAdder, prefix: &str, trigger: Button, anchor: Anchor) -> AnyElement {
128
let ReactionAdder {
129
key,
130
picker,
131
react,
132
done,
133
mine,
134
pin,
135
} = adder;
136
let picker_reset = picker.clone();
137
Popover::new(element_id(prefix, &key))
138
.anchor(anchor)
139
.trigger(trigger)
120
140
.on_open_change(move |open, window, cx| {
121
141
pin(*open, window, cx);
122
142
if *open {
@@ -133,6 +153,36 @@ fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {
133
153
.into_any_element()
134
154
}
135
155
156
fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {
157
let trigger = Button::new(element_id("add-reaction", &menu.key))
158
.child(icon(IconName::Plus, BAR_ICON, theme::text_soft()))
159
.custom(bar_variant(cx))
160
.rounded(px(7.))
161
.size(px(BAR_BUTTON));
162
picker_popover(
163
menu.reaction_adder(),
164
"reaction-picker",
165
trigger,
166
Anchor::TopRight,
167
)
168
}
169
170
pub fn add_reaction_pill(adder: ReactionAdder, height: f32, cx: &App) -> AnyElement {
171
let trigger = Button::new(element_id("pill-add-reaction", &adder.key))
172
.child(symbol("mood", ADD_REACTION_ICON, theme::text_muted()))
173
.custom(
174
ButtonCustomVariant::new(cx)
175
.color(theme::border_strong())
176
.foreground(theme::text_muted())
177
.hover(theme::popup_hover())
178
.active(theme::popup_hover()),
179
)
180
.rounded(px(height / 2.))
181
.h(px(height))
182
.w(px(height + ADD_REACTION_EXTRA_WIDTH));
183
picker_popover(adder, "pill-reaction-picker", trigger, Anchor::TopLeft)
184
}
185
136
186
fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {
137
187
let (
138
188
reply,
@@ -14,7 +14,7 @@ use gpui_kit::*;14
14
15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};15
use super::reaction_picker::{DoneHandler, PickHandler, ReactionPicker};16
use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};16
use super::toolbar_placement::{HoverChange, TOOLBAR_HEIGHT, toolbar_slot};17
use super::widgets::icon;17
use super::widgets::{icon, symbol};18
use crate::rows::reaction_glyph;18
use crate::rows::reaction_glyph;19
use crate::theme::{self, ElevatedSurface as _};19
use crate::theme::{self, ElevatedSurface as _};20
20
@@ -23,6 +23,8 @@ const BAR_PADDING: f32 = 3.;23
const BAR_ICON: f32 = 16.;23
const BAR_ICON: f32 = 16.;24
const DELEGATE_ITEM_WIDTH: f32 = 188.;24
const DELEGATE_ITEM_WIDTH: f32 = 188.;25
const DELEGATE_AGENT_SIZE: f32 = 11.;25
const DELEGATE_AGENT_SIZE: f32 = 11.;26
const ADD_REACTION_ICON: f32 = 15.;27
const ADD_REACTION_EXTRA_WIDTH: f32 = 8.;26
28
27
pub type Action = Rc<dyn Fn(&mut Window, &mut App)>;29
pub type Action = Rc<dyn Fn(&mut Window, &mut App)>;28
pub type OpenChange = Rc<dyn Fn(bool, &mut Window, &mut App)>;30
pub type OpenChange = Rc<dyn Fn(bool, &mut Window, &mut App)>;@@ -99,24 +101,42 @@ fn reaction_button(menu: &MessageMenu, glyph: &str, index: usize) -> AnyElement99
.into_any_element()101
.into_any_element()100
}102
}101
103
102
fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {104
#[derive(Clone)]103
let (picker, picker_reset, react, done, mine, pin) = (105
pub struct ReactionAdder {104
menu.picker.clone(),106
pub key: String,105
menu.picker.clone(),107
pub picker: Entity<ReactionPicker>,106
menu.react.clone(),108
pub react: PickHandler,107
menu.done.clone(),109
pub done: DoneHandler,108
menu.mine.clone(),110
pub mine: HashSet<String>,109
menu.pin.clone(),111
pub pin: OpenChange,110
);112
}111
Popover::new(element_id("reaction-picker", &menu.key))113
112
.anchor(Anchor::TopRight)114
impl MessageMenu {113
.trigger(115
pub fn reaction_adder(&self) -> ReactionAdder {114
Button::new(element_id("add-reaction", &menu.key))116
ReactionAdder {115
.child(icon(IconName::Plus, BAR_ICON, theme::text_soft()))117
key: self.key.clone(),116
.custom(bar_variant(cx))118
picker: self.picker.clone(),117
.rounded(px(7.))119
react: self.react.clone(),118
.size(px(BAR_BUTTON)),120
done: self.done.clone(),119
)121
mine: self.mine.clone(),122
pin: self.pin.clone(),123
}124
}125
}126
127
fn picker_popover(adder: ReactionAdder, prefix: &str, trigger: Button, anchor: Anchor) -> AnyElement {128
let ReactionAdder {129
key,130
picker,131
react,132
done,133
mine,134
pin,135
} = adder;136
let picker_reset = picker.clone();137
Popover::new(element_id(prefix, &key))138
.anchor(anchor)139
.trigger(trigger)120
.on_open_change(move |open, window, cx| {140
.on_open_change(move |open, window, cx| {121
pin(*open, window, cx);141
pin(*open, window, cx);122
if *open {142
if *open {@@ -133,6 +153,36 @@ fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {133
.into_any_element()153
.into_any_element()134
}154
}135
155
156
fn picker_button(menu: &MessageMenu, cx: &App) -> AnyElement {157
let trigger = Button::new(element_id("add-reaction", &menu.key))158
.child(icon(IconName::Plus, BAR_ICON, theme::text_soft()))159
.custom(bar_variant(cx))160
.rounded(px(7.))161
.size(px(BAR_BUTTON));162
picker_popover(163
menu.reaction_adder(),164
"reaction-picker",165
trigger,166
Anchor::TopRight,167
)168
}169
170
pub fn add_reaction_pill(adder: ReactionAdder, height: f32, cx: &App) -> AnyElement {171
let trigger = Button::new(element_id("pill-add-reaction", &adder.key))172
.child(symbol("mood", ADD_REACTION_ICON, theme::text_muted()))173
.custom(174
ButtonCustomVariant::new(cx)175
.color(theme::border_strong())176
.foreground(theme::text_muted())177
.hover(theme::popup_hover())178
.active(theme::popup_hover()),179
)180
.rounded(px(height / 2.))181
.h(px(height))182
.w(px(height + ADD_REACTION_EXTRA_WIDTH));183
picker_popover(adder, "pill-reaction-picker", trigger, Anchor::TopLeft)184
}185
136
fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {186
fn more_button(menu: &MessageMenu, cx: &App) -> AnyElement {137
let (187
let (138
reply,188
reply,@@ -10,10 +10,10 @@ use super::avatar::{bot_avatar, person_avatar};
10
10
use super::call_card::{CallActions, call_card_row};
11
11
use super::jumbo_emoji::jumbo_row;
12
12
use super::link_preview::{link_preview_card, meeting_join_chip};
13
use super::message_actions::{MessageMenu, message_toolbar};
13
use super::message_actions::{MessageMenu, ReactionAdder, message_toolbar};
14
14
use super::profile_card::opens_profile;
15
15
use super::reaction_picker::PickHandler;
16
use super::reaction_pills::{ReactionControls, reaction_pills};
16
use super::reaction_pills::{PillLook, ReactionControls, reaction_pills};
17
17
use super::reaction_proposal_pill::{ReactionPill, reaction_pill};
18
18
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};
19
19
use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};
@@ -78,6 +78,7 @@ pub struct RowActions {
78
78
pub scheduled_menu: Option<ScheduledMenu>,
79
79
pub react: Option<PickHandler>,
80
80
pub reaction_controls: Option<ReactionControls>,
81
pub add_reaction: Option<ReactionAdder>,
81
82
pub files: Option<FileActions>,
82
83
pub open_image: Option<ImageActions>,
83
84
pub highlighted: bool,
@@ -290,6 +291,7 @@ fn bubble(
290
291
&row.reactions,
291
292
index,
292
293
own,
294
PillLook::Faces,
293
295
directory,
294
296
extras.react.clone(),
295
297
extras.controls.as_ref(),
@@ -674,6 +676,7 @@ pub fn render_message_row(
674
676
scheduled_menu,
675
677
react,
676
678
reaction_controls,
679
add_reaction: _,
677
680
files,
678
681
open_image,
679
682
highlighted,
@@ -10,10 +10,10 @@ use super::avatar::{bot_avatar, person_avatar};10
use super::call_card::{CallActions, call_card_row};10
use super::call_card::{CallActions, call_card_row};11
use super::jumbo_emoji::jumbo_row;11
use super::jumbo_emoji::jumbo_row;12
use super::link_preview::{link_preview_card, meeting_join_chip};12
use super::link_preview::{link_preview_card, meeting_join_chip};13
use super::message_actions::{MessageMenu, message_toolbar};13
use super::message_actions::{MessageMenu, ReactionAdder, message_toolbar};14
use super::profile_card::opens_profile;14
use super::profile_card::opens_profile;15
use super::reaction_picker::PickHandler;15
use super::reaction_picker::PickHandler;16
use super::reaction_pills::{ReactionControls, reaction_pills};16
use super::reaction_pills::{PillLook, ReactionControls, reaction_pills};17
use super::reaction_proposal_pill::{ReactionPill, reaction_pill};17
use super::reaction_proposal_pill::{ReactionPill, reaction_pill};18
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};18
use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};19
use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};19
use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};@@ -78,6 +78,7 @@ pub struct RowActions {78
pub scheduled_menu: Option<ScheduledMenu>,78
pub scheduled_menu: Option<ScheduledMenu>,79
pub react: Option<PickHandler>,79
pub react: Option<PickHandler>,80
pub reaction_controls: Option<ReactionControls>,80
pub reaction_controls: Option<ReactionControls>,81
pub add_reaction: Option<ReactionAdder>,81
pub files: Option<FileActions>,82
pub files: Option<FileActions>,82
pub open_image: Option<ImageActions>,83
pub open_image: Option<ImageActions>,83
pub highlighted: bool,84
pub highlighted: bool,@@ -290,6 +291,7 @@ fn bubble(290
&row.reactions,291
&row.reactions,291
index,292
index,292
own,293
own,294
PillLook::Faces,293
directory,295
directory,294
extras.react.clone(),296
extras.react.clone(),295
extras.controls.as_ref(),297
extras.controls.as_ref(),@@ -674,6 +676,7 @@ pub fn render_message_row(674
scheduled_menu,676
scheduled_menu,675
react,677
react,676
reaction_controls,678
reaction_controls,679
add_reaction: _,677
files,680
files,678
open_image,681
open_image,679
highlighted,682
highlighted,@@ -5,16 +5,16 @@ use gpui_kit::*;
5
5
6
6
use super::adaptive_card::cards_view;
7
7
use super::attachments::{attachments_view, message_body};
8
use super::avatar::{bot_avatar, person_avatar};
8
use super::avatar::{bot_avatar, person_avatar, with_presence};
9
9
use super::call_card::{CallActions, post_call_card};
10
10
use super::call_notice::notice_line;
11
11
use super::link_preview::{link_preview_card, meeting_join_chip};
12
use super::message_actions::message_toolbar;
12
use super::message_actions::{add_reaction_pill, message_toolbar};
13
13
use super::message_row::{
14
14
BODY_SIZE, RowActions, deleted_tombstone, delivery_note, forwarded_header, has_text,
15
15
};
16
16
use super::profile_card::opens_profile;
17
use super::reaction_pills::reaction_pills;
17
use super::reaction_pills::{PILL_HEIGHT, PillLook, reaction_pills};
18
18
use super::reaction_proposal_pill::reaction_pill;
19
19
use super::scheduled_toolbar::scheduled_toolbar;
20
20
use super::toolbar_placement::placed_toolbar;
@@ -35,6 +35,14 @@ const PINNED_LABEL: &str = "Pinned";
35
35
const SLOTS_PER_POST: usize = 64;
36
36
const TOOLBAR_RIGHT_INSET: f32 = 8.;
37
37
const SUBJECT_SIZE: f32 = 14.;
38
const FOOTER_AVATAR: f32 = 20.;
39
const FOOTER_BUTTON_PADDING: f32 = 6.;
40
const FOOTER_BUTTON_VERTICAL: f32 = 4.;
41
const REPLY_IN_THREAD: &str = "Reply in thread";
42
pub const POST_CARD_TAG: &str = "post-card";
43
pub const POST_AVATAR_TAG: &str = "post-card/avatar";
44
pub const POST_BODY_TAG: &str = "post-card/body";
45
pub const POST_FOOTER_AVATAR_TAG: &str = "post-card/footer-avatar";
38
46
39
47
pub type PostAction = Box<dyn Fn(&mut Window, &mut App)>;
40
48
@@ -138,14 +146,27 @@ fn message_content(
138
146
cx,
139
147
));
140
148
if !row.reactions.is_empty() {
141
content = content.child(reaction_pills(
142
&row.reactions,
143
index,
144
false,
145
directory,
146
actions.react.clone(),
147
actions.reaction_controls.as_ref(),
148
));
149
content = content.child(
150
h_flex()
151
.gap(px(4.))
152
.flex_wrap()
153
.items_center()
154
.child(reaction_pills(
155
&row.reactions,
156
index,
157
false,
158
PillLook::Count,
159
directory,
160
actions.react.clone(),
161
actions.reaction_controls.as_ref(),
162
))
163
.children(
164
actions
165
.add_reaction
166
.clone()
167
.map(|adder| add_reaction_pill(adder, PILL_HEIGHT, cx)),
168
),
169
);
149
170
}
150
171
content
151
172
}
@@ -161,16 +182,7 @@ fn message_header(
161
182
h_flex()
162
183
.gap(px(6.))
163
184
.items_center()
164
.child(
165
opens_profile(
166
div().id(ElementId::Name(format!("post-author-{index}").into())),
167
profile_user,
168
)
169
.text_size(px(13.))
170
.font_weight(FontWeight::SEMIBOLD)
171
.text_color(theme::text())
172
.child(author),
173
)
185
.child(author_name(index, author, profile_user))
174
186
.child(
175
187
div()
176
188
.text_size(px(11.))
@@ -187,6 +199,51 @@ fn message_header(
187
199
})
188
200
}
189
201
202
fn author_name(index: usize, author: String, profile_user: Option<&str>) -> Stateful<Div> {
203
opens_profile(
204
div().id(ElementId::Name(format!("post-author-{index}").into())),
205
profile_user,
206
)
207
.text_size(px(13.))
208
.font_weight(FontWeight::SEMIBOLD)
209
.text_color(theme::text())
210
.child(author)
211
}
212
213
fn root_header(
214
row: &MessageRow,
215
index: usize,
216
author: String,
217
profile_user: Option<&str>,
218
saved: bool,
219
pinned: bool,
220
) -> Div {
221
v_flex()
222
.min_w_0()
223
.child(
224
h_flex()
225
.gap(px(6.))
226
.items_center()
227
.child(author_name(index, author, profile_user))
228
.when(saved, |line| {
229
line.child(icon(IconName::Bookmark, 12., theme::accent_text()))
230
})
231
.when(row.delivery == Delivery::Sending, |line| {
232
line.child(symbol("schedule", 13., theme::text_muted()))
233
}),
234
)
235
.child(
236
h_flex()
237
.gap(px(6.))
238
.items_center()
239
.text_size(px(11.))
240
.text_color(theme::text_muted())
241
.child(row.time.clone())
242
.when(row.edited, |line| line.child(edited_marker()))
243
.when(pinned, |line| line.child(pinned_marker())),
244
)
245
}
246
190
247
fn message_block(
191
248
row: &MessageRow,
192
249
index: usize,
@@ -204,9 +261,16 @@ fn message_block(
204
261
.bot
205
262
.as_ref()
206
263
.map_or_else(|| row.author.clone(), |bot| bot.name.clone());
207
let avatar = match &actions.bot {
208
Some(bot) => bot_avatar(bot, size),
209
None => person_avatar(directory, row.sender_id.as_deref(), &row.author, size),
264
let avatar = match (&actions.bot, row.sender_id.as_deref()) {
265
(Some(bot), _) => bot_avatar(bot, size),
266
(None, Some(sender_id)) if role == Role::Root => with_presence(
267
person_avatar(directory, Some(sender_id), &row.author, size),
268
directory.presence_of(sender_id),
269
size,
270
theme::row_hover(),
271
)
272
.into_any_element(),
273
(None, sender_id) => person_avatar(directory, sender_id, &row.author, size),
210
274
};
211
275
if let (Role::Reply, Some(call)) = (role, &row.call)
212
276
&& let Some(notice) = &call.notice
@@ -247,35 +311,62 @@ fn message_block(
247
311
} = actions;
248
312
let note = delivery_note(row, delivery, index);
249
313
let translation = translation_line(row, index, translation_actions.as_ref());
250
let body = v_flex()
251
.flex_1()
314
let subject = row
315
.subject
316
.clone()
317
.filter(|_| role == Role::Root)
318
.map(|subject| {
319
div()
320
.text_size(px(SUBJECT_SIZE))
321
.font_weight(FontWeight::BOLD)
322
.text_color(theme::text())
323
.child(subject)
324
});
325
let details = v_flex()
326
.w_full()
252
327
.min_w_0()
253
328
.gap(px(6.))
254
.child(message_header(
255
row,
256
index,
257
author,
258
profile_user,
259
saved,
260
pinned,
261
))
262
.when_some(
263
row.subject.clone().filter(|_| role == Role::Root),
264
|column, subject| {
265
column.child(
266
div()
267
.text_size(px(SUBJECT_SIZE))
268
.font_weight(FontWeight::BOLD)
269
.text_color(theme::text())
270
.child(subject),
271
)
272
},
273
)
329
.children(subject)
274
330
.child(content)
275
331
.children(translation)
276
332
.children(note)
277
333
.children(agent_run.map(|run| run_chip(&run, theme::surface_raised())))
278
334
.children(reaction_proposal.map(|pill| reaction_pill(pill, &row.key)));
335
let avatar = opens_profile(
336
div().id(ElementId::Name(format!("post-avatar-{index}").into())),
337
profile_user,
338
)
339
.w(px(size))
340
.flex_none()
341
.child(avatar);
342
let layout = match role {
343
Role::Root => v_flex()
344
.w_full()
345
.gap(px(8.))
346
.child(
347
h_flex()
348
.items_center()
349
.gap(px(AVATAR_GAP))
350
.child(avatar.debug_selector(|| POST_AVATAR_TAG.into()))
351
.child(root_header(row, index, author, profile_user, saved, pinned)),
352
)
353
.child(details.debug_selector(|| POST_BODY_TAG.into())),
354
Role::Reply => h_flex().items_start().gap(px(8.)).child(avatar).child(
355
v_flex()
356
.flex_1()
357
.min_w_0()
358
.gap(px(6.))
359
.child(message_header(
360
row,
361
index,
362
author,
363
profile_user,
364
saved,
365
pinned,
366
))
367
.child(details),
368
),
369
};
279
370
div()
280
371
.id(ElementId::Name(format!("post-message-{index}").into()))
281
372
.relative()
@@ -293,21 +384,7 @@ fn message_block(
293
384
.when_some(reply, |block, reply| {
294
385
block.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx))
295
386
})
296
.child(
297
h_flex()
298
.items_start()
299
.gap(px(if role == Role::Root { AVATAR_GAP } else { 8. }))
300
.child(
301
opens_profile(
302
div().id(ElementId::Name(format!("post-avatar-{index}").into())),
303
profile_user,
304
)
305
.w(px(size))
306
.flex_none()
307
.child(avatar),
308
)
309
.child(body),
310
)
387
.child(layout)
311
388
.when_some(menu, |block, menu| {
312
389
block.child(placed_toolbar(
313
390
message_toolbar(menu, cx),
@@ -345,37 +422,50 @@ fn reply_footer(
345
422
post_index: usize,
346
423
open: Option<PostAction>,
347
424
editor: Option<AnyElement>,
425
directory: &Directory,
348
426
) -> Option<Div> {
349
427
let footer = v_flex()
350
428
.w_full()
351
.px(px(CARD_PADDING))
429
.px(px(CARD_PADDING - FOOTER_BUTTON_PADDING))
352
430
.rounded_b(px(CARD_RADIUS))
353
431
.bg(theme::reply_surface());
354
432
if let Some(editor) = editor {
355
return Some(footer.py(px(8.)).child(editor));
433
return Some(footer.px(px(CARD_PADDING)).py(px(8.)).child(editor));
356
434
}
357
435
let open = open?;
436
let own_avatar = directory.me.as_ref().map(|me| {
437
div()
438
.debug_selector(|| POST_FOOTER_AVATAR_TAG.into())
439
.flex_none()
440
.child(person_avatar(
441
directory,
442
Some(&me.user_id),
443
&me.display_name,
444
FOOTER_AVATAR,
445
))
446
});
358
447
Some(
359
footer.h(px(36.)).justify_center().child(
448
footer.py(px(CARD_PADDING - FOOTER_BUTTON_VERTICAL)).child(
360
449
h_flex().child(
361
450
h_flex()
362
451
.id(ElementId::Name(format!("post-reply-{post_index}").into()))
363
.gap(px(6.))
364
.px(px(6.))
365
.py(px(4.))
452
.gap(px(8.))
453
.px(px(FOOTER_BUTTON_PADDING))
454
.py(px(FOOTER_BUTTON_VERTICAL))
366
455
.items_center()
367
456
.rounded(px(6.))
368
457
.cursor_pointer()
369
.text_size(px(12.5))
370
.text_color(theme::text_muted())
458
.text_size(px(13.))
459
.font_weight(FontWeight::SEMIBOLD)
460
.text_color(theme::text_soft())
371
461
.hover(|button| {
372
462
button
373
463
.bg(theme::row_hover())
374
464
.text_color(theme::text_strong())
375
465
})
376
466
.on_click(move |_, window, cx| open(window, cx))
377
.child(icon(IconName::Reply, 14., theme::text_muted()))
378
.child("Reply"),
467
.children(own_avatar)
468
.child(REPLY_IN_THREAD),
379
469
),
380
470
),
381
471
)
@@ -396,6 +486,7 @@ pub fn render_post(
396
486
reply_editor,
397
487
} = actions;
398
488
let mut card = v_flex()
489
.debug_selector(|| POST_CARD_TAG.into())
399
490
.w_full()
400
491
.rounded(px(CARD_RADIUS))
401
492
.bg(theme::row_hover())
@@ -426,7 +517,7 @@ pub fn render_post(
426
517
.when(closes_card, |block| block.rounded_b(px(CARD_RADIUS))),
427
518
);
428
519
}
429
card = card.children(reply_footer(index, open_reply, reply_editor));
520
card = card.children(reply_footer(index, open_reply, reply_editor, directory));
430
521
div()
431
522
.w_full()
432
523
.px(px(20.))
@@ -5,16 +5,16 @@ use gpui_kit::*;5
5
6
use super::adaptive_card::cards_view;6
use super::adaptive_card::cards_view;7
use super::attachments::{attachments_view, message_body};7
use super::attachments::{attachments_view, message_body};8
use super::avatar::{bot_avatar, person_avatar};8
use super::avatar::{bot_avatar, person_avatar, with_presence};9
use super::call_card::{CallActions, post_call_card};9
use super::call_card::{CallActions, post_call_card};10
use super::call_notice::notice_line;10
use super::call_notice::notice_line;11
use super::link_preview::{link_preview_card, meeting_join_chip};11
use super::link_preview::{link_preview_card, meeting_join_chip};12
use super::message_actions::message_toolbar;12
use super::message_actions::{add_reaction_pill, message_toolbar};13
use super::message_row::{13
use super::message_row::{14
BODY_SIZE, RowActions, deleted_tombstone, delivery_note, forwarded_header, has_text,14
BODY_SIZE, RowActions, deleted_tombstone, delivery_note, forwarded_header, has_text,15
};15
};16
use super::profile_card::opens_profile;16
use super::profile_card::opens_profile;17
use super::reaction_pills::reaction_pills;17
use super::reaction_pills::{PILL_HEIGHT, PillLook, reaction_pills};18
use super::reaction_proposal_pill::reaction_pill;18
use super::reaction_proposal_pill::reaction_pill;19
use super::scheduled_toolbar::scheduled_toolbar;19
use super::scheduled_toolbar::scheduled_toolbar;20
use super::toolbar_placement::placed_toolbar;20
use super::toolbar_placement::placed_toolbar;@@ -35,6 +35,14 @@ const PINNED_LABEL: &str = "Pinned";35
const SLOTS_PER_POST: usize = 64;35
const SLOTS_PER_POST: usize = 64;36
const TOOLBAR_RIGHT_INSET: f32 = 8.;36
const TOOLBAR_RIGHT_INSET: f32 = 8.;37
const SUBJECT_SIZE: f32 = 14.;37
const SUBJECT_SIZE: f32 = 14.;38
const FOOTER_AVATAR: f32 = 20.;39
const FOOTER_BUTTON_PADDING: f32 = 6.;40
const FOOTER_BUTTON_VERTICAL: f32 = 4.;41
const REPLY_IN_THREAD: &str = "Reply in thread";42
pub const POST_CARD_TAG: &str = "post-card";43
pub const POST_AVATAR_TAG: &str = "post-card/avatar";44
pub const POST_BODY_TAG: &str = "post-card/body";45
pub const POST_FOOTER_AVATAR_TAG: &str = "post-card/footer-avatar";38
46
39
pub type PostAction = Box<dyn Fn(&mut Window, &mut App)>;47
pub type PostAction = Box<dyn Fn(&mut Window, &mut App)>;40
48
@@ -138,14 +146,27 @@ fn message_content(138
cx,146
cx,139
));147
));140
if !row.reactions.is_empty() {148
if !row.reactions.is_empty() {141
content = content.child(reaction_pills(149
content = content.child(142
&row.reactions,150
h_flex()143
index,151
.gap(px(4.))144
false,152
.flex_wrap()145
directory,153
.items_center()146
actions.react.clone(),154
.child(reaction_pills(147
actions.reaction_controls.as_ref(),155
&row.reactions,148
));156
index,157
false,158
PillLook::Count,159
directory,160
actions.react.clone(),161
actions.reaction_controls.as_ref(),162
))163
.children(164
actions165
.add_reaction166
.clone()167
.map(|adder| add_reaction_pill(adder, PILL_HEIGHT, cx)),168
),169
);149
}170
}150
content171
content151
}172
}@@ -161,16 +182,7 @@ fn message_header(161
h_flex()182
h_flex()162
.gap(px(6.))183
.gap(px(6.))163
.items_center()184
.items_center()164
.child(185
.child(author_name(index, author, profile_user))165
opens_profile(166
div().id(ElementId::Name(format!("post-author-{index}").into())),167
profile_user,168
)169
.text_size(px(13.))170
.font_weight(FontWeight::SEMIBOLD)171
.text_color(theme::text())172
.child(author),173
)174
.child(186
.child(175
div()187
div()176
.text_size(px(11.))188
.text_size(px(11.))@@ -187,6 +199,51 @@ fn message_header(187
})199
})188
}200
}189
201
202
fn author_name(index: usize, author: String, profile_user: Option<&str>) -> Stateful<Div> {203
opens_profile(204
div().id(ElementId::Name(format!("post-author-{index}").into())),205
profile_user,206
)207
.text_size(px(13.))208
.font_weight(FontWeight::SEMIBOLD)209
.text_color(theme::text())210
.child(author)211
}212
213
fn root_header(214
row: &MessageRow,215
index: usize,216
author: String,217
profile_user: Option<&str>,218
saved: bool,219
pinned: bool,220
) -> Div {221
v_flex()222
.min_w_0()223
.child(224
h_flex()225
.gap(px(6.))226
.items_center()227
.child(author_name(index, author, profile_user))228
.when(saved, |line| {229
line.child(icon(IconName::Bookmark, 12., theme::accent_text()))230
})231
.when(row.delivery == Delivery::Sending, |line| {232
line.child(symbol("schedule", 13., theme::text_muted()))233
}),234
)235
.child(236
h_flex()237
.gap(px(6.))238
.items_center()239
.text_size(px(11.))240
.text_color(theme::text_muted())241
.child(row.time.clone())242
.when(row.edited, |line| line.child(edited_marker()))243
.when(pinned, |line| line.child(pinned_marker())),244
)245
}246
190
fn message_block(247
fn message_block(191
row: &MessageRow,248
row: &MessageRow,192
index: usize,249
index: usize,@@ -204,9 +261,16 @@ fn message_block(204
.bot261
.bot205
.as_ref()262
.as_ref()206
.map_or_else(|| row.author.clone(), |bot| bot.name.clone());263
.map_or_else(|| row.author.clone(), |bot| bot.name.clone());207
let avatar = match &actions.bot {264
let avatar = match (&actions.bot, row.sender_id.as_deref()) {208
Some(bot) => bot_avatar(bot, size),265
(Some(bot), _) => bot_avatar(bot, size),209
None => person_avatar(directory, row.sender_id.as_deref(), &row.author, size),266
(None, Some(sender_id)) if role == Role::Root => with_presence(267
person_avatar(directory, Some(sender_id), &row.author, size),268
directory.presence_of(sender_id),269
size,270
theme::row_hover(),271
)272
.into_any_element(),273
(None, sender_id) => person_avatar(directory, sender_id, &row.author, size),210
};274
};211
if let (Role::Reply, Some(call)) = (role, &row.call)275
if let (Role::Reply, Some(call)) = (role, &row.call)212
&& let Some(notice) = &call.notice276
&& let Some(notice) = &call.notice@@ -247,35 +311,62 @@ fn message_block(247
} = actions;311
} = actions;248
let note = delivery_note(row, delivery, index);312
let note = delivery_note(row, delivery, index);249
let translation = translation_line(row, index, translation_actions.as_ref());313
let translation = translation_line(row, index, translation_actions.as_ref());250
let body = v_flex()314
let subject = row251
.flex_1()315
.subject316
.clone()317
.filter(|_| role == Role::Root)318
.map(|subject| {319
div()320
.text_size(px(SUBJECT_SIZE))321
.font_weight(FontWeight::BOLD)322
.text_color(theme::text())323
.child(subject)324
});325
let details = v_flex()326
.w_full()252
.min_w_0()327
.min_w_0()253
.gap(px(6.))328
.gap(px(6.))254
.child(message_header(329
.children(subject)255
row,256
index,257
author,258
profile_user,259
saved,260
pinned,261
))262
.when_some(263
row.subject.clone().filter(|_| role == Role::Root),264
|column, subject| {265
column.child(266
div()267
.text_size(px(SUBJECT_SIZE))268
.font_weight(FontWeight::BOLD)269
.text_color(theme::text())270
.child(subject),271
)272
},273
)274
.child(content)330
.child(content)275
.children(translation)331
.children(translation)276
.children(note)332
.children(note)277
.children(agent_run.map(|run| run_chip(&run, theme::surface_raised())))333
.children(agent_run.map(|run| run_chip(&run, theme::surface_raised())))278
.children(reaction_proposal.map(|pill| reaction_pill(pill, &row.key)));334
.children(reaction_proposal.map(|pill| reaction_pill(pill, &row.key)));335
let avatar = opens_profile(336
div().id(ElementId::Name(format!("post-avatar-{index}").into())),337
profile_user,338
)339
.w(px(size))340
.flex_none()341
.child(avatar);342
let layout = match role {343
Role::Root => v_flex()344
.w_full()345
.gap(px(8.))346
.child(347
h_flex()348
.items_center()349
.gap(px(AVATAR_GAP))350
.child(avatar.debug_selector(|| POST_AVATAR_TAG.into()))351
.child(root_header(row, index, author, profile_user, saved, pinned)),352
)353
.child(details.debug_selector(|| POST_BODY_TAG.into())),354
Role::Reply => h_flex().items_start().gap(px(8.)).child(avatar).child(355
v_flex()356
.flex_1()357
.min_w_0()358
.gap(px(6.))359
.child(message_header(360
row,361
index,362
author,363
profile_user,364
saved,365
pinned,366
))367
.child(details),368
),369
};279
div()370
div()280
.id(ElementId::Name(format!("post-message-{index}").into()))371
.id(ElementId::Name(format!("post-message-{index}").into()))281
.relative()372
.relative()@@ -293,21 +384,7 @@ fn message_block(293
.when_some(reply, |block, reply| {384
.when_some(reply, |block, reply| {294
block.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx))385
block.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx))295
})386
})296
.child(387
.child(layout)297
h_flex()298
.items_start()299
.gap(px(if role == Role::Root { AVATAR_GAP } else { 8. }))300
.child(301
opens_profile(302
div().id(ElementId::Name(format!("post-avatar-{index}").into())),303
profile_user,304
)305
.w(px(size))306
.flex_none()307
.child(avatar),308
)309
.child(body),310
)311
.when_some(menu, |block, menu| {388
.when_some(menu, |block, menu| {312
block.child(placed_toolbar(389
block.child(placed_toolbar(313
message_toolbar(menu, cx),390
message_toolbar(menu, cx),@@ -345,37 +422,50 @@ fn reply_footer(345
post_index: usize,422
post_index: usize,346
open: Option<PostAction>,423
open: Option<PostAction>,347
editor: Option<AnyElement>,424
editor: Option<AnyElement>,425
directory: &Directory,348
) -> Option<Div> {426
) -> Option<Div> {349
let footer = v_flex()427
let footer = v_flex()350
.w_full()428
.w_full()351
.px(px(CARD_PADDING))429
.px(px(CARD_PADDING - FOOTER_BUTTON_PADDING))352
.rounded_b(px(CARD_RADIUS))430
.rounded_b(px(CARD_RADIUS))353
.bg(theme::reply_surface());431
.bg(theme::reply_surface());354
if let Some(editor) = editor {432
if let Some(editor) = editor {355
return Some(footer.py(px(8.)).child(editor));433
return Some(footer.px(px(CARD_PADDING)).py(px(8.)).child(editor));356
}434
}357
let open = open?;435
let open = open?;436
let own_avatar = directory.me.as_ref().map(|me| {437
div()438
.debug_selector(|| POST_FOOTER_AVATAR_TAG.into())439
.flex_none()440
.child(person_avatar(441
directory,442
Some(&me.user_id),443
&me.display_name,444
FOOTER_AVATAR,445
))446
});358
Some(447
Some(359
footer.h(px(36.)).justify_center().child(448
footer.py(px(CARD_PADDING - FOOTER_BUTTON_VERTICAL)).child(360
h_flex().child(449
h_flex().child(361
h_flex()450
h_flex()362
.id(ElementId::Name(format!("post-reply-{post_index}").into()))451
.id(ElementId::Name(format!("post-reply-{post_index}").into()))363
.gap(px(6.))452
.gap(px(8.))364
.px(px(6.))453
.px(px(FOOTER_BUTTON_PADDING))365
.py(px(4.))454
.py(px(FOOTER_BUTTON_VERTICAL))366
.items_center()455
.items_center()367
.rounded(px(6.))456
.rounded(px(6.))368
.cursor_pointer()457
.cursor_pointer()369
.text_size(px(12.5))458
.text_size(px(13.))370
.text_color(theme::text_muted())459
.font_weight(FontWeight::SEMIBOLD)460
.text_color(theme::text_soft())371
.hover(|button| {461
.hover(|button| {372
button462
button373
.bg(theme::row_hover())463
.bg(theme::row_hover())374
.text_color(theme::text_strong())464
.text_color(theme::text_strong())375
})465
})376
.on_click(move |_, window, cx| open(window, cx))466
.on_click(move |_, window, cx| open(window, cx))377
.child(icon(IconName::Reply, 14., theme::text_muted()))467
.children(own_avatar)378
.child("Reply"),468
.child(REPLY_IN_THREAD),379
),469
),380
),470
),381
)471
)@@ -396,6 +486,7 @@ pub fn render_post(396
reply_editor,486
reply_editor,397
} = actions;487
} = actions;398
let mut card = v_flex()488
let mut card = v_flex()489
.debug_selector(|| POST_CARD_TAG.into())399
.w_full()490
.w_full()400
.rounded(px(CARD_RADIUS))491
.rounded(px(CARD_RADIUS))401
.bg(theme::row_hover())492
.bg(theme::row_hover())@@ -426,7 +517,7 @@ pub fn render_post(426
.when(closes_card, |block| block.rounded_b(px(CARD_RADIUS))),517
.when(closes_card, |block| block.rounded_b(px(CARD_RADIUS))),427
);518
);428
}519
}429
card = card.children(reply_footer(index, open_reply, reply_editor));520
card = card.children(reply_footer(index, open_reply, reply_editor, directory));430
div()521
div()431
.w_full()522
.w_full()432
.px(px(20.))523
.px(px(20.))@@ -16,7 +16,7 @@ use crate::reaction_model::{
16
16
use crate::rows::ReactionChip;
17
17
use crate::theme::{self, ElevatedSurface as _};
18
18
19
const PILL_HEIGHT: f32 = 24.;
19
pub const PILL_HEIGHT: f32 = 24.;
20
20
const PILL_EMOJI_SIZE: f32 = 14.;
21
21
const PILL_TEXT_SIZE: f32 = 12.;
22
22
const PILL_GAP: f32 = 3.;
@@ -70,13 +70,19 @@ fn faces_width(count: usize) -> f32 {
70
70
diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)
71
71
}
72
72
73
fn pill_content(chip: &ReactionChip, background: Hsla, directory: &Directory) -> Div {
73
#[derive(Clone, Copy, PartialEq, Eq)]
74
pub enum PillLook {
75
Faces,
76
Count,
77
}
78
79
fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory: &Directory) -> Div {
74
80
let content = h_flex().items_center().child(
75
81
div()
76
82
.text_size(px(PILL_EMOJI_SIZE))
77
83
.child(chip.label.clone()),
78
84
);
79
if shows_faces(chip.reactors.len()) {
85
if look == PillLook::Faces && shows_faces(chip.reactors.len()) {
80
86
content.child(
81
87
div()
82
88
.relative()
@@ -103,6 +109,7 @@ fn pill(
103
109
chip: &ReactionChip,
104
110
index: usize,
105
111
own: bool,
112
look: PillLook,
106
113
directory: &Directory,
107
114
react: Option<PickHandler>,
108
115
controls: Option<&ReactionControls>,
@@ -135,14 +142,14 @@ fn pill(
135
142
.h(px(PILL_HEIGHT))
136
143
.flex_none()
137
144
.pl(px(5.))
138
.pr(px(2.))
145
.pr(px(if look == PillLook::Count { 4. } else { 2. }))
139
146
.items_center()
140
147
.rounded(px(PILL_HEIGHT / 2.))
141
148
.bg(background)
142
149
.text_size(px(PILL_TEXT_SIZE))
143
150
.line_height(px(PILL_HEIGHT))
144
151
.text_color(foreground)
145
.child(pill_content(chip, background, directory))
152
.child(pill_content(chip, look, background, directory))
146
153
.tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))
147
154
.when_some(toggle, |pill, (open, close, glyph, is_open)| {
148
155
pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {
@@ -290,6 +297,7 @@ pub fn reaction_pills(
290
297
chips: &[ReactionChip],
291
298
index: usize,
292
299
own: bool,
300
look: PillLook,
293
301
directory: &Directory,
294
302
react: Option<PickHandler>,
295
303
controls: Option<&ReactionControls>,
@@ -304,7 +312,7 @@ pub fn reaction_pills(
304
312
div()
305
313
.relative()
306
314
.flex_none()
307
.child(pill(chip, index, own, directory, react.clone(), controls))
315
.child(pill(chip, index, own, look, directory, react.clone(), controls))
308
316
.when_some(open_here, |wrapper, (controls, state)| {
309
317
wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))
310
318
})
@@ -16,7 +16,7 @@ use crate::reaction_model::{16
use crate::rows::ReactionChip;16
use crate::rows::ReactionChip;17
use crate::theme::{self, ElevatedSurface as _};17
use crate::theme::{self, ElevatedSurface as _};18
18
19
const PILL_HEIGHT: f32 = 24.;19
pub const PILL_HEIGHT: f32 = 24.;20
const PILL_EMOJI_SIZE: f32 = 14.;20
const PILL_EMOJI_SIZE: f32 = 14.;21
const PILL_TEXT_SIZE: f32 = 12.;21
const PILL_TEXT_SIZE: f32 = 12.;22
const PILL_GAP: f32 = 3.;22
const PILL_GAP: f32 = 3.;@@ -70,13 +70,19 @@ fn faces_width(count: usize) -> f32 {70
diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)70
diameter + count.saturating_sub(1) as f32 * (diameter - FACE_OVERLAP)71
}71
}72
72
73
fn pill_content(chip: &ReactionChip, background: Hsla, directory: &Directory) -> Div {73
#[derive(Clone, Copy, PartialEq, Eq)]74
pub enum PillLook {75
Faces,76
Count,77
}78
79
fn pill_content(chip: &ReactionChip, look: PillLook, background: Hsla, directory: &Directory) -> Div {74
let content = h_flex().items_center().child(80
let content = h_flex().items_center().child(75
div()81
div()76
.text_size(px(PILL_EMOJI_SIZE))82
.text_size(px(PILL_EMOJI_SIZE))77
.child(chip.label.clone()),83
.child(chip.label.clone()),78
);84
);79
if shows_faces(chip.reactors.len()) {85
if look == PillLook::Faces && shows_faces(chip.reactors.len()) {80
content.child(86
content.child(81
div()87
div()82
.relative()88
.relative()@@ -103,6 +109,7 @@ fn pill(103
chip: &ReactionChip,109
chip: &ReactionChip,104
index: usize,110
index: usize,105
own: bool,111
own: bool,112
look: PillLook,106
directory: &Directory,113
directory: &Directory,107
react: Option<PickHandler>,114
react: Option<PickHandler>,108
controls: Option<&ReactionControls>,115
controls: Option<&ReactionControls>,@@ -135,14 +142,14 @@ fn pill(135
.h(px(PILL_HEIGHT))142
.h(px(PILL_HEIGHT))136
.flex_none()143
.flex_none()137
.pl(px(5.))144
.pl(px(5.))138
.pr(px(2.))145
.pr(px(if look == PillLook::Count { 4. } else { 2. }))139
.items_center()146
.items_center()140
.rounded(px(PILL_HEIGHT / 2.))147
.rounded(px(PILL_HEIGHT / 2.))141
.bg(background)148
.bg(background)142
.text_size(px(PILL_TEXT_SIZE))149
.text_size(px(PILL_TEXT_SIZE))143
.line_height(px(PILL_HEIGHT))150
.line_height(px(PILL_HEIGHT))144
.text_color(foreground)151
.text_color(foreground)145
.child(pill_content(chip, background, directory))152
.child(pill_content(chip, look, background, directory))146
.tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))153
.tooltip(move |window, cx| Tooltip::new(tooltip_text.clone()).build(window, cx))147
.when_some(toggle, |pill, (open, close, glyph, is_open)| {154
.when_some(toggle, |pill, (open, close, glyph, is_open)| {148
pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {155
pill.on_mouse_down(MouseButton::Right, move |_, _, cx| {@@ -290,6 +297,7 @@ pub fn reaction_pills(290
chips: &[ReactionChip],297
chips: &[ReactionChip],291
index: usize,298
index: usize,292
own: bool,299
own: bool,300
look: PillLook,293
directory: &Directory,301
directory: &Directory,294
react: Option<PickHandler>,302
react: Option<PickHandler>,295
controls: Option<&ReactionControls>,303
controls: Option<&ReactionControls>,@@ -304,7 +312,7 @@ pub fn reaction_pills(304
div()312
div()305
.relative()313
.relative()306
.flex_none()314
.flex_none()307
.child(pill(chip, index, own, directory, react.clone(), controls))315
.child(pill(chip, index, own, look, directory, react.clone(), controls))308
.when_some(open_here, |wrapper, (controls, state)| {316
.when_some(open_here, |wrapper, (controls, state)| {309
wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))317
wrapper.child(popover(chips, state.tab.as_deref(), directory, controls))310
})318
})@@ -1,8 +1,8 @@
1
1
use chatsvc::ConversationRef;
2
2
use chrono::{DateTime, Duration, Utc};
3
3
use graph::{
4
FileReference, MessageExtras, MessageTarget, OutgoingMention, UploadDestination, UploadedFile,
5
hosted_image_order,
4
FileReference, KeptAttachment, MessageExtras, MessageTarget, OutgoingMention,
5
UploadDestination, UploadedFile, hosted_image_order,
6
6
};
7
7
use store::MessageRecord;
8
8
@@ -13,10 +13,13 @@ use crate::hidden_chats::cleared_until_ms;
13
13
use crate::links::LinkPreview;
14
14
use crate::mapping::message_record;
15
15
use crate::markdown::markdown_to_html;
16
use crate::preview::preview_text;
16
17
use crate::mentions::{MentionInput, apply_mentions, ensure_allowed_in_chat};
17
18
use crate::remote::Remote;
18
19
use crate::scheduled::NOTES_CHAT_ID;
19
20
21
const MESSAGE_REFERENCE: &str = "messageReference";
22
20
23
impl<R: Remote> SyncEngine<R> {
21
24
pub async fn send_message(
22
25
&self,
@@ -124,32 +127,42 @@ impl<R: Remote> SyncEngine<R> {
124
127
) -> Result<MessageRecord> {
125
128
let conversation = self.resolve(conversation_id).await?;
126
129
let (html, mentions) = outgoing(&conversation, html, mentions)?;
127
let sent = match conversation {
130
let (sent, extras) = match conversation {
128
131
Conversation::Chat => {
129
self.remote
132
let sent = self
133
.remote
130
134
.reply_with_quote(conversation_id, message_id, &html, &mentions, extras)
131
.await?
135
.await?;
136
(sent, extras.clone())
132
137
}
133
138
Conversation::Channel { team_id } => {
134
let root_id = self
139
let quoted = self
135
140
.store
136
141
.messages_by_id(conversation_id, &[message_id.to_owned()])?
137
.remove(message_id)
138
.and_then(|record| record.reply_to_id)
142
.remove(message_id);
143
let root_id = quoted
144
.as_ref()
145
.and_then(|record| record.reply_to_id.clone())
139
146
.unwrap_or_else(|| message_id.to_owned());
140
self.remote
147
let mut extras = extras.clone();
148
if let Some(quoted) = "ed {
149
extras.kept.insert(0, quote_reference(quoted));
150
}
151
let sent = self
152
.remote
141
153
.reply_to_channel_message(
142
154
&team_id,
143
155
conversation_id,
144
156
&root_id,
145
157
&html,
146
158
&mentions,
147
extras,
159
&extras,
148
160
)
149
.await?
161
.await?;
162
(sent, extras)
150
163
}
151
164
};
152
self.cache_sent(conversation_id, &sent, &html, extras)
165
self.cache_sent(conversation_id, &sent, &html, &extras)
153
166
}
154
167
155
168
/// Own and not deleted. Chat messages, channel posts and channel replies alike.
@@ -787,6 +800,33 @@ fn outgoing(
787
800
Ok(apply_mentions(html, mentions))
788
801
}
789
802
803
/// The `messageReference` attachment Graph's chat `replyWithQuote` produces; channels have no such action.
804
fn quote_reference(record: &MessageRecord) -> KeptAttachment {
805
let sender = record.sender_id.as_ref().map(|user_id| {
806
serde_json::json!({
807
"application": null,
808
"device": null,
809
"user": {
810
"userIdentityType": "aadUser",
811
"id": user_id,
812
"displayName": record.sender_name,
813
},
814
})
815
});
816
let content = serde_json::json!({
817
"messageId": record.message_id,
818
"messagePreview": preview_text(&record.body_html).unwrap_or_default(),
819
"messageSender": sender,
820
});
821
KeptAttachment {
822
id: record.message_id.clone(),
823
content_type: Some(MESSAGE_REFERENCE.to_owned()),
824
content: Some(content.to_string()),
825
content_url: None,
826
name: None,
827
}
828
}
829
790
830
fn missing_attachment_id() -> Error {
791
831
graph::Error::Upload("the uploaded file has no attachment id".into()).into()
792
832
}
@@ -1,8 +1,8 @@1
use chatsvc::ConversationRef;1
use chatsvc::ConversationRef;2
use chrono::{DateTime, Duration, Utc};2
use chrono::{DateTime, Duration, Utc};3
use graph::{3
use graph::{4
FileReference, MessageExtras, MessageTarget, OutgoingMention, UploadDestination, UploadedFile,4
FileReference, KeptAttachment, MessageExtras, MessageTarget, OutgoingMention,5
hosted_image_order,5
UploadDestination, UploadedFile, hosted_image_order,6
};6
};7
use store::MessageRecord;7
use store::MessageRecord;8
8
@@ -13,10 +13,13 @@ use crate::hidden_chats::cleared_until_ms;13
use crate::links::LinkPreview;13
use crate::links::LinkPreview;14
use crate::mapping::message_record;14
use crate::mapping::message_record;15
use crate::markdown::markdown_to_html;15
use crate::markdown::markdown_to_html;16
use crate::preview::preview_text;16
use crate::mentions::{MentionInput, apply_mentions, ensure_allowed_in_chat};17
use crate::mentions::{MentionInput, apply_mentions, ensure_allowed_in_chat};17
use crate::remote::Remote;18
use crate::remote::Remote;18
use crate::scheduled::NOTES_CHAT_ID;19
use crate::scheduled::NOTES_CHAT_ID;19
20
21
const MESSAGE_REFERENCE: &str = "messageReference";22
20
impl<R: Remote> SyncEngine<R> {23
impl<R: Remote> SyncEngine<R> {21
pub async fn send_message(24
pub async fn send_message(22
&self,25
&self,@@ -124,32 +127,42 @@ impl<R: Remote> SyncEngine<R> {124
) -> Result<MessageRecord> {127
) -> Result<MessageRecord> {125
let conversation = self.resolve(conversation_id).await?;128
let conversation = self.resolve(conversation_id).await?;126
let (html, mentions) = outgoing(&conversation, html, mentions)?;129
let (html, mentions) = outgoing(&conversation, html, mentions)?;127
let sent = match conversation {130
let (sent, extras) = match conversation {128
Conversation::Chat => {131
Conversation::Chat => {129
self.remote132
let sent = self133
.remote130
.reply_with_quote(conversation_id, message_id, &html, &mentions, extras)134
.reply_with_quote(conversation_id, message_id, &html, &mentions, extras)131
.await?135
.await?;136
(sent, extras.clone())132
}137
}133
Conversation::Channel { team_id } => {138
Conversation::Channel { team_id } => {134
let root_id = self139
let quoted = self135
.store140
.store136
.messages_by_id(conversation_id, &[message_id.to_owned()])?141
.messages_by_id(conversation_id, &[message_id.to_owned()])?137
.remove(message_id)142
.remove(message_id);138
.and_then(|record| record.reply_to_id)143
let root_id = quoted144
.as_ref()145
.and_then(|record| record.reply_to_id.clone())139
.unwrap_or_else(|| message_id.to_owned());146
.unwrap_or_else(|| message_id.to_owned());140
self.remote147
let mut extras = extras.clone();148
if let Some(quoted) = "ed {149
extras.kept.insert(0, quote_reference(quoted));150
}151
let sent = self152
.remote141
.reply_to_channel_message(153
.reply_to_channel_message(142
&team_id,154
&team_id,143
conversation_id,155
conversation_id,144
&root_id,156
&root_id,145
&html,157
&html,146
&mentions,158
&mentions,147
extras,159
&extras,148
)160
)149
.await?161
.await?;162
(sent, extras)150
}163
}151
};164
};152
self.cache_sent(conversation_id, &sent, &html, extras)165
self.cache_sent(conversation_id, &sent, &html, &extras)153
}166
}154
167
155
/// Own and not deleted. Chat messages, channel posts and channel replies alike.168
/// Own and not deleted. Chat messages, channel posts and channel replies alike.@@ -787,6 +800,33 @@ fn outgoing(787
Ok(apply_mentions(html, mentions))800
Ok(apply_mentions(html, mentions))788
}801
}789
802
803
/// The `messageReference` attachment Graph's chat `replyWithQuote` produces; channels have no such action.804
fn quote_reference(record: &MessageRecord) -> KeptAttachment {805
let sender = record.sender_id.as_ref().map(|user_id| {806
serde_json::json!({807
"application": null,808
"device": null,809
"user": {810
"userIdentityType": "aadUser",811
"id": user_id,812
"displayName": record.sender_name,813
},814
})815
});816
let content = serde_json::json!({817
"messageId": record.message_id,818
"messagePreview": preview_text(&record.body_html).unwrap_or_default(),819
"messageSender": sender,820
});821
KeptAttachment {822
id: record.message_id.clone(),823
content_type: Some(MESSAGE_REFERENCE.to_owned()),824
content: Some(content.to_string()),825
content_url: None,826
name: None,827
}828
}829
790
fn missing_attachment_id() -> Error {830
fn missing_attachment_id() -> Error {791
graph::Error::Upload("the uploaded file has no attachment id".into()).into()831
graph::Error::Upload("the uploaded file has no attachment id".into()).into()792
}832
}@@ -5408,3 +5408,22 @@ async fn marking_the_notes_chat_read_takes_the_tenant_from_another_chat() {
5408
5408
.any(|chat_id| chat_id == NOTES_CHAT_ID)
5409
5409
);
5410
5410
}
5411
5412
#[tokio::test]
5413
async fn a_quoted_channel_reply_carries_the_quote_as_a_message_reference() {
5414
let fake = Arc::new(Fake::default());
5415
let engine = channel_engine(&fake).await;
5416
engine.fetch_newer(CHANNEL).await.unwrap();
5417
engine
5418
.reply_to_with_mentions(CHANNEL, "m0030", "answer", &[])
5419
.await
5420
.unwrap();
5421
let extras = fake.extras_sent.lock().unwrap().last().cloned().unwrap();
5422
let quote = &extras.kept[0];
5423
assert_eq!(quote.id, "m0030");
5424
assert_eq!(quote.content_type.as_deref(), Some("messageReference"));
5425
let content: serde_json::Value =
5426
serde_json::from_str(quote.content.as_deref().unwrap()).unwrap();
5427
assert_eq!(content["messageId"], "m0030");
5428
assert_eq!(content["messageSender"]["user"]["userIdentityType"], "aadUser");
5429
}
@@ -5408,3 +5408,22 @@ async fn marking_the_notes_chat_read_takes_the_tenant_from_another_chat() {5408
.any(|chat_id| chat_id == NOTES_CHAT_ID)5408
.any(|chat_id| chat_id == NOTES_CHAT_ID)5409
);5409
);5410
}5410
}5411
5412
#[tokio::test]5413
async fn a_quoted_channel_reply_carries_the_quote_as_a_message_reference() {5414
let fake = Arc::new(Fake::default());5415
let engine = channel_engine(&fake).await;5416
engine.fetch_newer(CHANNEL).await.unwrap();5417
engine5418
.reply_to_with_mentions(CHANNEL, "m0030", "answer", &[])5419
.await5420
.unwrap();5421
let extras = fake.extras_sent.lock().unwrap().last().cloned().unwrap();5422
let quote = &extras.kept[0];5423
assert_eq!(quote.id, "m0030");5424
assert_eq!(quote.content_type.as_deref(), Some("messageReference"));5425
let content: serde_json::Value =5426
serde_json::from_str(quote.content.as_deref().unwrap()).unwrap();5427
assert_eq!(content["messageId"], "m0030");5428
assert_eq!(content["messageSender"]["user"]["userIdentityType"], "aadUser");5429
}@@ -67,6 +67,12 @@ impl MessageScrollerState {
67
67
&& !self.list_state.is_scrolled_to_end().unwrap_or(false)
68
68
}
69
69
70
/// Return whether rows are hidden above the top of the viewport.
71
pub fn is_scrolled_from_top(&self) -> bool {
72
let top = self.list_state.logical_scroll_top();
73
top.item_ix > 0 || top.offset_in_item > px(0.5)
74
}
75
70
76
/// Return the index of the row at the top of the viewport.
71
77
pub fn top_item(&self) -> usize {
72
78
self.list_state.logical_scroll_top().item_ix
@@ -67,6 +67,12 @@ impl MessageScrollerState {67
&& !self.list_state.is_scrolled_to_end().unwrap_or(false)67
&& !self.list_state.is_scrolled_to_end().unwrap_or(false)68
}68
}69
69
70
/// Return whether rows are hidden above the top of the viewport.71
pub fn is_scrolled_from_top(&self) -> bool {72
let top = self.list_state.logical_scroll_top();73
top.item_ix > 0 || top.offset_in_item > px(0.5)74
}75
70
/// Return the index of the row at the top of the viewport.76
/// Return the index of the row at the top of the viewport.71
pub fn top_item(&self) -> usize {77
pub fn top_item(&self) -> usize {72
self.list_state.logical_scroll_top().item_ix78
self.list_state.logical_scroll_top().item_ix