fix(app): flow mentions inline and date old channel posts
- Mentions render as bold accent text inside the normal text flow, like Teams - Line breaks, wrapping and long URLs now work in messages with a mention - Channel post header shows the day for posts not from today - Demo channel gets a post with mention, paragraphs and a long link Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -761,6 +761,26 @@ fn channel_messages() -> Vec<MessageRecord> {
761
761
"[]",
762
762
false,
763
763
),
764
message(
765
channel,
766
"t4",
767
None,
768
mara,
769
at(3, 8, 42),
770
"<p>Sprint Demos.</p><p>I added you both to the sprint. <at id=\"0\">Tobias Klein</at> did you present everything about the migration tool? The spec is at <a href=\"https://wiki.example.com/display/TEAM/Settings+types+and+password+policies\">https://wiki.example.com/display/TEAM/Settings+types+and+password+policies</a>Can you please review it?</p>",
771
"[]",
772
false,
773
),
774
message(
775
channel,
776
"t4r1",
777
Some("t4"),
778
tobias,
779
at(0, 9, 15),
780
"<p>Yes, all done.</p>",
781
"[]",
782
false,
783
),
764
784
]
765
785
}
766
786
@@ -761,6 +761,26 @@ fn channel_messages() -> Vec<MessageRecord> {761
"[]",761
"[]",762
false,762
false,763
),763
),764
message(765
channel,766
"t4",767
None,768
mara,769
at(3, 8, 42),770
"<p>Sprint Demos.</p><p>I added you both to the sprint. <at id=\"0\">Tobias Klein</at> did you present everything about the migration tool? The spec is at <a href=\"https://wiki.example.com/display/TEAM/Settings+types+and+password+policies\">https://wiki.example.com/display/TEAM/Settings+types+and+password+policies</a>Can you please review it?</p>",771
"[]",772
false,773
),774
message(775
channel,776
"t4r1",777
Some("t4"),778
tobias,779
at(0, 9, 15),780
"<p>Yes, all done.</p>",781
"[]",782
false,783
),764
]784
]765
}785
}766
786
@@ -81,6 +81,24 @@ pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffse
81
81
}
82
82
}
83
83
84
pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
85
let local = time.with_timezone(&offset);
86
let day = local.date_naive();
87
let days_ago = (today - day).num_days();
88
let clock = local.format("%H:%M");
89
if days_ago <= 0 {
90
clock.to_string()
91
} else if days_ago == 1 {
92
format!("Gestern {clock}")
93
} else if days_ago <= WEEKDAY_WINDOW_DAYS {
94
format!("{} {clock}", weekday_label(local.weekday()))
95
} else if day.year() == today.year() {
96
format!("{} {clock}", local.format("%d.%m."))
97
} else {
98
format!("{} {clock}", local.format("%d.%m.%y"))
99
}
100
}
101
84
102
pub fn day_label(day: NaiveDate, today: NaiveDate) -> String {
85
103
if day == today {
86
104
"Today".to_owned()
@@ -190,6 +208,17 @@ mod tests {
190
208
assert_eq!(short_version("dev", "0.1.0"), "v0.1.0 (dev)");
191
209
}
192
210
211
#[test]
212
fn post_time_adds_the_day_when_not_today() {
213
assert_eq!(post_time_label(utc(7, 13), today(), zero()), "13:05");
214
assert_eq!(post_time_label(utc(6, 9), today(), zero()), "Gestern 09:05");
215
assert_eq!(post_time_label(utc(5, 13), today(), zero()), "Mo 13:05");
216
let september = Utc.with_ymd_and_hms(2026, 9, 30, 8, 42, 0).unwrap();
217
assert_eq!(post_time_label(september, today(), zero()), "30.09. 08:42");
218
let last_year = Utc.with_ymd_and_hms(2020, 5, 22, 8, 42, 0).unwrap();
219
assert_eq!(post_time_label(last_year, today(), zero()), "22.05.20 08:42");
220
}
221
193
222
#[test]
194
223
fn day_labels() {
195
224
assert_eq!(day_label(today(), today()), "Today");
@@ -81,6 +81,24 @@ pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffse81
}81
}82
}82
}83
83
84
pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {85
let local = time.with_timezone(&offset);86
let day = local.date_naive();87
let days_ago = (today - day).num_days();88
let clock = local.format("%H:%M");89
if days_ago <= 0 {90
clock.to_string()91
} else if days_ago == 1 {92
format!("Gestern {clock}")93
} else if days_ago <= WEEKDAY_WINDOW_DAYS {94
format!("{} {clock}", weekday_label(local.weekday()))95
} else if day.year() == today.year() {96
format!("{} {clock}", local.format("%d.%m."))97
} else {98
format!("{} {clock}", local.format("%d.%m.%y"))99
}100
}101
84
pub fn day_label(day: NaiveDate, today: NaiveDate) -> String {102
pub fn day_label(day: NaiveDate, today: NaiveDate) -> String {85
if day == today {103
if day == today {86
"Today".to_owned()104
"Today".to_owned()@@ -190,6 +208,17 @@ mod tests {190
assert_eq!(short_version("dev", "0.1.0"), "v0.1.0 (dev)");208
assert_eq!(short_version("dev", "0.1.0"), "v0.1.0 (dev)");191
}209
}192
210
211
#[test]212
fn post_time_adds_the_day_when_not_today() {213
assert_eq!(post_time_label(utc(7, 13), today(), zero()), "13:05");214
assert_eq!(post_time_label(utc(6, 9), today(), zero()), "Gestern 09:05");215
assert_eq!(post_time_label(utc(5, 13), today(), zero()), "Mo 13:05");216
let september = Utc.with_ymd_and_hms(2026, 9, 30, 8, 42, 0).unwrap();217
assert_eq!(post_time_label(september, today(), zero()), "30.09. 08:42");218
let last_year = Utc.with_ymd_and_hms(2020, 5, 22, 8, 42, 0).unwrap();219
assert_eq!(post_time_label(last_year, today(), zero()), "22.05.20 08:42");220
}221
193
#[test]222
#[test]194
fn day_labels() {223
fn day_labels() {195
assert_eq!(day_label(today(), today()), "Today");224
assert_eq!(day_label(today(), today()), "Today");@@ -2,7 +2,6 @@ use std::ops::Range;
2
2
3
3
use teams_core::Span;
4
4
5
pub const MENTION_PAD: char = '\u{2009}';
6
5
pub const IMAGE_PLACEHOLDER: &str = "[image]";
7
6
const URL_PREFIXES: [&str; 3] = ["https://", "http://", "www."];
8
7
const TRAILING_PUNCTUATION: &str = ".,;:!?'\"";
@@ -243,10 +242,7 @@ fn append_inline(spans: &[Span], style: StyleFlags, link: Option<&str>, out: &mu
243
242
out,
244
243
),
245
244
Span::Mention { name } => {
246
let label = format!(
247
"{MENTION_PAD}@{}{MENTION_PAD}",
248
name.trim_start_matches('@')
249
);
245
let label = format!("@{}", name.trim_start_matches('@'));
250
246
out.push(
251
247
&label,
252
248
StyleFlags {
@@ -453,7 +449,7 @@ mod tests {
453
449
let Block::Paragraph(inline) = &blocks[0] else {
454
450
panic!("paragraph expected")
455
451
};
456
assert_eq!(inline.text, "\u{2009}@Ada\u{2009} \u{2009}@Bob");
452
assert_eq!(inline.text, "@Ada @Bob");
457
453
assert!(inline.segments[0].style.mention);
458
454
}
459
455
@@ -2,7 +2,6 @@ use std::ops::Range;2
2
3
use teams_core::Span;3
use teams_core::Span;4
4
5
pub const MENTION_PAD: char = '\u{2009}';6
pub const IMAGE_PLACEHOLDER: &str = "[image]";5
pub const IMAGE_PLACEHOLDER: &str = "[image]";7
const URL_PREFIXES: [&str; 3] = ["https://", "http://", "www."];6
const URL_PREFIXES: [&str; 3] = ["https://", "http://", "www."];8
const TRAILING_PUNCTUATION: &str = ".,;:!?'\"";7
const TRAILING_PUNCTUATION: &str = ".,;:!?'\"";@@ -243,10 +242,7 @@ fn append_inline(spans: &[Span], style: StyleFlags, link: Option<&str>, out: &mu243
out,242
out,244
),243
),245
Span::Mention { name } => {244
Span::Mention { name } => {246
let label = format!(245
let label = format!("@{}", name.trim_start_matches('@'));247
"{MENTION_PAD}@{}{MENTION_PAD}",248
name.trim_start_matches('@')249
);250
out.push(246
out.push(251
&label,247
&label,252
StyleFlags {248
StyleFlags {@@ -453,7 +449,7 @@ mod tests {453
let Block::Paragraph(inline) = &blocks[0] else {449
let Block::Paragraph(inline) = &blocks[0] else {454
panic!("paragraph expected")450
panic!("paragraph expected")455
};451
};456
assert_eq!(inline.text, "\u{2009}@Ada\u{2009} \u{2009}@Bob");452
assert_eq!(inline.text, "@Ada @Bob");457
assert!(inline.segments[0].style.mention);453
assert!(inline.segments[0].style.mention);458
}454
}459
455
@@ -65,9 +65,6 @@ fn code_font(cx: &App) -> SharedString {
65
65
}
66
66
67
67
fn render_inline(inline: &Inline, id: String, own: bool) -> AnyElement {
68
if inline.segments.iter().any(|segment| segment.style.mention) {
69
return render_inline_with_chips(inline, &id, own);
70
}
71
68
let highlights = inline
72
69
.segments
73
70
.iter()
@@ -115,67 +112,22 @@ fn highlight_for(style: StyleFlags, own: bool) -> HighlightStyle {
115
112
if style.code {
116
113
highlight.background_color = Some(theme::code_background());
117
114
}
115
let accent = if own {
116
theme::accent_soft()
117
} else {
118
theme::accent_text()
119
};
120
if style.mention {
121
highlight.font_weight = Some(FontWeight::BOLD);
122
highlight.color = Some(accent);
123
}
118
124
if style.link {
119
let color = if own {
120
theme::accent_soft()
121
} else {
122
theme::accent_text()
123
};
124
highlight.color = Some(color);
125
highlight.color = Some(accent);
125
126
highlight.underline = Some(UnderlineStyle {
126
127
thickness: px(1.),
127
color: Some(color),
128
color: Some(accent),
128
129
wavy: false,
129
130
});
130
131
}
131
132
highlight
132
133
}
133
134
fn render_inline_with_chips(inline: &Inline, id: &str, own: bool) -> AnyElement {
135
let mut pieces: Vec<AnyElement> = Vec::new();
136
for (segment_index, segment) in inline.segments.iter().enumerate() {
137
let text = &inline.text[segment.range.clone()];
138
if segment.style.mention {
139
pieces.push(mention_chip(text.trim(), own));
140
continue;
141
}
142
for (word_index, word) in text.split_inclusive(' ').enumerate() {
143
let mut piece = div()
144
.id(ElementId::Name(
145
format!("{id}-{segment_index}-{word_index}").into(),
146
))
147
.whitespace_nowrap()
148
.child(
149
StyledText::new(word.to_owned())
150
.with_highlights([(0..word.len(), highlight_for(segment.style, own))]),
151
);
152
if let Some(url) = segment.link.clone() {
153
piece = piece
154
.cursor_pointer()
155
.on_click(move |_, _, cx| cx.open_url(&url));
156
}
157
pieces.push(piece.into_any_element());
158
}
159
}
160
div()
161
.w_full()
162
.flex()
163
.flex_wrap()
164
.items_center()
165
.text_color(theme::text())
166
.children(pieces)
167
.into_any_element()
168
}
169
170
fn mention_chip(text: &str, own: bool) -> AnyElement {
171
div()
172
.mx(px(1.))
173
.px(px(6.))
174
.rounded(px(6.))
175
.bg(theme::mention_background(own))
176
.text_color(theme::mention_text())
177
.font_weight(FontWeight::SEMIBOLD)
178
.whitespace_nowrap()
179
.child(text.to_owned())
180
.into_any_element()
181
}
@@ -65,9 +65,6 @@ fn code_font(cx: &App) -> SharedString {65
}65
}66
66
67
fn render_inline(inline: &Inline, id: String, own: bool) -> AnyElement {67
fn render_inline(inline: &Inline, id: String, own: bool) -> AnyElement {68
if inline.segments.iter().any(|segment| segment.style.mention) {69
return render_inline_with_chips(inline, &id, own);70
}71
let highlights = inline68
let highlights = inline72
.segments69
.segments73
.iter()70
.iter()@@ -115,67 +112,22 @@ fn highlight_for(style: StyleFlags, own: bool) -> HighlightStyle {115
if style.code {112
if style.code {116
highlight.background_color = Some(theme::code_background());113
highlight.background_color = Some(theme::code_background());117
}114
}115
let accent = if own {116
theme::accent_soft()117
} else {118
theme::accent_text()119
};120
if style.mention {121
highlight.font_weight = Some(FontWeight::BOLD);122
highlight.color = Some(accent);123
}118
if style.link {124
if style.link {119
let color = if own {125
highlight.color = Some(accent);120
theme::accent_soft()121
} else {122
theme::accent_text()123
};124
highlight.color = Some(color);125
highlight.underline = Some(UnderlineStyle {126
highlight.underline = Some(UnderlineStyle {126
thickness: px(1.),127
thickness: px(1.),127
color: Some(color),128
color: Some(accent),128
wavy: false,129
wavy: false,129
});130
});130
}131
}131
highlight132
highlight132
}133
}133
134
fn render_inline_with_chips(inline: &Inline, id: &str, own: bool) -> AnyElement {135
let mut pieces: Vec<AnyElement> = Vec::new();136
for (segment_index, segment) in inline.segments.iter().enumerate() {137
let text = &inline.text[segment.range.clone()];138
if segment.style.mention {139
pieces.push(mention_chip(text.trim(), own));140
continue;141
}142
for (word_index, word) in text.split_inclusive(' ').enumerate() {143
let mut piece = div()144
.id(ElementId::Name(145
format!("{id}-{segment_index}-{word_index}").into(),146
))147
.whitespace_nowrap()148
.child(149
StyledText::new(word.to_owned())150
.with_highlights([(0..word.len(), highlight_for(segment.style, own))]),151
);152
if let Some(url) = segment.link.clone() {153
piece = piece154
.cursor_pointer()155
.on_click(move |_, _, cx| cx.open_url(&url));156
}157
pieces.push(piece.into_any_element());158
}159
}160
div()161
.w_full()162
.flex()163
.flex_wrap()164
.items_center()165
.text_color(theme::text())166
.children(pieces)167
.into_any_element()168
}169
170
fn mention_chip(text: &str, own: bool) -> AnyElement {171
div()172
.mx(px(1.))173
.px(px(6.))174
.rounded(px(6.))175
.bg(theme::mention_background(own))176
.text_color(theme::mention_text())177
.font_weight(FontWeight::SEMIBOLD)178
.whitespace_nowrap()179
.child(text.to_owned())180
.into_any_element()181
}@@ -6,7 +6,7 @@ use store::MessageRecord;
6
6
use teams_core::{FileCard, ImageRef, ReactionInfo, Span, files, images, message_spans, reactions};
7
7
8
8
use crate::format;
9
use crate::render::blocks::{Inline, MENTION_PAD, strip_image_placeholders};
9
use crate::render::blocks::{Inline, strip_image_placeholders};
10
10
use crate::render::{Block, layout_blocks};
11
11
use crate::sidebar_model::Face;
12
12
@@ -294,8 +294,7 @@ pub fn reply_excerpt(record: &MessageRecord) -> String {
294
294
Block::Code(code) => Some(code),
295
295
Block::Quote(_) => None,
296
296
})
297
.unwrap_or_default()
298
.replace(MENTION_PAD, "");
297
.unwrap_or_default();
299
298
let first_line = text.lines().map(str::trim).find(|line| !line.is_empty());
300
299
let excerpt = match first_line {
301
300
Some(line) => line.to_owned(),
@@ -443,6 +442,7 @@ pub fn thread_list_rows(
443
442
row.day_header = (previous_day != Some(day)).then(|| format::day_label(day, context.today));
444
443
previous_day = Some(day);
445
444
row.card = true;
445
row.time = format::post_time_label(root.created_at, context.today, context.offset);
446
446
row.reply_count = Some(thread.reply_ids.len());
447
447
let replies: Vec<&&MessageRecord> = thread
448
448
.reply_ids
@@ -6,7 +6,7 @@ use store::MessageRecord;6
use teams_core::{FileCard, ImageRef, ReactionInfo, Span, files, images, message_spans, reactions};6
use teams_core::{FileCard, ImageRef, ReactionInfo, Span, files, images, message_spans, reactions};7
7
8
use crate::format;8
use crate::format;9
use crate::render::blocks::{Inline, MENTION_PAD, strip_image_placeholders};9
use crate::render::blocks::{Inline, strip_image_placeholders};10
use crate::render::{Block, layout_blocks};10
use crate::render::{Block, layout_blocks};11
use crate::sidebar_model::Face;11
use crate::sidebar_model::Face;12
12
@@ -294,8 +294,7 @@ pub fn reply_excerpt(record: &MessageRecord) -> String {294
Block::Code(code) => Some(code),294
Block::Code(code) => Some(code),295
Block::Quote(_) => None,295
Block::Quote(_) => None,296
})296
})297
.unwrap_or_default()297
.unwrap_or_default();298
.replace(MENTION_PAD, "");299
let first_line = text.lines().map(str::trim).find(|line| !line.is_empty());298
let first_line = text.lines().map(str::trim).find(|line| !line.is_empty());300
let excerpt = match first_line {299
let excerpt = match first_line {301
Some(line) => line.to_owned(),300
Some(line) => line.to_owned(),@@ -443,6 +442,7 @@ pub fn thread_list_rows(443
row.day_header = (previous_day != Some(day)).then(|| format::day_label(day, context.today));442
row.day_header = (previous_day != Some(day)).then(|| format::day_label(day, context.today));444
previous_day = Some(day);443
previous_day = Some(day);445
row.card = true;444
row.card = true;445
row.time = format::post_time_label(root.created_at, context.today, context.offset);446
row.reply_count = Some(thread.reply_ids.len());446
row.reply_count = Some(thread.reply_ids.len());447
let replies: Vec<&&MessageRecord> = thread447
let replies: Vec<&&MessageRecord> = thread448
.reply_ids448
.reply_ids