BlueGit

ict rusty-teams

fix(chat): open findings of the area sweep (121a)

- mentions: @Everyone in a group chat is sent again (chatsvc entry: chat thread as mri, mentionType everyone)
- edit: a channel message with a mention is edited through Graph instead of failing
- time: message times, day separators, find, activity and gallery follow the daylight saving rules of the message's date (Zone::Local)
- composer: the unsent draft survives editing a message; Reply while editing ends the edit; a failed edit goes back into edit mode
- schedule: a pending schedule only blocks sending in its own chat; an edit of a scheduled message that is gone comes back with a notice
- find in chat: the current hit stays the same message when server hits arrive
- channel: the reply text of a post is kept when the editor closes or moves to another post
- history: older pages keep loading when a page has no message we can show

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-14 · 2 weeks ago

Hash
0ff9db96aa796c7a2f0ef2683b120c81e5838fd6
Parent
d3ec5ddc
23 files changed +270 −96
crates/app-base/src/format.rs +36 −10
@@ -1,9 +1,31 @@
1 1 use std::cell::Cell;
2 2
3 use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, Utc, Weekday};
3 use chrono::{DateTime, Datelike, FixedOffset, Local, NaiveDate, Utc, Weekday};
4 4
5 5 use crate::theme;
6 6
7 /// `Local` follows the daylight saving rules at the given instant, a fixed offset is the same all year.
8 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
9 pub enum Zone {
10 Local,
11 Fixed(FixedOffset),
12 }
13
14 impl Zone {
15 pub fn at(self, time: DateTime<Utc>) -> DateTime<FixedOffset> {
16 match self {
17 Zone::Local => time.with_timezone(&Local).fixed_offset(),
18 Zone::Fixed(offset) => time.with_timezone(&offset),
19 }
20 }
21 }
22
23 impl From<FixedOffset> for Zone {
24 fn from(offset: FixedOffset) -> Self {
25 Zone::Fixed(offset)
26 }
27 }
28
7 29 const BADGE_CAP: u32 = 99;
8 30 const WEEKDAY_WINDOW_DAYS: i64 = 6;
9 31 const TWELVE_HOUR_LOCALES: [&str; 6] = ["en-us", "en-ca", "en-ph", "en-au", "en-nz", "en-in"];
@@ -201,7 +223,7 @@ pub fn short_version(build_id: &str, package_version: &str) -> String {
201 223 format!("v{package_version} ({commit})")
202 224 }
203 225
204 pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
226 pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> String {
205 227 list_time_label_in(current_date_style(), time, today, offset)
206 228 }
207 229
@@ -209,9 +231,9 @@ pub fn list_time_label_in(
209 231 style: Option<DateStyle>,
210 232 time: DateTime<Utc>,
211 233 today: NaiveDate,
212 offset: FixedOffset,
234 offset: impl Into<Zone>,
213 235 ) -> String {
214 let local = time.with_timezone(&offset);
236 let local = offset.into().at(time);
215 237 let day = local.date_naive();
216 238 let days_ago = (today - day).num_days();
217 239 if days_ago <= 0 {
@@ -228,7 +250,11 @@ pub fn list_time_label_in(
228 250 }
229 251
230 252 /// The last activity next to a channel name: the time today, else day and month, with the year once older.
231 pub fn channel_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
253 pub fn channel_time_label(
254 time: DateTime<Utc>,
255 today: NaiveDate,
256 offset: impl Into<Zone>,
257 ) -> String {
232 258 channel_time_label_in(current_date_style(), time, today, offset)
233 259 }
234 260
@@ -236,9 +262,9 @@ pub fn channel_time_label_in(
236 262 style: Option<DateStyle>,
237 263 time: DateTime<Utc>,
238 264 today: NaiveDate,
239 offset: FixedOffset,
265 offset: impl Into<Zone>,
240 266 ) -> String {
241 let local = time.with_timezone(&offset);
267 let local = offset.into().at(time);
242 268 let pattern = if local.date_naive() >= today {
243 269 style.map_or("%H:%M", |style| style.clock)
244 270 } else if local.year() == today.year() {
@@ -249,7 +275,7 @@ pub fn channel_time_label_in(
249 275 local.format(pattern).to_string()
250 276 }
251 277
252 pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
278 pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> String {
253 279 post_time_label_in(current_date_style(), time, today, offset)
254 280 }
255 281
@@ -257,9 +283,9 @@ pub fn post_time_label_in(
257 283 style: Option<DateStyle>,
258 284 time: DateTime<Utc>,
259 285 today: NaiveDate,
260 offset: FixedOffset,
286 offset: impl Into<Zone>,
261 287 ) -> String {
262 let local = time.with_timezone(&offset);
288 let local = offset.into().at(time);
263 289 let day = local.date_naive();
264 290 let days_ago = (today - day).num_days();
265 291 let clock = local.format(style.map_or("%H:%M", |style| style.clock));
@@ -1,9 +1,31 @@
1use std::cell::Cell;
1use std::cell::Cell;
2
2
3use chrono::{DateTime, Datelike, FixedOffset, NaiveDate, Utc, Weekday};
3use chrono::{DateTime, Datelike, FixedOffset, Local, NaiveDate, Utc, Weekday};
4
4
5use crate::theme;
5use crate::theme;
6
6
7/// `Local` follows the daylight saving rules at the given instant, a fixed offset is the same all year.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum Zone {
10 Local,
11 Fixed(FixedOffset),
12}
13
14impl Zone {
15 pub fn at(self, time: DateTime<Utc>) -> DateTime<FixedOffset> {
16 match self {
17 Zone::Local => time.with_timezone(&Local).fixed_offset(),
18 Zone::Fixed(offset) => time.with_timezone(&offset),
19 }
20 }
21}
22
23impl From<FixedOffset> for Zone {
24 fn from(offset: FixedOffset) -> Self {
25 Zone::Fixed(offset)
26 }
27}
28
7const BADGE_CAP: u32 = 99;
29const BADGE_CAP: u32 = 99;
8const WEEKDAY_WINDOW_DAYS: i64 = 6;
30const WEEKDAY_WINDOW_DAYS: i64 = 6;
9const TWELVE_HOUR_LOCALES: [&str; 6] = ["en-us", "en-ca", "en-ph", "en-au", "en-nz", "en-in"];
31const TWELVE_HOUR_LOCALES: [&str; 6] = ["en-us", "en-ca", "en-ph", "en-au", "en-nz", "en-in"];
@@ -201,7 +223,7 @@ pub fn short_version(build_id: &str, package_version: &str) -> String {
201 format!("v{package_version} ({commit})")
223 format!("v{package_version} ({commit})")
202}
224}
203
225
204pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
226pub fn list_time_label(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> String {
205 list_time_label_in(current_date_style(), time, today, offset)
227 list_time_label_in(current_date_style(), time, today, offset)
206}
228}
207
229
@@ -209,9 +231,9 @@ pub fn list_time_label_in(
209 style: Option<DateStyle>,
231 style: Option<DateStyle>,
210 time: DateTime<Utc>,
232 time: DateTime<Utc>,
211 today: NaiveDate,
233 today: NaiveDate,
212 offset: FixedOffset,
234 offset: impl Into<Zone>,
213) -> String {
235) -> String {
214 let local = time.with_timezone(&offset);
236 let local = offset.into().at(time);
215 let day = local.date_naive();
237 let day = local.date_naive();
216 let days_ago = (today - day).num_days();
238 let days_ago = (today - day).num_days();
217 if days_ago <= 0 {
239 if days_ago <= 0 {
@@ -228,7 +250,11 @@ pub fn list_time_label_in(
228}
250}
229
251
230/// The last activity next to a channel name: the time today, else day and month, with the year once older.
252/// The last activity next to a channel name: the time today, else day and month, with the year once older.
231pub fn channel_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
253pub fn channel_time_label(
254 time: DateTime<Utc>,
255 today: NaiveDate,
256 offset: impl Into<Zone>,
257) -> String {
232 channel_time_label_in(current_date_style(), time, today, offset)
258 channel_time_label_in(current_date_style(), time, today, offset)
233}
259}
234
260
@@ -236,9 +262,9 @@ pub fn channel_time_label_in(
236 style: Option<DateStyle>,
262 style: Option<DateStyle>,
237 time: DateTime<Utc>,
263 time: DateTime<Utc>,
238 today: NaiveDate,
264 today: NaiveDate,
239 offset: FixedOffset,
265 offset: impl Into<Zone>,
240) -> String {
266) -> String {
241 let local = time.with_timezone(&offset);
267 let local = offset.into().at(time);
242 let pattern = if local.date_naive() >= today {
268 let pattern = if local.date_naive() >= today {
243 style.map_or("%H:%M", |style| style.clock)
269 style.map_or("%H:%M", |style| style.clock)
244 } else if local.year() == today.year() {
270 } else if local.year() == today.year() {
@@ -249,7 +275,7 @@ pub fn channel_time_label_in(
249 local.format(pattern).to_string()
275 local.format(pattern).to_string()
250}
276}
251
277
252pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> String {
278pub fn post_time_label(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> String {
253 post_time_label_in(current_date_style(), time, today, offset)
279 post_time_label_in(current_date_style(), time, today, offset)
254}
280}
255
281
@@ -257,9 +283,9 @@ pub fn post_time_label_in(
257 style: Option<DateStyle>,
283 style: Option<DateStyle>,
258 time: DateTime<Utc>,
284 time: DateTime<Utc>,
259 today: NaiveDate,
285 today: NaiveDate,
260 offset: FixedOffset,
286 offset: impl Into<Zone>,
261) -> String {
287) -> String {
262 let local = time.with_timezone(&offset);
288 let local = offset.into().at(time);
263 let day = local.date_naive();
289 let day = local.date_naive();
264 let days_ago = (today - day).num_days();
290 let days_ago = (today - day).num_days();
265 let clock = local.format(style.map_or("%H:%M", |style| style.clock));
291 let clock = local.format(style.map_or("%H:%M", |style| style.clock));
crates/app-state/src/activity/feed.rs +7 −4
@@ -1,6 +1,7 @@
1 1 use std::collections::HashMap;
2 2
3 use chrono::{DateTime, FixedOffset, NaiveDate, Utc};
3 use app_base::format::Zone;
4 use chrono::{DateTime, NaiveDate, Utc};
4 5 use serde::{Deserialize, Serialize};
5 6
6 7 use crate::reaction_model::UNKNOWN_REACTOR;
@@ -99,8 +100,8 @@ pub enum Bucket {
99 100 }
100 101
101 102 impl Bucket {
102 pub fn of(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> Bucket {
103 let days_ago = (today - time.with_timezone(&offset).date_naive()).num_days();
103 pub fn of(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> Bucket {
104 let days_ago = (today - offset.into().at(time).date_naive()).num_days();
104 105 match days_ago {
105 106 ..=0 => Bucket::Today,
106 107 1 => Bucket::Yesterday,
@@ -224,8 +225,9 @@ impl Feed {
224 225 &self,
225 226 filter: Filter,
226 227 today: NaiveDate,
227 offset: FixedOffset,
228 offset: impl Into<Zone>,
228 229 ) -> Vec<Section<'_>> {
230 let offset = offset.into();
229 231 let mut admitted: Vec<&Entry> = self
230 232 .entries
231 233 .iter()
@@ -250,6 +252,7 @@ impl Feed {
250 252
251 253 #[cfg(test)]
252 254 mod tests {
255 use chrono::FixedOffset;
253 256 use chrono::TimeZone;
254 257
255 258 use super::*;
@@ -1,6 +1,7 @@
1use std::collections::HashMap;
1use std::collections::HashMap;
2
2
3use chrono::{DateTime, FixedOffset, NaiveDate, Utc};
3use app_base::format::Zone;
4use chrono::{DateTime, NaiveDate, Utc};
4use serde::{Deserialize, Serialize};
5use serde::{Deserialize, Serialize};
5
6
6use crate::reaction_model::UNKNOWN_REACTOR;
7use crate::reaction_model::UNKNOWN_REACTOR;
@@ -99,8 +100,8 @@ pub enum Bucket {
99}
100}
100
101
101impl Bucket {
102impl Bucket {
102 pub fn of(time: DateTime<Utc>, today: NaiveDate, offset: FixedOffset) -> Bucket {
103 pub fn of(time: DateTime<Utc>, today: NaiveDate, offset: impl Into<Zone>) -> Bucket {
103 let days_ago = (today - time.with_timezone(&offset).date_naive()).num_days();
104 let days_ago = (today - offset.into().at(time).date_naive()).num_days();
104 match days_ago {
105 match days_ago {
105 ..=0 => Bucket::Today,
106 ..=0 => Bucket::Today,
106 1 => Bucket::Yesterday,
107 1 => Bucket::Yesterday,
@@ -224,8 +225,9 @@ impl Feed {
224 &self,
225 &self,
225 filter: Filter,
226 filter: Filter,
226 today: NaiveDate,
227 today: NaiveDate,
227 offset: FixedOffset,
228 offset: impl Into<Zone>,
228 ) -> Vec<Section<'_>> {
229 ) -> Vec<Section<'_>> {
230 let offset = offset.into();
229 let mut admitted: Vec<&Entry> = self
231 let mut admitted: Vec<&Entry> = self
230 .entries
232 .entries
231 .iter()
233 .iter()
@@ -250,6 +252,7 @@ impl Feed {
250
252
251#[cfg(test)]
253#[cfg(test)]
252mod tests {
254mod tests {
255 use chrono::FixedOffset;
253 use chrono::TimeZone;
256 use chrono::TimeZone;
254
257
255 use super::*;
258 use super::*;
crates/app-state/src/call_rows.rs +12 −9
@@ -1,6 +1,7 @@
1 1 use std::collections::{HashMap, HashSet};
2 2
3 use chrono::{DateTime, FixedOffset, NaiveDate, Utc};
3 use app_base::format::Zone;
4 use chrono::{DateTime, NaiveDate, Utc};
4 5 use store::MessageRecord;
5 6 use teams_core::roster_event::RosterEvent;
6 7 use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
@@ -134,7 +135,7 @@ pub fn roster_card(
134 135 }
135 136
136 137 pub struct CallClock<'a> {
137 pub offset: FixedOffset,
138 pub offset: Zone,
138 139 pub today: NaiveDate,
139 140 pub meeting: &'a MeetingInfo,
140 141 }
@@ -322,19 +323,20 @@ fn recap_date_line(
322 323 });
323 324 format!(
324 325 "{} - {}",
325 slot.start.with_timezone(&clock.offset).format(&format!(
326 clock.offset.at(slot.start).format(&format!(
326 327 "{RECAP_DATE_FORMAT} {}",
327 328 app_base::format::clock_format()
328 329 )),
329 slot.end
330 .with_timezone(&clock.offset)
330 clock
331 .offset
332 .at(slot.end)
331 333 .format(app_base::format::clock_format())
332 334 )
333 335 }
334 336
335 337 /// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
336 338 fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
337 let local = time.with_timezone(&clock.offset);
339 let local = clock.offset.at(time);
338 340 let days_ago = (clock.today - local.date_naive()).num_days();
339 341 if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
340 342 format!(
@@ -543,6 +545,7 @@ pub fn call_card(
543 545
544 546 #[cfg(test)]
545 547 mod tests {
548 use chrono::FixedOffset;
546 549 use chrono::TimeZone;
547 550 use teams_core::Recording;
548 551
@@ -603,7 +606,7 @@ mod tests {
603 606 names: &names,
604 607 };
605 608 let clock = CallClock {
606 offset: FixedOffset::east_opt(0).unwrap(),
609 offset: FixedOffset::east_opt(0).unwrap().into(),
607 610 today: NaiveDate::from_ymd_opt(2026, 10, 30).unwrap(),
608 611 meeting,
609 612 };
@@ -728,7 +731,7 @@ mod tests {
728 731 started_at,
729 732 ended_at,
730 733 &CallClock {
731 offset: FixedOffset::east_opt(2 * 3600).unwrap(),
734 offset: FixedOffset::east_opt(2 * 3600).unwrap().into(),
732 735 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
733 736 meeting,
734 737 },
@@ -752,7 +755,7 @@ mod tests {
752 755 fn notice_stamps_spell_out_the_weekday_like_teams() {
753 756 let meeting = MeetingInfo::default();
754 757 let clock = CallClock {
755 offset: FixedOffset::east_opt(0).unwrap(),
758 offset: FixedOffset::east_opt(0).unwrap().into(),
756 759 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
757 760 meeting: &meeting,
758 761 };
@@ -1,6 +1,7 @@
1use std::collections::{HashMap, HashSet};
1use std::collections::{HashMap, HashSet};
2
2
3use chrono::{DateTime, FixedOffset, NaiveDate, Utc};
3use app_base::format::Zone;
4use chrono::{DateTime, NaiveDate, Utc};
4use store::MessageRecord;
5use store::MessageRecord;
5use teams_core::roster_event::RosterEvent;
6use teams_core::roster_event::RosterEvent;
6use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
7use teams_core::{CallEvent, CallPhase, CallType, ImageRef, format_duration};
@@ -134,7 +135,7 @@ pub fn roster_card(
134}
135}
135
136
136pub struct CallClock<'a> {
137pub struct CallClock<'a> {
137 pub offset: FixedOffset,
138 pub offset: Zone,
138 pub today: NaiveDate,
139 pub today: NaiveDate,
139 pub meeting: &'a MeetingInfo,
140 pub meeting: &'a MeetingInfo,
140}
141}
@@ -322,19 +323,20 @@ fn recap_date_line(
322 });
323 });
323 format!(
324 format!(
324 "{} - {}",
325 "{} - {}",
325 slot.start.with_timezone(&clock.offset).format(&format!(
326 clock.offset.at(slot.start).format(&format!(
326 "{RECAP_DATE_FORMAT} {}",
327 "{RECAP_DATE_FORMAT} {}",
327 app_base::format::clock_format()
328 app_base::format::clock_format()
328 )),
329 )),
329 slot.end
330 clock
330 .with_timezone(&clock.offset)
331 .offset
332 .at(slot.end)
331 .format(app_base::format::clock_format())
333 .format(app_base::format::clock_format())
332 )
334 )
333}
335}
334
336
335/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
337/// Teams writes the weekday in full on these lines ("Thursday 11:45"), unlike message times.
336fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
338fn notice_stamp(time: DateTime<Utc>, clock: &CallClock) -> String {
337 let local = time.with_timezone(&clock.offset);
339 let local = clock.offset.at(time);
338 let days_ago = (clock.today - local.date_naive()).num_days();
340 let days_ago = (clock.today - local.date_naive()).num_days();
339 if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
341 if (2..=WEEKDAY_STAMP_DAYS).contains(&days_ago) {
340 format!(
342 format!(
@@ -543,6 +545,7 @@ pub fn call_card(
543
545
544#[cfg(test)]
546#[cfg(test)]
545mod tests {
547mod tests {
548 use chrono::FixedOffset;
546 use chrono::TimeZone;
549 use chrono::TimeZone;
547 use teams_core::Recording;
550 use teams_core::Recording;
548
551
@@ -603,7 +606,7 @@ mod tests {
603 names: &names,
606 names: &names,
604 };
607 };
605 let clock = CallClock {
608 let clock = CallClock {
606 offset: FixedOffset::east_opt(0).unwrap(),
609 offset: FixedOffset::east_opt(0).unwrap().into(),
607 today: NaiveDate::from_ymd_opt(2026, 10, 30).unwrap(),
610 today: NaiveDate::from_ymd_opt(2026, 10, 30).unwrap(),
608 meeting,
611 meeting,
609 };
612 };
@@ -728,7 +731,7 @@ mod tests {
728 started_at,
731 started_at,
729 ended_at,
732 ended_at,
730 &CallClock {
733 &CallClock {
731 offset: FixedOffset::east_opt(2 * 3600).unwrap(),
734 offset: FixedOffset::east_opt(2 * 3600).unwrap().into(),
732 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
735 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
733 meeting,
736 meeting,
734 },
737 },
@@ -752,7 +755,7 @@ mod tests {
752 fn notice_stamps_spell_out_the_weekday_like_teams() {
755 fn notice_stamps_spell_out_the_weekday_like_teams() {
753 let meeting = MeetingInfo::default();
756 let meeting = MeetingInfo::default();
754 let clock = CallClock {
757 let clock = CallClock {
755 offset: FixedOffset::east_opt(0).unwrap(),
758 offset: FixedOffset::east_opt(0).unwrap().into(),
756 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
759 today: NaiveDate::from_ymd_opt(2026, 10, 17).unwrap(),
757 meeting: &meeting,
760 meeting: &meeting,
758 };
761 };
crates/app-state/src/find_in_chat.rs +14 −7
@@ -1,8 +1,9 @@
1 1 use std::collections::HashSet;
2 2 use std::ops::Range;
3 3
4 use app_base::format::Zone;
4 5 use chatsvc::substrate_search::{MessageFilter, SearchMessage, split_highlights};
5 use chrono::{DateTime, Datelike, Duration, FixedOffset, NaiveDate, Utc};
6 use chrono::{DateTime, Datelike, Duration, NaiveDate, Utc};
6 7 use store::{HIGHLIGHT_END, HIGHLIGHT_START, MessageRecord, SearchHit};
7 8
8 9 pub const FIND_IN_CHAT: &str = "Find in chat";
@@ -94,15 +95,15 @@ impl FindFilters {
94 95 self.from.is_some() || self.date.is_some() || self.has_attachment || self.mentions_me
95 96 }
96 97
97 pub fn admits(&self, hit: &FindHit, today: NaiveDate, offset: FixedOffset) -> bool {
98 pub fn admits(&self, hit: &FindHit, today: NaiveDate, offset: impl Into<Zone>) -> bool {
98 99 let from_holds = self.from.as_ref().is_none_or(|sender| {
99 100 hit.sender_id
100 101 .as_deref()
101 102 .is_some_and(|sender_id| same_user(sender_id, &sender.user_id))
102 103 });
103 let date_holds = self.date.is_none_or(|range| {
104 range.contains(hit.sent_at.with_timezone(&offset).date_naive(), today)
105 });
104 let date_holds = self
105 .date
106 .is_none_or(|range| range.contains(offset.into().at(hit.sent_at).date_naive(), today));
106 107 from_holds
107 108 && date_holds
108 109 && (!self.has_attachment || hit.has_attachment)
@@ -259,10 +260,15 @@ pub struct MonthGroup {
259 260 pub hits: Vec<FindHit>,
260 261 }
261 262
262 pub fn group_by_month(hits: &[FindHit], today: NaiveDate, offset: FixedOffset) -> Vec<MonthGroup> {
263 pub fn group_by_month(
264 hits: &[FindHit],
265 today: NaiveDate,
266 offset: impl Into<Zone>,
267 ) -> Vec<MonthGroup> {
268 let offset = offset.into();
263 269 let mut groups: Vec<MonthGroup> = Vec::new();
264 270 for hit in hits {
265 let label = month_label(hit.sent_at.with_timezone(&offset).date_naive(), today);
271 let label = month_label(offset.at(hit.sent_at).date_naive(), today);
266 272 match groups.last_mut() {
267 273 Some(group) if group.label == label => group.hits.push(hit.clone()),
268 274 _ => groups.push(MonthGroup {
@@ -288,6 +294,7 @@ pub fn step_index(current: Option<usize>, count: usize, backwards: bool) -> Opti
288 294
289 295 #[cfg(test)]
290 296 mod tests {
297 use chrono::FixedOffset;
291 298 use chrono::TimeZone;
292 299
293 300 use super::*;
@@ -1,8 +1,9 @@
1use std::collections::HashSet;
1use std::collections::HashSet;
2use std::ops::Range;
2use std::ops::Range;
3
3
4use app_base::format::Zone;
4use chatsvc::substrate_search::{MessageFilter, SearchMessage, split_highlights};
5use chatsvc::substrate_search::{MessageFilter, SearchMessage, split_highlights};
5use chrono::{DateTime, Datelike, Duration, FixedOffset, NaiveDate, Utc};
6use chrono::{DateTime, Datelike, Duration, NaiveDate, Utc};
6use store::{HIGHLIGHT_END, HIGHLIGHT_START, MessageRecord, SearchHit};
7use store::{HIGHLIGHT_END, HIGHLIGHT_START, MessageRecord, SearchHit};
7
8
8pub const FIND_IN_CHAT: &str = "Find in chat";
9pub const FIND_IN_CHAT: &str = "Find in chat";
@@ -94,15 +95,15 @@ impl FindFilters {
94 self.from.is_some() || self.date.is_some() || self.has_attachment || self.mentions_me
95 self.from.is_some() || self.date.is_some() || self.has_attachment || self.mentions_me
95 }
96 }
96
97
97 pub fn admits(&self, hit: &FindHit, today: NaiveDate, offset: FixedOffset) -> bool {
98 pub fn admits(&self, hit: &FindHit, today: NaiveDate, offset: impl Into<Zone>) -> bool {
98 let from_holds = self.from.as_ref().is_none_or(|sender| {
99 let from_holds = self.from.as_ref().is_none_or(|sender| {
99 hit.sender_id
100 hit.sender_id
100 .as_deref()
101 .as_deref()
101 .is_some_and(|sender_id| same_user(sender_id, &sender.user_id))
102 .is_some_and(|sender_id| same_user(sender_id, &sender.user_id))
102 });
103 });
103 let date_holds = self.date.is_none_or(|range| {
104 let date_holds = self
104 range.contains(hit.sent_at.with_timezone(&offset).date_naive(), today)
105 .date
105 });
106 .is_none_or(|range| range.contains(offset.into().at(hit.sent_at).date_naive(), today));
106 from_holds
107 from_holds
107 && date_holds
108 && date_holds
108 && (!self.has_attachment || hit.has_attachment)
109 && (!self.has_attachment || hit.has_attachment)
@@ -259,10 +260,15 @@ pub struct MonthGroup {
259 pub hits: Vec<FindHit>,
260 pub hits: Vec<FindHit>,
260}
261}
261
262
262pub fn group_by_month(hits: &[FindHit], today: NaiveDate, offset: FixedOffset) -> Vec<MonthGroup> {
263pub fn group_by_month(
264 hits: &[FindHit],
265 today: NaiveDate,
266 offset: impl Into<Zone>,
267) -> Vec<MonthGroup> {
268 let offset = offset.into();
263 let mut groups: Vec<MonthGroup> = Vec::new();
269 let mut groups: Vec<MonthGroup> = Vec::new();
264 for hit in hits {
270 for hit in hits {
265 let label = month_label(hit.sent_at.with_timezone(&offset).date_naive(), today);
271 let label = month_label(offset.at(hit.sent_at).date_naive(), today);
266 match groups.last_mut() {
272 match groups.last_mut() {
267 Some(group) if group.label == label => group.hits.push(hit.clone()),
273 Some(group) if group.label == label => group.hits.push(hit.clone()),
268 _ => groups.push(MonthGroup {
274 _ => groups.push(MonthGroup {
@@ -288,6 +294,7 @@ pub fn step_index(current: Option<usize>, count: usize, backwards: bool) -> Opti
288
294
289#[cfg(test)]
295#[cfg(test)]
290mod tests {
296mod tests {
297 use chrono::FixedOffset;
291 use chrono::TimeZone;
298 use chrono::TimeZone;
292
299
293 use super::*;
300 use super::*;
crates/app-state/src/message_actions.rs +2 −2
@@ -1,6 +1,6 @@
1 1 use std::collections::HashSet;
2 2
3 use chrono::{DateTime, Local, Offset, Utc};
3 use chrono::{DateTime, Local, Utc};
4 4 use gpui_kit::*;
5 5 use store::MessageRecord;
6 6 use teams_core::{PinnedMessage, SavedMessage};
@@ -439,7 +439,7 @@ impl AppState {
439 439 }
440 440
441 441 fn forward_time(time: DateTime<Utc>, now: DateTime<Local>) -> String {
442 format::list_time_label(time, now.date_naive(), now.offset().fix())
442 format::list_time_label(time, now.date_naive(), app_base::format::Zone::Local)
443 443 }
444 444
445 445 #[cfg(test)]
@@ -1,6 +1,6 @@
1use std::collections::HashSet;
1use std::collections::HashSet;
2
2
3use chrono::{DateTime, Local, Offset, Utc};
3use chrono::{DateTime, Local, Utc};
4use gpui_kit::*;
4use gpui_kit::*;
5use store::MessageRecord;
5use store::MessageRecord;
6use teams_core::{PinnedMessage, SavedMessage};
6use teams_core::{PinnedMessage, SavedMessage};
@@ -439,7 +439,7 @@ impl AppState {
439}
439}
440
440
441fn forward_time(time: DateTime<Utc>, now: DateTime<Local>) -> String {
441fn forward_time(time: DateTime<Utc>, now: DateTime<Local>) -> String {
442 format::list_time_label(time, now.date_naive(), now.offset().fix())
442 format::list_time_label(time, now.date_naive(), app_base::format::Zone::Local)
443}
443}
444
444
445#[cfg(test)]
445#[cfg(test)]
crates/app-state/src/rows.rs +12 −14
@@ -2,7 +2,8 @@ use std::collections::{BTreeMap, HashMap};
2 2 use std::ops::Range;
3 3 use std::sync::Arc;
4 4
5 use chrono::{DateTime, Duration, FixedOffset, NaiveDate, Utc};
5 use app_base::format::Zone;
6 use chrono::{DateTime, Duration, NaiveDate, Utc};
6 7 use gpui_kit::Image;
7 8 use store::{MessageImportance, MessageRecord};
8 9 use teams_core::roster_event::{RosterEvent, roster_event};
@@ -401,8 +402,10 @@ pub struct Thread {
401 402 pub reply_ids: Vec<String>,
402 403 }
403 404
404 pub fn clock_label(time: DateTime<Utc>, offset: FixedOffset) -> String {
405 time.with_timezone(&offset)
405 pub fn clock_label(time: DateTime<Utc>, offset: impl Into<Zone>) -> String {
406 offset
407 .into()
408 .at(time)
406 409 .format(app_base::format::clock_format())
407 410 .to_string()
408 411 }
@@ -634,7 +637,7 @@ pub fn reply_excerpt(record: &MessageRecord) -> String {
634 637 }
635 638
636 639 pub struct RowContext {
637 pub offset: FixedOffset,
640 pub offset: Zone,
638 641 pub today: NaiveDate,
639 642 pub my_user_id: Option<String>,
640 643 pub names: HashMap<String, String>,
@@ -768,10 +771,7 @@ fn event_row(
768 771 series: Series::default(),
769 772 author: author.name,
770 773 day_header: Some(format::day_label(
771 record
772 .created_at
773 .with_timezone(&context.offset)
774 .date_naive(),
774 context.offset.at(record.created_at).date_naive(),
775 775 context.today,
776 776 )),
777 777 blocks: Vec::new(),
@@ -879,7 +879,7 @@ fn message_row_with(
879 879 if let Some(event) = roster_event(record) {
880 880 return roster_row(record, &event, context);
881 881 }
882 let local = record.created_at.with_timezone(&context.offset);
882 let local = context.offset.at(record.created_at);
883 883 let images = images(record);
884 884 let own = context.my_user_id.is_some() && record.sender_id == context.my_user_id;
885 885 let translation = context.translation.resolve(record, own);
@@ -971,10 +971,7 @@ pub fn flat_rows(records: &[MessageRecord], context: &RowContext, has_older: boo
971 971 if let Some(call) = row.call.as_mut() {
972 972 call.started &= timeline.is_live_start(index);
973 973 }
974 let day = record
975 .created_at
976 .with_timezone(&context.offset)
977 .date_naive();
974 let day = context.offset.at(record.created_at).date_naive();
978 975 if previous_day == Some(day) {
979 976 row.day_header = None;
980 977 }
@@ -1264,6 +1261,7 @@ pub fn changed_indices(old: &[Row], new: &[Row]) -> Vec<usize> {
1264 1261
1265 1262 #[cfg(test)]
1266 1263 mod tests {
1264 use chrono::FixedOffset;
1267 1265 use chrono::TimeZone;
1268 1266 use teams_core::CallType;
1269 1267
@@ -1526,7 +1524,7 @@ mod tests {
1526 1524
1527 1525 fn context() -> RowContext {
1528 1526 RowContext {
1529 offset: FixedOffset::east_opt(0).unwrap(),
1527 offset: FixedOffset::east_opt(0).unwrap().into(),
1530 1528 today: NaiveDate::from_ymd_opt(2026, 10, 7).unwrap(),
1531 1529 my_user_id: None,
1532 1530 names: HashMap::new(),
@@ -2,7 +2,8 @@ use std::collections::{BTreeMap, HashMap};
2use std::ops::Range;
2use std::ops::Range;
3use std::sync::Arc;
3use std::sync::Arc;
4
4
5use chrono::{DateTime, Duration, FixedOffset, NaiveDate, Utc};
5use app_base::format::Zone;
6use chrono::{DateTime, Duration, NaiveDate, Utc};
6use gpui_kit::Image;
7use gpui_kit::Image;
7use store::{MessageImportance, MessageRecord};
8use store::{MessageImportance, MessageRecord};
8use teams_core::roster_event::{RosterEvent, roster_event};
9use teams_core::roster_event::{RosterEvent, roster_event};
@@ -401,8 +402,10 @@ pub struct Thread {
401 pub reply_ids: Vec<String>,
402 pub reply_ids: Vec<String>,
402}
403}
403
404
404pub fn clock_label(time: DateTime<Utc>, offset: FixedOffset) -> String {
405pub fn clock_label(time: DateTime<Utc>, offset: impl Into<Zone>) -> String {
405 time.with_timezone(&offset)
406 offset
407 .into()
408 .at(time)
406 .format(app_base::format::clock_format())
409 .format(app_base::format::clock_format())
407 .to_string()
410 .to_string()
408}
411}
@@ -634,7 +637,7 @@ pub fn reply_excerpt(record: &MessageRecord) -> String {
634}
637}
635
638
636pub struct RowContext {
639pub struct RowContext {
637 pub offset: FixedOffset,
640 pub offset: Zone,
638 pub today: NaiveDate,
641 pub today: NaiveDate,
639 pub my_user_id: Option<String>,
642 pub my_user_id: Option<String>,
640 pub names: HashMap<String, String>,
643 pub names: HashMap<String, String>,
@@ -768,10 +771,7 @@ fn event_row(
768 series: Series::default(),
771 series: Series::default(),
769 author: author.name,
772 author: author.name,
770 day_header: Some(format::day_label(
773 day_header: Some(format::day_label(
771 record
774 context.offset.at(record.created_at).date_naive(),
772 .created_at
773 .with_timezone(&context.offset)
774 .date_naive(),
775 context.today,
775 context.today,
776 )),
776 )),
777 blocks: Vec::new(),
777 blocks: Vec::new(),
@@ -879,7 +879,7 @@ fn message_row_with(
879 if let Some(event) = roster_event(record) {
879 if let Some(event) = roster_event(record) {
880 return roster_row(record, &event, context);
880 return roster_row(record, &event, context);
881 }
881 }
882 let local = record.created_at.with_timezone(&context.offset);
882 let local = context.offset.at(record.created_at);
883 let images = images(record);
883 let images = images(record);
884 let own = context.my_user_id.is_some() && record.sender_id == context.my_user_id;
884 let own = context.my_user_id.is_some() && record.sender_id == context.my_user_id;
885 let translation = context.translation.resolve(record, own);
885 let translation = context.translation.resolve(record, own);
@@ -971,10 +971,7 @@ pub fn flat_rows(records: &[MessageRecord], context: &RowContext, has_older: boo
971 if let Some(call) = row.call.as_mut() {
971 if let Some(call) = row.call.as_mut() {
972 call.started &= timeline.is_live_start(index);
972 call.started &= timeline.is_live_start(index);
973 }
973 }
974 let day = record
974 let day = context.offset.at(record.created_at).date_naive();
975 .created_at
976 .with_timezone(&context.offset)
977 .date_naive();
978 if previous_day == Some(day) {
975 if previous_day == Some(day) {
979 row.day_header = None;
976 row.day_header = None;
980 }
977 }
@@ -1264,6 +1261,7 @@ pub fn changed_indices(old: &[Row], new: &[Row]) -> Vec<usize> {
1264
1261
1265#[cfg(test)]
1262#[cfg(test)]
1266mod tests {
1263mod tests {
1264 use chrono::FixedOffset;
1267 use chrono::TimeZone;
1265 use chrono::TimeZone;
1268 use teams_core::CallType;
1266 use teams_core::CallType;
1269
1267
@@ -1526,7 +1524,7 @@ mod tests {
1526
1524
1527 fn context() -> RowContext {
1525 fn context() -> RowContext {
1528 RowContext {
1526 RowContext {
1529 offset: FixedOffset::east_opt(0).unwrap(),
1527 offset: FixedOffset::east_opt(0).unwrap().into(),
1530 today: NaiveDate::from_ymd_opt(2026, 10, 7).unwrap(),
1528 today: NaiveDate::from_ymd_opt(2026, 10, 7).unwrap(),
1531 my_user_id: None,
1529 my_user_id: None,
1532 names: HashMap::new(),
1530 names: HashMap::new(),
crates/app/src/views/activity_panel.rs +11 −10
@@ -3,7 +3,7 @@ use std::ops::Range;
3 3 use std::rc::Rc;
4 4
5 5 use app_ui_kit::layout::SIDEBAR_WIDTH;
6 use chrono::{DateTime, Local, NaiveDate, Offset, TimeZone, Utc};
6 use chrono::{DateTime, Local, NaiveDate, TimeZone, Utc};
7 7 use gpui_kit::assets::IconName;
8 8 use gpui_kit::component::scroll::ScrollableElement as _;
9 9 use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
@@ -267,7 +267,7 @@ impl ActivityPanel {
267 267 sidebar: &Sidebar,
268 268 directory: &crate::data::Directory,
269 269 today: NaiveDate,
270 offset: chrono::FixedOffset,
270 offset: app_base::format::Zone,
271 271 panel: Entity<ActivityPanel>,
272 272 ) -> AnyElement {
273 273 let activity = self.activity.clone();
@@ -309,7 +309,7 @@ impl ActivityPanel {
309 309 pending: &PendingProposal,
310 310 sidebar: &Sidebar,
311 311 today: NaiveDate,
312 offset: chrono::FixedOffset,
312 offset: app_base::format::Zone,
313 313 panel: Entity<ActivityPanel>,
314 314 ) -> AnyElement {
315 315 let group = SharedString::from(format!("activity-proposal-group-{}", pending.id));
@@ -824,7 +824,7 @@ fn visible_slots(heights: &[f32], from: f32, to: f32) -> VisibleSlots {
824 824 impl Render for ActivityPanel {
825 825 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
826 826 let now: DateTime<Local> = Local::now();
827 let (today, offset) = (now.date_naive(), now.offset().fix());
827 let (today, offset) = (now.date_naive(), app_base::format::Zone::Local);
828 828 let panel = cx.entity();
829 829 let app = self.app.clone();
830 830 let activity = self.activity.clone();
@@ -947,7 +947,7 @@ mod tests {
947 947 use std::collections::HashMap;
948 948 use std::sync::Arc;
949 949
950 use chrono::{Local, Offset, TimeZone, Utc};
950 use chrono::{Local, TimeZone, Utc};
951 951 use gpui_kit::{AppContext as _, Modifiers, TestAppContext};
952 952 use store::{ChatRecord, Sidebar, Store};
953 953
@@ -1178,11 +1178,12 @@ mod tests {
1178 1178 let activity = cx.update(|_, cx| panel.read(cx).activity.clone());
1179 1179 let first_unread = cx.update(|_, cx| {
1180 1180 let now = Local::now();
1181 activity
1182 .read(cx)
1183 .feed()
1184 .sections(Filter::Unread, now.date_naive(), now.offset().fix())[0]
1185 .entries[0]
1181 activity.read(cx).feed().sections(
1182 Filter::Unread,
1183 now.date_naive(),
1184 app_base::format::Zone::Local,
1185 )[0]
1186 .entries[0]
1186 1187 .id
1187 1188 .clone()
1188 1189 });
@@ -3,7 +3,7 @@ use std::ops::Range;
3use std::rc::Rc;
3use std::rc::Rc;
4
4
5use app_ui_kit::layout::SIDEBAR_WIDTH;
5use app_ui_kit::layout::SIDEBAR_WIDTH;
6use chrono::{DateTime, Local, NaiveDate, Offset, TimeZone, Utc};
6use chrono::{DateTime, Local, NaiveDate, TimeZone, Utc};
7use gpui_kit::assets::IconName;
7use gpui_kit::assets::IconName;
8use gpui_kit::component::scroll::ScrollableElement as _;
8use gpui_kit::component::scroll::ScrollableElement as _;
9use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
9use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
@@ -267,7 +267,7 @@ impl ActivityPanel {
267 sidebar: &Sidebar,
267 sidebar: &Sidebar,
268 directory: &crate::data::Directory,
268 directory: &crate::data::Directory,
269 today: NaiveDate,
269 today: NaiveDate,
270 offset: chrono::FixedOffset,
270 offset: app_base::format::Zone,
271 panel: Entity<ActivityPanel>,
271 panel: Entity<ActivityPanel>,
272 ) -> AnyElement {
272 ) -> AnyElement {
273 let activity = self.activity.clone();
273 let activity = self.activity.clone();
@@ -309,7 +309,7 @@ impl ActivityPanel {
309 pending: &PendingProposal,
309 pending: &PendingProposal,
310 sidebar: &Sidebar,
310 sidebar: &Sidebar,
311 today: NaiveDate,
311 today: NaiveDate,
312 offset: chrono::FixedOffset,
312 offset: app_base::format::Zone,
313 panel: Entity<ActivityPanel>,
313 panel: Entity<ActivityPanel>,
314 ) -> AnyElement {
314 ) -> AnyElement {
315 let group = SharedString::from(format!("activity-proposal-group-{}", pending.id));
315 let group = SharedString::from(format!("activity-proposal-group-{}", pending.id));
@@ -824,7 +824,7 @@ fn visible_slots(heights: &[f32], from: f32, to: f32) -> VisibleSlots {
824impl Render for ActivityPanel {
824impl Render for ActivityPanel {
825 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
825 fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
826 let now: DateTime<Local> = Local::now();
826 let now: DateTime<Local> = Local::now();
827 let (today, offset) = (now.date_naive(), now.offset().fix());
827 let (today, offset) = (now.date_naive(), app_base::format::Zone::Local);
828 let panel = cx.entity();
828 let panel = cx.entity();
829 let app = self.app.clone();
829 let app = self.app.clone();
830 let activity = self.activity.clone();
830 let activity = self.activity.clone();
@@ -947,7 +947,7 @@ mod tests {
947 use std::collections::HashMap;
947 use std::collections::HashMap;
948 use std::sync::Arc;
948 use std::sync::Arc;
949
949
950 use chrono::{Local, Offset, TimeZone, Utc};
950 use chrono::{Local, TimeZone, Utc};
951 use gpui_kit::{AppContext as _, Modifiers, TestAppContext};
951 use gpui_kit::{AppContext as _, Modifiers, TestAppContext};
952 use store::{ChatRecord, Sidebar, Store};
952 use store::{ChatRecord, Sidebar, Store};
953
953
@@ -1178,11 +1178,12 @@ mod tests {
1178 let activity = cx.update(|_, cx| panel.read(cx).activity.clone());
1178 let activity = cx.update(|_, cx| panel.read(cx).activity.clone());
1179 let first_unread = cx.update(|_, cx| {
1179 let first_unread = cx.update(|_, cx| {
1180 let now = Local::now();
1180 let now = Local::now();
1181 activity
1181 activity.read(cx).feed().sections(
1182 .read(cx)
1182 Filter::Unread,
1183 .feed()
1183 now.date_naive(),
1184 .sections(Filter::Unread, now.date_naive(), now.offset().fix())[0]
1184 app_base::format::Zone::Local,
1185 .entries[0]
1185 )[0]
1186 .entries[0]
1186 .id
1187 .id
1187 .clone()
1188 .clone()
1188 });
1189 });
crates/app/src/views/composer.rs +56 −3
@@ -250,6 +250,8 @@ pub struct Composer {
250 250 saved_images: Option<drafts::ImageFingerprint>,
251 251 schedule: Option<schedule::SchedulePopover>,
252 252 scheduling: Option<String>,
253 scheduling_for: Option<String>,
254 draft_before_edit: Option<(Outgoing, Vec<u64>)>,
253 255 pending_anchors: HashMap<u64, usize>,
254 256 link: ComposeLink,
255 257 fun_picker: Entity<FunPicker>,
@@ -525,6 +527,8 @@ impl Composer {
525 527 saved_images: None,
526 528 schedule: None,
527 529 scheduling: None,
530 scheduling_for: None,
531 draft_before_edit: None,
528 532 pending_anchors: HashMap::new(),
529 533 link: ComposeLink::default(),
530 534 fun_picker,
@@ -1791,6 +1795,7 @@ impl Composer {
1791 1795 self.save_draft_now(cx);
1792 1796 self.draft_save = None;
1793 1797 self.saved_images = None;
1798 self.draft_before_edit = None;
1794 1799 let carry = self.carry_images_into.take().as_deref() == Some(conversation_id);
1795 1800 self.conversation_id = Some(conversation_id.to_owned());
1796 1801 self.close_rewrite();
@@ -1842,13 +1847,41 @@ impl Composer {
1842 1847 }
1843 1848
1844 1849 pub fn begin_edit(&mut self, draft: Outgoing, window: &mut Window, cx: &mut Context<Self>) {
1850 if self.editing.is_none() {
1851 self.save_draft_now(cx);
1852 let image_ids = self.live_image_ids(cx);
1853 self.draft_before_edit = Some((self.compose(cx), image_ids));
1854 }
1845 1855 self.restore(&draft, window, cx);
1846 1856 self.focus(window, cx);
1847 1857 }
1848 1858
1849 1859 pub fn cancel_edit(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1850 1860 self.editing = None;
1851 self.set_text("", window, cx);
1861 self.restore_draft_before_edit(window, cx);
1862 }
1863
1864 fn live_image_ids(&self, cx: &App) -> Vec<u64> {
1865 self.input
1866 .read(cx)
1867 .tokens()
1868 .iter()
1869 .filter_map(|span| image_id(span.token()))
1870 .filter(|id| self.tray.image(*id).is_some())
1871 .collect()
1872 }
1873
1874 fn restore_draft_before_edit(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1875 match self.draft_before_edit.take() {
1876 Some((outgoing, image_ids)) => {
1877 let image_ids = image_ids
1878 .into_iter()
1879 .filter(|id| self.tray.image(*id).is_some())
1880 .collect();
1881 self.restore_content(&outgoing, image_ids, window, cx);
1882 }
1883 None => self.set_text("", window, cx),
1884 }
1852 1885 }
1853 1886
1854 1887 fn outgoing(&self, cx: &App) -> Option<Outgoing> {
@@ -2372,9 +2405,10 @@ impl Composer {
2372 2405 }
2373 2406
2374 2407 pub fn submit_current(&mut self, window: &mut Window, cx: &mut Context<Self>) {
2375 if self.scheduling.is_some() {
2408 if self.scheduling.is_some() && self.scheduling_for == self.conversation_id {
2376 2409 return;
2377 2410 }
2411 let was_editing = self.editing.is_some();
2378 2412 let Some(outgoing) = self.outgoing(cx) else {
2379 2413 return;
2380 2414 };
@@ -2391,6 +2425,9 @@ impl Composer {
2391 2425 self.close_popup();
2392 2426 self.reset_importance();
2393 2427 self.close_announcement(window, cx);
2428 if was_editing {
2429 self.restore_draft_before_edit(window, cx);
2430 }
2394 2431 cx.emit(ComposerEvent::Submit(Box::new(outgoing)));
2395 2432 cx.notify();
2396 2433 }
@@ -2423,13 +2460,23 @@ impl Composer {
2423 2460 }
2424 2461
2425 2462 pub fn restore(&mut self, outgoing: &Outgoing, window: &mut Window, cx: &mut Context<Self>) {
2426 self.mention_inputs.clear();
2427 2463 let image_ids = if outgoing.edit.is_none() {
2428 2464 self.cancel_uploads();
2429 2465 self.tray.restore(&outgoing.images, &outgoing.files)
2430 2466 } else {
2431 2467 Vec::new()
2432 2468 };
2469 self.restore_content(outgoing, image_ids, window, cx);
2470 }
2471
2472 fn restore_content(
2473 &mut self,
2474 outgoing: &Outgoing,
2475 image_ids: Vec<u64>,
2476 window: &mut Window,
2477 cx: &mut Context<Self>,
2478 ) {
2479 self.mention_inputs.clear();
2433 2480 let text = outgoing.draft.text();
2434 2481 let mut content = InputContent::new(text.to_owned());
2435 2482 for ((offset, _), id) in text.match_indices(OBJECT_MARK).zip(image_ids) {
@@ -2497,6 +2544,10 @@ impl Composer {
2497 2544 cx.notify();
2498 2545 }
2499 2546
2547 pub fn unsent(&self, cx: &App) -> Option<Outgoing> {
2548 (!self.draft.is_blank() && self.editing.is_none()).then(|| self.compose(cx))
2549 }
2550
2500 2551 pub fn is_empty(&self, cx: &App) -> bool {
2501 2552 self.draft.is_blank() && !self.has_attachments(cx)
2502 2553 }
@@ -5316,6 +5367,7 @@ mod tests {
5316 5367 files: Vec::new(),
5317 5368 importance: Default::default(),
5318 5369 };
5370 composer.set_text("half reply", window, cx);
5319 5371 composer.begin_edit(draft, window, cx);
5320 5372 });
5321 5373 })
@@ -5335,6 +5387,7 @@ mod tests {
5335 5387 let composer = composer.read(cx);
5336 5388 assert_eq!(composer.tray.items().len(), 1);
5337 5389 assert!(composer.can_send(cx));
5390 assert_eq!(composer.outgoing(cx).unwrap().text(), "half reply");
5338 5391 });
5339 5392 }
5340 5393
@@ -250,6 +250,8 @@ pub struct Composer {
250 saved_images: Option<drafts::ImageFingerprint>,
250 saved_images: Option<drafts::ImageFingerprint>,
251 schedule: Option<schedule::SchedulePopover>,
251 schedule: Option<schedule::SchedulePopover>,
252 scheduling: Option<String>,
252 scheduling: Option<String>,
253 scheduling_for: Option<String>,
254 draft_before_edit: Option<(Outgoing, Vec<u64>)>,
253 pending_anchors: HashMap<u64, usize>,
255 pending_anchors: HashMap<u64, usize>,
254 link: ComposeLink,
256 link: ComposeLink,
255 fun_picker: Entity<FunPicker>,
257 fun_picker: Entity<FunPicker>,
@@ -525,6 +527,8 @@ impl Composer {
525 saved_images: None,
527 saved_images: None,
526 schedule: None,
528 schedule: None,
527 scheduling: None,
529 scheduling: None,
530 scheduling_for: None,
531 draft_before_edit: None,
528 pending_anchors: HashMap::new(),
532 pending_anchors: HashMap::new(),
529 link: ComposeLink::default(),
533 link: ComposeLink::default(),
530 fun_picker,
534 fun_picker,
@@ -1791,6 +1795,7 @@ impl Composer {
1791 self.save_draft_now(cx);
1795 self.save_draft_now(cx);
1792 self.draft_save = None;
1796 self.draft_save = None;
1793 self.saved_images = None;
1797 self.saved_images = None;
1798 self.draft_before_edit = None;
1794 let carry = self.carry_images_into.take().as_deref() == Some(conversation_id);
1799 let carry = self.carry_images_into.take().as_deref() == Some(conversation_id);
1795 self.conversation_id = Some(conversation_id.to_owned());
1800 self.conversation_id = Some(conversation_id.to_owned());
1796 self.close_rewrite();
1801 self.close_rewrite();
@@ -1842,13 +1847,41 @@ impl Composer {
1842 }
1847 }
1843
1848
1844 pub fn begin_edit(&mut self, draft: Outgoing, window: &mut Window, cx: &mut Context<Self>) {
1849 pub fn begin_edit(&mut self, draft: Outgoing, window: &mut Window, cx: &mut Context<Self>) {
1850 if self.editing.is_none() {
1851 self.save_draft_now(cx);
1852 let image_ids = self.live_image_ids(cx);
1853 self.draft_before_edit = Some((self.compose(cx), image_ids));
1854 }
1845 self.restore(&draft, window, cx);
1855 self.restore(&draft, window, cx);
1846 self.focus(window, cx);
1856 self.focus(window, cx);
1847 }
1857 }
1848
1858
1849 pub fn cancel_edit(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1859 pub fn cancel_edit(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1850 self.editing = None;
1860 self.editing = None;
1851 self.set_text("", window, cx);
1861 self.restore_draft_before_edit(window, cx);
1862 }
1863
1864 fn live_image_ids(&self, cx: &App) -> Vec<u64> {
1865 self.input
1866 .read(cx)
1867 .tokens()
1868 .iter()
1869 .filter_map(|span| image_id(span.token()))
1870 .filter(|id| self.tray.image(*id).is_some())
1871 .collect()
1872 }
1873
1874 fn restore_draft_before_edit(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1875 match self.draft_before_edit.take() {
1876 Some((outgoing, image_ids)) => {
1877 let image_ids = image_ids
1878 .into_iter()
1879 .filter(|id| self.tray.image(*id).is_some())
1880 .collect();
1881 self.restore_content(&outgoing, image_ids, window, cx);
1882 }
1883 None => self.set_text("", window, cx),
1884 }
1852 }
1885 }
1853
1886
1854 fn outgoing(&self, cx: &App) -> Option<Outgoing> {
1887 fn outgoing(&self, cx: &App) -> Option<Outgoing> {
@@ -2372,9 +2405,10 @@ impl Composer {
2372 }
2405 }
2373
2406
2374 pub fn submit_current(&mut self, window: &mut Window, cx: &mut Context<Self>) {
2407 pub fn submit_current(&mut self, window: &mut Window, cx: &mut Context<Self>) {
2375 if self.scheduling.is_some() {
2408 if self.scheduling.is_some() && self.scheduling_for == self.conversation_id {
2376 return;
2409 return;
2377 }
2410 }
2411 let was_editing = self.editing.is_some();
2378 let Some(outgoing) = self.outgoing(cx) else {
2412 let Some(outgoing) = self.outgoing(cx) else {
2379 return;
2413 return;
2380 };
2414 };
@@ -2391,6 +2425,9 @@ impl Composer {
2391 self.close_popup();
2425 self.close_popup();
2392 self.reset_importance();
2426 self.reset_importance();
2393 self.close_announcement(window, cx);
2427 self.close_announcement(window, cx);
2428 if was_editing {
2429 self.restore_draft_before_edit(window, cx);
2430 }
2394 cx.emit(ComposerEvent::Submit(Box::new(outgoing)));
2431 cx.emit(ComposerEvent::Submit(Box::new(outgoing)));
2395 cx.notify();
2432 cx.notify();
2396 }
2433 }
@@ -2423,13 +2460,23 @@ impl Composer {
2423 }
2460 }
2424
2461
2425 pub fn restore(&mut self, outgoing: &Outgoing, window: &mut Window, cx: &mut Context<Self>) {
2462 pub fn restore(&mut self, outgoing: &Outgoing, window: &mut Window, cx: &mut Context<Self>) {
2426 self.mention_inputs.clear();
2427 let image_ids = if outgoing.edit.is_none() {
2463 let image_ids = if outgoing.edit.is_none() {
2428 self.cancel_uploads();
2464 self.cancel_uploads();
2429 self.tray.restore(&outgoing.images, &outgoing.files)
2465 self.tray.restore(&outgoing.images, &outgoing.files)
2430 } else {
2466 } else {
2431 Vec::new()
2467 Vec::new()
2432 };
2468 };
2469 self.restore_content(outgoing, image_ids, window, cx);
2470 }
2471
2472 fn restore_content(
2473 &mut self,
2474 outgoing: &Outgoing,
2475 image_ids: Vec<u64>,
2476 window: &mut Window,
2477 cx: &mut Context<Self>,
2478 ) {
2479 self.mention_inputs.clear();
2433 let text = outgoing.draft.text();
2480 let text = outgoing.draft.text();
2434 let mut content = InputContent::new(text.to_owned());
2481 let mut content = InputContent::new(text.to_owned());
2435 for ((offset, _), id) in text.match_indices(OBJECT_MARK).zip(image_ids) {
2482 for ((offset, _), id) in text.match_indices(OBJECT_MARK).zip(image_ids) {
@@ -2497,6 +2544,10 @@ impl Composer {
2497 cx.notify();
2544 cx.notify();
2498 }
2545 }
2499
2546
2547 pub fn unsent(&self, cx: &App) -> Option<Outgoing> {
2548 (!self.draft.is_blank() && self.editing.is_none()).then(|| self.compose(cx))
2549 }
2550
2500 pub fn is_empty(&self, cx: &App) -> bool {
2551 pub fn is_empty(&self, cx: &App) -> bool {
2501 self.draft.is_blank() && !self.has_attachments(cx)
2552 self.draft.is_blank() && !self.has_attachments(cx)
2502 }
2553 }
@@ -5316,6 +5367,7 @@ mod tests {
5316 files: Vec::new(),
5367 files: Vec::new(),
5317 importance: Default::default(),
5368 importance: Default::default(),
5318 };
5369 };
5370 composer.set_text("half reply", window, cx);
5319 composer.begin_edit(draft, window, cx);
5371 composer.begin_edit(draft, window, cx);
5320 });
5372 });
5321 })
5373 })
@@ -5335,6 +5387,7 @@ mod tests {
5335 let composer = composer.read(cx);
5387 let composer = composer.read(cx);
5336 assert_eq!(composer.tray.items().len(), 1);
5388 assert_eq!(composer.tray.items().len(), 1);
5337 assert!(composer.can_send(cx));
5389 assert!(composer.can_send(cx));
5390 assert_eq!(composer.outgoing(cx).unwrap().text(), "half reply");
5338 });
5391 });
5339 }
5392 }
5340
5393
crates/app/src/views/composer/schedule.rs +1 −0
@@ -258,6 +258,7 @@ impl Composer {
258 258 self.importance = store::MessageImportance::Normal;
259 259 let outgoing = self.compose(cx);
260 260 self.scheduling = Some(outgoing.html());
261 self.scheduling_for = self.conversation_id.clone();
261 262 self.close_schedule(window, cx);
262 263 cx.emit(ComposerEvent::Schedule {
263 264 outgoing: Box::new(outgoing),
@@ -258,6 +258,7 @@ impl Composer {
258 self.importance = store::MessageImportance::Normal;
258 self.importance = store::MessageImportance::Normal;
259 let outgoing = self.compose(cx);
259 let outgoing = self.compose(cx);
260 self.scheduling = Some(outgoing.html());
260 self.scheduling = Some(outgoing.html());
261 self.scheduling_for = self.conversation_id.clone();
261 self.close_schedule(window, cx);
262 self.close_schedule(window, cx);
262 cx.emit(ComposerEvent::Schedule {
263 cx.emit(ComposerEvent::Schedule {
263 outgoing: Box::new(outgoing),
264 outgoing: Box::new(outgoing),
crates/app/src/views/conversation.rs +16 −6
@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
4 4 use std::rc::Rc;
5 5 use std::time::{Duration, Instant};
6 6
7 use chrono::{DateTime, Local, Offset, Utc};
7 use chrono::{DateTime, Local, Utc};
8 8 use gpui_kit::assets::IconName;
9 9 use gpui_kit::component::{
10 10 button::{Button, ButtonVariants as _},
@@ -232,6 +232,7 @@ pub struct ConversationView {
232 232 new_post_open: bool,
233 233 reply_composer: Option<Entity<Composer>>,
234 234 reply_root: Option<String>,
235 reply_drafts: HashMap<String, Outgoing>,
235 236 feed_stash: Option<FeedStash>,
236 237 feed_rows_seen: Rc<Cell<usize>>,
237 238 feed_at_top: bool,
@@ -409,7 +410,11 @@ impl ConversationView {
409 410 return;
410 411 };
411 412 let now = Local::now();
412 let items = collect_gallery(&self.rows.borrow(), now.date_naive(), now.offset().fix());
413 let items = collect_gallery(
414 &self.rows.borrow(),
415 now.date_naive(),
416 app_base::format::Zone::Local,
417 );
413 418 let Some(index) = position_of(&items, message_key, url) else {
414 419 return;
415 420 };
@@ -587,6 +592,7 @@ impl ConversationView {
587 592 new_post_open: false,
588 593 reply_composer: None,
589 594 reply_root: None,
595 reply_drafts: HashMap::new(),
590 596 feed_stash: None,
591 597 feed_rows_seen: Rc::new(Cell::new(usize::MAX)),
592 598 feed_at_top: true,
@@ -1479,6 +1485,9 @@ impl ConversationView {
1479 1485 return;
1480 1486 }
1481 1487 self.composer.update(cx, |composer, cx| {
1488 if composer.is_editing() {
1489 composer.cancel_edit(window, cx);
1490 }
1482 1491 composer.set_reply(Some(preview), cx);
1483 1492 composer.focus(window, cx);
1484 1493 });
@@ -1524,7 +1533,7 @@ impl ConversationView {
1524 1533 })
1525 1534 .unwrap_or_default();
1526 1535 RowContext {
1527 offset: now.offset().fix(),
1536 offset: app_base::format::Zone::Local,
1528 1537 today: now.date_naive(),
1529 1538 my_user_id: app.store.meta(META_USER_ID).ok().flatten(),
1530 1539 names,
@@ -3272,11 +3281,12 @@ impl ConversationView {
3272 3281 cx.notify();
3273 3282 } else if failed {
3274 3283 this.show_main_composer(cx);
3275 if this.composer.read(cx).is_empty(cx) {
3284 if !this.composer.read(cx).is_editing() {
3276 3285 this.notice =
3277 3286 Some("Edit failed: your text is back in the composer".to_owned());
3278 this.composer
3279 .update(cx, |composer, cx| composer.restore(&outgoing, window, cx));
3287 this.composer.update(cx, |composer, cx| {
3288 composer.begin_edit(outgoing.clone(), window, cx)
3289 });
3280 3290 } else {
3281 3291 this.notice = Some("Edit failed".to_owned());
3282 3292 }
@@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
4use std::rc::Rc;
4use std::rc::Rc;
5use std::time::{Duration, Instant};
5use std::time::{Duration, Instant};
6
6
7use chrono::{DateTime, Local, Offset, Utc};
7use chrono::{DateTime, Local, Utc};
8use gpui_kit::assets::IconName;
8use gpui_kit::assets::IconName;
9use gpui_kit::component::{
9use gpui_kit::component::{
10 button::{Button, ButtonVariants as _},
10 button::{Button, ButtonVariants as _},
@@ -232,6 +232,7 @@ pub struct ConversationView {
232 new_post_open: bool,
232 new_post_open: bool,
233 reply_composer: Option<Entity<Composer>>,
233 reply_composer: Option<Entity<Composer>>,
234 reply_root: Option<String>,
234 reply_root: Option<String>,
235 reply_drafts: HashMap<String, Outgoing>,
235 feed_stash: Option<FeedStash>,
236 feed_stash: Option<FeedStash>,
236 feed_rows_seen: Rc<Cell<usize>>,
237 feed_rows_seen: Rc<Cell<usize>>,
237 feed_at_top: bool,
238 feed_at_top: bool,
@@ -409,7 +410,11 @@ impl ConversationView {
409 return;
410 return;
410 };
411 };
411 let now = Local::now();
412 let now = Local::now();
412 let items = collect_gallery(&self.rows.borrow(), now.date_naive(), now.offset().fix());
413 let items = collect_gallery(
414 &self.rows.borrow(),
415 now.date_naive(),
416 app_base::format::Zone::Local,
417 );
413 let Some(index) = position_of(&items, message_key, url) else {
418 let Some(index) = position_of(&items, message_key, url) else {
414 return;
419 return;
415 };
420 };
@@ -587,6 +592,7 @@ impl ConversationView {
587 new_post_open: false,
592 new_post_open: false,
588 reply_composer: None,
593 reply_composer: None,
589 reply_root: None,
594 reply_root: None,
595 reply_drafts: HashMap::new(),
590 feed_stash: None,
596 feed_stash: None,
591 feed_rows_seen: Rc::new(Cell::new(usize::MAX)),
597 feed_rows_seen: Rc::new(Cell::new(usize::MAX)),
592 feed_at_top: true,
598 feed_at_top: true,
@@ -1479,6 +1485,9 @@ impl ConversationView {
1479 return;
1485 return;
1480 }
1486 }
1481 self.composer.update(cx, |composer, cx| {
1487 self.composer.update(cx, |composer, cx| {
1488 if composer.is_editing() {
1489 composer.cancel_edit(window, cx);
1490 }
1482 composer.set_reply(Some(preview), cx);
1491 composer.set_reply(Some(preview), cx);
1483 composer.focus(window, cx);
1492 composer.focus(window, cx);
1484 });
1493 });
@@ -1524,7 +1533,7 @@ impl ConversationView {
1524 })
1533 })
1525 .unwrap_or_default();
1534 .unwrap_or_default();
1526 RowContext {
1535 RowContext {
1527 offset: now.offset().fix(),
1536 offset: app_base::format::Zone::Local,
1528 today: now.date_naive(),
1537 today: now.date_naive(),
1529 my_user_id: app.store.meta(META_USER_ID).ok().flatten(),
1538 my_user_id: app.store.meta(META_USER_ID).ok().flatten(),
1530 names,
1539 names,
@@ -3272,11 +3281,12 @@ impl ConversationView {
3272 cx.notify();
3281 cx.notify();
3273 } else if failed {
3282 } else if failed {
3274 this.show_main_composer(cx);
3283 this.show_main_composer(cx);
3275 if this.composer.read(cx).is_empty(cx) {
3284 if !this.composer.read(cx).is_editing() {
3276 this.notice =
3285 this.notice =
3277 Some("Edit failed: your text is back in the composer".to_owned());
3286 Some("Edit failed: your text is back in the composer".to_owned());
3278 this.composer
3287 this.composer.update(cx, |composer, cx| {
3279 .update(cx, |composer, cx| composer.restore(&outgoing, window, cx));
3288 composer.begin_edit(outgoing.clone(), window, cx)
3289 });
3280 } else {
3290 } else {
3281 this.notice = Some("Edit failed".to_owned());
3291 this.notice = Some("Edit failed".to_owned());
3282 }
3292 }
crates/app/src/views/conversation/channel_details.rs +2 −3
@@ -61,9 +61,8 @@ pub(super) fn pinned_post_item(message_id: &str, record: Option<&MessageRecord>)
61 61 byline: String::new(),
62 62 };
63 63 };
64 let offset = Local::now().offset().fix();
65 let today = Utc::now().with_timezone(&offset).date_naive();
66 let date = format::list_time_label(record.created_at, today, offset);
64 let today = Local::now().date_naive();
65 let date = format::list_time_label(record.created_at, today, app_base::format::Zone::Local);
67 66 let author = record.sender_name.clone().unwrap_or_default();
68 67 let byline = match (author.is_empty(), date.is_empty()) {
69 68 (false, false) => format!("{author}, {date}"),
@@ -61,9 +61,8 @@ pub(super) fn pinned_post_item(message_id: &str, record: Option<&MessageRecord>)
61 byline: String::new(),
61 byline: String::new(),
62 };
62 };
63 };
63 };
64 let offset = Local::now().offset().fix();
64 let today = Local::now().date_naive();
65 let today = Utc::now().with_timezone(&offset).date_naive();
65 let date = format::list_time_label(record.created_at, today, app_base::format::Zone::Local);
66 let date = format::list_time_label(record.created_at, today, offset);
67 let author = record.sender_name.clone().unwrap_or_default();
66 let author = record.sender_name.clone().unwrap_or_default();
68 let byline = match (author.is_empty(), date.is_empty()) {
67 let byline = match (author.is_empty(), date.is_empty()) {
69 (false, false) => format!("{author}, {date}"),
68 (false, false) => format!("{author}, {date}"),
crates/app/src/views/conversation/feed.rs +23 −3
@@ -203,18 +203,38 @@ impl ConversationView {
203 203 let composer = self.reply_composer(window, cx);
204 204 let previous = self.reply_root.replace(root_id.clone());
205 205 let changed = previous.as_deref() != Some(root_id.as_str());
206 if changed && let Some(previous) = &previous {
207 self.keep_reply_draft(previous, cx);
208 }
209 let kept = self.reply_drafts.remove(&root_id).filter(|_| changed);
206 210 composer.update(cx, |composer, cx| {
207 if changed {
208 composer.set_text("", window, cx);
211 match &kept {
212 Some(outgoing) => composer.restore(outgoing, window, cx),
213 None if changed => composer.set_text("", window, cx),
214 None => {}
215 }
216 if quote.is_some() || kept.is_none() {
217 composer.set_reply(quote, cx);
209 218 }
210 composer.set_reply(quote, cx);
211 219 composer.focus(window, cx);
212 220 });
213 221 self.remeasure_posts(&[Some(root_id), previous], cx);
214 222 }
215 223
224 fn keep_reply_draft(&mut self, root_id: &str, cx: &mut Context<Self>) {
225 let unsent = self
226 .reply_composer
227 .as_ref()
228 .and_then(|composer| composer.read(cx).unsent(cx));
229 match unsent {
230 Some(outgoing) => self.reply_drafts.insert(root_id.to_owned(), outgoing),
231 None => self.reply_drafts.remove(root_id),
232 };
233 }
234
216 235 pub(super) fn close_reply_editor(&mut self, cx: &mut Context<Self>) {
217 236 if let Some(root_id) = self.reply_root.take() {
237 self.keep_reply_draft(&root_id, cx);
218 238 self.remeasure_posts(&[Some(root_id)], cx);
219 239 }
220 240 }
@@ -203,18 +203,38 @@ impl ConversationView {
203 let composer = self.reply_composer(window, cx);
203 let composer = self.reply_composer(window, cx);
204 let previous = self.reply_root.replace(root_id.clone());
204 let previous = self.reply_root.replace(root_id.clone());
205 let changed = previous.as_deref() != Some(root_id.as_str());
205 let changed = previous.as_deref() != Some(root_id.as_str());
206 if changed && let Some(previous) = &previous {
207 self.keep_reply_draft(previous, cx);
208 }
209 let kept = self.reply_drafts.remove(&root_id).filter(|_| changed);
206 composer.update(cx, |composer, cx| {
210 composer.update(cx, |composer, cx| {
207 if changed {
211 match &kept {
208 composer.set_text("", window, cx);
212 Some(outgoing) => composer.restore(outgoing, window, cx),
213 None if changed => composer.set_text("", window, cx),
214 None => {}
215 }
216 if quote.is_some() || kept.is_none() {
217 composer.set_reply(quote, cx);
209 }
218 }
210 composer.set_reply(quote, cx);
211 composer.focus(window, cx);
219 composer.focus(window, cx);
212 });
220 });
213 self.remeasure_posts(&[Some(root_id), previous], cx);
221 self.remeasure_posts(&[Some(root_id), previous], cx);
214 }
222 }
215
223
224 fn keep_reply_draft(&mut self, root_id: &str, cx: &mut Context<Self>) {
225 let unsent = self
226 .reply_composer
227 .as_ref()
228 .and_then(|composer| composer.read(cx).unsent(cx));
229 match unsent {
230 Some(outgoing) => self.reply_drafts.insert(root_id.to_owned(), outgoing),
231 None => self.reply_drafts.remove(root_id),
232 };
233 }
234
216 pub(super) fn close_reply_editor(&mut self, cx: &mut Context<Self>) {
235 pub(super) fn close_reply_editor(&mut self, cx: &mut Context<Self>) {
217 if let Some(root_id) = self.reply_root.take() {
236 if let Some(root_id) = self.reply_root.take() {
237 self.keep_reply_draft(&root_id, cx);
218 self.remeasure_posts(&[Some(root_id)], cx);
238 self.remeasure_posts(&[Some(root_id)], cx);
219 }
239 }
220 }
240 }
crates/app/src/views/conversation/scheduled.rs +12 −0
@@ -17,6 +17,9 @@ use crate::scheduled_rows::{
17 17 draft_id_of, draft_key, scheduled_feed_rows, scheduled_outgoing, scheduled_rows,
18 18 };
19 19 use crate::views::composer::{EditPreview, Outgoing};
20
21 const SCHEDULED_EDIT_LOST_NOTICE: &str =
22 "This scheduled message can no longer be changed: your text is back in the composer";
20 23 use crate::views::message_actions::Action;
21 24 use crate::views::message_row::{DeliveryActions, RowAction};
22 25 use crate::views::scheduled_toolbar::ScheduledMenu;
@@ -237,6 +240,15 @@ impl ConversationView {
237 240 let Some(edit) = outgoing.edit.as_ref() else {
238 241 return;
239 242 };
243 let changeable = self
244 .scheduled_draft(&edit.message_id, cx)
245 .is_some_and(|draft| {
246 !draft.id.is_empty() && !self.scheduled_in_flight.contains(&draft.id)
247 });
248 if !changeable {
249 self.restore_unsent(SCHEDULED_EDIT_LOST_NOTICE, &outgoing, None, window, cx);
250 return;
251 }
240 252 self.change_scheduled(
241 253 &edit.message_id.clone(),
242 254 ScheduledAction::Update(outgoing.html()),
@@ -17,6 +17,9 @@ use crate::scheduled_rows::{
17 draft_id_of, draft_key, scheduled_feed_rows, scheduled_outgoing, scheduled_rows,
17 draft_id_of, draft_key, scheduled_feed_rows, scheduled_outgoing, scheduled_rows,
18};
18};
19use crate::views::composer::{EditPreview, Outgoing};
19use crate::views::composer::{EditPreview, Outgoing};
20
21const SCHEDULED_EDIT_LOST_NOTICE: &str =
22 "This scheduled message can no longer be changed: your text is back in the composer";
20use crate::views::message_actions::Action;
23use crate::views::message_actions::Action;
21use crate::views::message_row::{DeliveryActions, RowAction};
24use crate::views::message_row::{DeliveryActions, RowAction};
22use crate::views::scheduled_toolbar::ScheduledMenu;
25use crate::views::scheduled_toolbar::ScheduledMenu;
@@ -237,6 +240,15 @@ impl ConversationView {
237 let Some(edit) = outgoing.edit.as_ref() else {
240 let Some(edit) = outgoing.edit.as_ref() else {
238 return;
241 return;
239 };
242 };
243 let changeable = self
244 .scheduled_draft(&edit.message_id, cx)
245 .is_some_and(|draft| {
246 !draft.id.is_empty() && !self.scheduled_in_flight.contains(&draft.id)
247 });
248 if !changeable {
249 self.restore_unsent(SCHEDULED_EDIT_LOST_NOTICE, &outgoing, None, window, cx);
250 return;
251 }
240 self.change_scheduled(
252 self.change_scheduled(
241 &edit.message_id.clone(),
253 &edit.message_id.clone(),
242 ScheduledAction::Update(outgoing.html()),
254 ScheduledAction::Update(outgoing.html()),
crates/app/src/views/find_panel.rs +13 −5
@@ -1,6 +1,6 @@
1 1 use std::time::Duration;
2 2
3 use chrono::{Local, NaiveDate, Offset};
3 use chrono::{Local, NaiveDate};
4 4 use gpui_kit::assets::IconName;
5 5 use gpui_kit::component::button::{Button, ButtonVariants as _};
6 6 use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};
@@ -240,7 +240,16 @@ impl FindPanel {
240 240 .filter_map(from_server)
241 241 .filter(|hit| self.filters.admits(hit, today, offset))
242 242 .collect();
243 let current = self
244 .current_index
245 .and_then(|index| self.hits.get(index))
246 .map(|hit| hit.message_id.clone());
243 247 self.hits = merge(self.local_hits.clone(), server);
248 self.current_index = current.and_then(|message_id| {
249 self.hits
250 .iter()
251 .position(|hit| hit.message_id == message_id)
252 });
244 253 self.status = Status::Ready;
245 254 cx.notify();
246 255 }
@@ -468,7 +477,7 @@ impl FindPanel {
468 477 hit: &FindHit,
469 478 index: usize,
470 479 today: NaiveDate,
471 offset: chrono::FixedOffset,
480 offset: app_base::format::Zone,
472 481 cx: &mut Context<Self>,
473 482 ) -> impl IntoElement {
474 483 let current = self.current_index == Some(index);
@@ -586,9 +595,8 @@ fn panel_title(selection: &Selection) -> &'static str {
586 595 }
587 596 }
588 597
589 fn today_and_offset() -> (NaiveDate, chrono::FixedOffset) {
590 let now = Local::now();
591 (now.date_naive(), now.offset().fix())
598 fn today_and_offset() -> (NaiveDate, app_base::format::Zone) {
599 (Local::now().date_naive(), app_base::format::Zone::Local)
592 600 }
593 601
594 602 fn local_hits(
@@ -1,6 +1,6 @@
1use std::time::Duration;
1use std::time::Duration;
2
2
3use chrono::{Local, NaiveDate, Offset};
3use chrono::{Local, NaiveDate};
4use gpui_kit::assets::IconName;
4use gpui_kit::assets::IconName;
5use gpui_kit::component::button::{Button, ButtonVariants as _};
5use gpui_kit::component::button::{Button, ButtonVariants as _};
6use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};
6use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};
@@ -240,7 +240,16 @@ impl FindPanel {
240 .filter_map(from_server)
240 .filter_map(from_server)
241 .filter(|hit| self.filters.admits(hit, today, offset))
241 .filter(|hit| self.filters.admits(hit, today, offset))
242 .collect();
242 .collect();
243 let current = self
244 .current_index
245 .and_then(|index| self.hits.get(index))
246 .map(|hit| hit.message_id.clone());
243 self.hits = merge(self.local_hits.clone(), server);
247 self.hits = merge(self.local_hits.clone(), server);
248 self.current_index = current.and_then(|message_id| {
249 self.hits
250 .iter()
251 .position(|hit| hit.message_id == message_id)
252 });
244 self.status = Status::Ready;
253 self.status = Status::Ready;
245 cx.notify();
254 cx.notify();
246 }
255 }
@@ -468,7 +477,7 @@ impl FindPanel {
468 hit: &FindHit,
477 hit: &FindHit,
469 index: usize,
478 index: usize,
470 today: NaiveDate,
479 today: NaiveDate,
471 offset: chrono::FixedOffset,
480 offset: app_base::format::Zone,
472 cx: &mut Context<Self>,
481 cx: &mut Context<Self>,
473 ) -> impl IntoElement {
482 ) -> impl IntoElement {
474 let current = self.current_index == Some(index);
483 let current = self.current_index == Some(index);
@@ -586,9 +595,8 @@ fn panel_title(selection: &Selection) -> &'static str {
586 }
595 }
587}
596}
588
597
589fn today_and_offset() -> (NaiveDate, chrono::FixedOffset) {
598fn today_and_offset() -> (NaiveDate, app_base::format::Zone) {
590 let now = Local::now();
599 (Local::now().date_naive(), app_base::format::Zone::Local)
591 (now.date_naive(), now.offset().fix())
592}
600}
593
601
594fn local_hits(
602fn local_hits(
crates/app/src/views/shared_tab.rs +1 −1
@@ -257,7 +257,7 @@ pub(crate) fn entry_badge(entry: &DriveEntry) -> Div {
257 257 pub(crate) fn modified_text(entry: &DriveEntry) -> String {
258 258 entry.modified_at.map_or_else(String::new, |time| {
259 259 let now = Local::now();
260 format::list_time_label(time, now.date_naive(), now.offset().fix())
260 format::list_time_label(time, now.date_naive(), app_base::format::Zone::Local)
261 261 })
262 262 }
263 263
@@ -257,7 +257,7 @@ pub(crate) fn entry_badge(entry: &DriveEntry) -> Div {
257pub(crate) fn modified_text(entry: &DriveEntry) -> String {
257pub(crate) fn modified_text(entry: &DriveEntry) -> String {
258 entry.modified_at.map_or_else(String::new, |time| {
258 entry.modified_at.map_or_else(String::new, |time| {
259 let now = Local::now();
259 let now = Local::now();
260 format::list_time_label(time, now.date_naive(), now.offset().fix())
260 format::list_time_label(time, now.date_naive(), app_base::format::Zone::Local)
261 })
261 })
262}
262}
263
263
crates/app/src/views/sidebar.rs +5 −2
@@ -2097,11 +2097,14 @@ fn is_private_channel(channel: &ChannelRecord) -> bool {
2097 2097 }
2098 2098
2099 2099 fn channel_activity(channel: &ChannelRecord) -> String {
2100 let offset = Local::now().offset().fix();
2101 2100 channel
2102 2101 .last_message_at
2103 2102 .map(|time| {
2104 format::channel_time_label(time, Utc::now().with_timezone(&offset).date_naive(), offset)
2103 format::channel_time_label(
2104 time,
2105 Local::now().date_naive(),
2106 app_base::format::Zone::Local,
2107 )
2105 2108 })
2106 2109 .unwrap_or_default()
2107 2110 }
@@ -2097,11 +2097,14 @@ fn is_private_channel(channel: &ChannelRecord) -> bool {
2097}
2097}
2098
2098
2099fn channel_activity(channel: &ChannelRecord) -> String {
2099fn channel_activity(channel: &ChannelRecord) -> String {
2100 let offset = Local::now().offset().fix();
2101 channel
2100 channel
2102 .last_message_at
2101 .last_message_at
2103 .map(|time| {
2102 .map(|time| {
2104 format::channel_time_label(time, Utc::now().with_timezone(&offset).date_naive(), offset)
2103 format::channel_time_label(
2104 time,
2105 Local::now().date_naive(),
2106 app_base::format::Zone::Local,
2107 )
2105 })
2108 })
2106 .unwrap_or_default()
2109 .unwrap_or_default()
2107}
2110}
crates/chatsvc/src/chat_listing.rs +3 −0
@@ -19,6 +19,7 @@ pub struct ConversationPage {
19 19 pub struct MessagePage {
20 20 pub messages: Vec<Value>,
21 21 pub has_older: bool,
22 pub oldest_arrival_ms: Option<i64>,
22 23 }
23 24
24 25 /// One chat with its members and meeting details, from the chat service aggregator.
@@ -135,9 +136,11 @@ impl<T: MessageTransport> ChatListing<T> {
135 136 .and_then(Value::as_str)
136 137 .is_some_and(|link| !link.is_empty())
137 138 && !messages.is_empty();
139 let oldest_arrival_ms = messages.iter().filter_map(arrival_ms).min();
138 140 Ok(MessagePage {
139 141 messages,
140 142 has_older,
143 oldest_arrival_ms,
141 144 })
142 145 }
143 146
@@ -19,6 +19,7 @@ pub struct ConversationPage {
19pub struct MessagePage {
19pub struct MessagePage {
20 pub messages: Vec<Value>,
20 pub messages: Vec<Value>,
21 pub has_older: bool,
21 pub has_older: bool,
22 pub oldest_arrival_ms: Option<i64>,
22}
23}
23
24
24/// One chat with its members and meeting details, from the chat service aggregator.
25/// One chat with its members and meeting details, from the chat service aggregator.
@@ -135,9 +136,11 @@ impl<T: MessageTransport> ChatListing<T> {
135 .and_then(Value::as_str)
136 .and_then(Value::as_str)
136 .is_some_and(|link| !link.is_empty())
137 .is_some_and(|link| !link.is_empty())
137 && !messages.is_empty();
138 && !messages.is_empty();
139 let oldest_arrival_ms = messages.iter().filter_map(arrival_ms).min();
138 Ok(MessagePage {
140 Ok(MessagePage {
139 messages,
141 messages,
140 has_older,
142 has_older,
143 oldest_arrival_ms,
141 })
144 })
142 }
145 }
143
146
crates/core/src/engine.rs +1 −0
@@ -660,6 +660,7 @@ fn oldest_created(page: &RemotePage) -> Option<DateTime<Utc>> {
660 660 page.items
661 661 .iter()
662 662 .filter_map(|message| message.created_date_time)
663 .chain(page.oldest_at)
663 664 .min()
664 665 }
665 666
@@ -660,6 +660,7 @@ fn oldest_created(page: &RemotePage) -> Option<DateTime<Utc>> {
660 page.items
660 page.items
661 .iter()
661 .iter()
662 .filter_map(|message| message.created_date_time)
662 .filter_map(|message| message.created_date_time)
663 .chain(page.oldest_at)
663 .min()
664 .min()
664}
665}
665
666
crates/core/src/native/source.rs +3 −0
@@ -164,6 +164,9 @@ impl<'a> NativeChats<'a> {
164 164 .filter_map(|message| graph_message(chat_id, message))
165 165 .collect(),
166 166 next_link: page.has_older.then(|| OLDER_PAGE_MARKER.to_owned()),
167 oldest_at: page
168 .oldest_arrival_ms
169 .and_then(DateTime::from_timestamp_millis),
167 170 })
168 171 }
169 172
@@ -164,6 +164,9 @@ impl<'a> NativeChats<'a> {
164 .filter_map(|message| graph_message(chat_id, message))
164 .filter_map(|message| graph_message(chat_id, message))
165 .collect(),
165 .collect(),
166 next_link: page.has_older.then(|| OLDER_PAGE_MARKER.to_owned()),
166 next_link: page.has_older.then(|| OLDER_PAGE_MARKER.to_owned()),
167 oldest_at: page
168 .oldest_arrival_ms
169 .and_then(DateTime::from_timestamp_millis),
167 })
170 })
168 }
171 }
169
172
crates/core/src/remote.rs +3 −4
@@ -39,6 +39,7 @@ const URGENT_ACK_EMOTION: &str = "acks";
39 39 pub struct RemotePage {
40 40 pub items: Vec<Message>,
41 41 pub next_link: Option<String>,
42 pub oldest_at: Option<DateTime<Utc>>,
42 43 }
43 44
44 45 #[derive(Debug, Clone)]
@@ -990,10 +991,7 @@ impl Remote for Graph {
990 991 )
991 992 .await?)
992 993 }
993 Some(_) => Err(Error::Unsupported(
994 "editing a channel message with mentions",
995 )),
996 None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
994 Some(_) | None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
997 995 }
998 996 }
999 997
@@ -1667,6 +1665,7 @@ impl From<graph::Page<Message>> for RemotePage {
1667 1665 RemotePage {
1668 1666 items: page.items,
1669 1667 next_link: page.next_link,
1668 oldest_at: None,
1670 1669 }
1671 1670 }
1672 1671 }
@@ -39,6 +39,7 @@ const URGENT_ACK_EMOTION: &str = "acks";
39pub struct RemotePage {
39pub struct RemotePage {
40 pub items: Vec<Message>,
40 pub items: Vec<Message>,
41 pub next_link: Option<String>,
41 pub next_link: Option<String>,
42 pub oldest_at: Option<DateTime<Utc>>,
42}
43}
43
44
44#[derive(Debug, Clone)]
45#[derive(Debug, Clone)]
@@ -990,10 +991,7 @@ impl Remote for Graph {
990 )
991 )
991 .await?)
992 .await?)
992 }
993 }
993 Some(_) => Err(Error::Unsupported(
994 Some(_) | None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
994 "editing a channel message with mentions",
995 )),
996 None => Ok(Graph::edit_message(self, target, html, mentions, extras).await?),
997 }
995 }
998 }
996 }
999
997
@@ -1667,6 +1665,7 @@ impl From<graph::Page<Message>> for RemotePage {
1667 RemotePage {
1665 RemotePage {
1668 items: page.items,
1666 items: page.items,
1669 next_link: page.next_link,
1667 next_link: page.next_link,
1668 oldest_at: None,
1670 }
1669 }
1671 }
1670 }
1672}
1671}
crates/core/src/teams_quote.rs +19 −7
@@ -73,14 +73,16 @@ pub(crate) fn mention_entries(mentions: &[OutgoingMention]) -> Option<Vec<Value>
73 73 }
74 74
75 75 fn mention_entry(mention: &OutgoingMention) -> Option<Value> {
76 let MentionTarget::User { user_id } = &mention.target else {
77 return None;
76 let (mri, mention_type) = match &mention.target {
77 MentionTarget::User { user_id } => (user_mri(user_id), "person"),
78 MentionTarget::Everyone { chat_id } => (chat_id.clone(), "everyone"),
79 _ => return None,
78 80 };
79 81 Some(json!({
80 82 "@type": MENTION_ITEMTYPE,
81 83 "itemid": mention.id.to_string(),
82 "mri": user_mri(user_id),
83 "mentionType": "person",
84 "mri": mri,
85 "mentionType": mention_type,
84 86 "displayName": mention.text,
85 87 }))
86 88 }
@@ -185,6 +187,19 @@ mod tests {
185 187 );
186 188 }
187 189
190 #[test]
191 fn an_everyone_mention_names_the_chat_itself() {
192 let everyone = mention(
193 0,
194 MentionTarget::Everyone {
195 chat_id: "19:g@thread.v2".into(),
196 },
197 );
198 let entries = mention_entries(&[everyone]).unwrap();
199 assert_eq!(entries[0]["mri"], "19:g@thread.v2");
200 assert_eq!(entries[0]["mentionType"], "everyone");
201 }
202
188 203 #[test]
189 204 fn group_mentions_have_no_chatsvc_shape() {
190 205 for target in [
@@ -194,9 +209,6 @@ mod tests {
194 209 MentionTarget::Team {
195 210 team_id: "team-1".into(),
196 211 },
197 MentionTarget::Everyone {
198 chat_id: "19:g@thread.v2".into(),
199 },
200 212 MentionTarget::Tag {
201 213 tag_id: "tag-1".into(),
202 214 },
@@ -73,14 +73,16 @@ pub(crate) fn mention_entries(mentions: &[OutgoingMention]) -> Option<Vec<Value>
73}
73}
74
74
75fn mention_entry(mention: &OutgoingMention) -> Option<Value> {
75fn mention_entry(mention: &OutgoingMention) -> Option<Value> {
76 let MentionTarget::User { user_id } = &mention.target else {
76 let (mri, mention_type) = match &mention.target {
77 return None;
77 MentionTarget::User { user_id } => (user_mri(user_id), "person"),
78 MentionTarget::Everyone { chat_id } => (chat_id.clone(), "everyone"),
79 _ => return None,
78 };
80 };
79 Some(json!({
81 Some(json!({
80 "@type": MENTION_ITEMTYPE,
82 "@type": MENTION_ITEMTYPE,
81 "itemid": mention.id.to_string(),
83 "itemid": mention.id.to_string(),
82 "mri": user_mri(user_id),
84 "mri": mri,
83 "mentionType": "person",
85 "mentionType": mention_type,
84 "displayName": mention.text,
86 "displayName": mention.text,
85 }))
87 }))
86}
88}
@@ -185,6 +187,19 @@ mod tests {
185 );
187 );
186 }
188 }
187
189
190 #[test]
191 fn an_everyone_mention_names_the_chat_itself() {
192 let everyone = mention(
193 0,
194 MentionTarget::Everyone {
195 chat_id: "19:g@thread.v2".into(),
196 },
197 );
198 let entries = mention_entries(&[everyone]).unwrap();
199 assert_eq!(entries[0]["mri"], "19:g@thread.v2");
200 assert_eq!(entries[0]["mentionType"], "everyone");
201 }
202
188 #[test]
203 #[test]
189 fn group_mentions_have_no_chatsvc_shape() {
204 fn group_mentions_have_no_chatsvc_shape() {
190 for target in [
205 for target in [
@@ -194,9 +209,6 @@ mod tests {
194 MentionTarget::Team {
209 MentionTarget::Team {
195 team_id: "team-1".into(),
210 team_id: "team-1".into(),
196 },
211 },
197 MentionTarget::Everyone {
198 chat_id: "19:g@thread.v2".into(),
199 },
200 MentionTarget::Tag {
212 MentionTarget::Tag {
201 tag_id: "tag-1".into(),
213 tag_id: "tag-1".into(),
202 },
214 },
crates/core/tests/engine.rs +5 −1
@@ -148,7 +148,11 @@ impl Fake {
148 148 }
149 149
150 150 fn page_of(items: Vec<Message>, next_link: Option<String>) -> Result<RemotePage> {
151 Ok(RemotePage { items, next_link })
151 Ok(RemotePage {
152 items,
153 next_link,
154 oldest_at: None,
155 })
152 156 }
153 157
154 158 struct Handle(Arc<Fake>);
@@ -148,7 +148,11 @@ impl Fake {
148}
148}
149
149
150fn page_of(items: Vec<Message>, next_link: Option<String>) -> Result<RemotePage> {
150fn page_of(items: Vec<Message>, next_link: Option<String>) -> Result<RemotePage> {
151 Ok(RemotePage { items, next_link })
151 Ok(RemotePage {
152 items,
153 next_link,
154 oldest_at: None,
155 })
152}
156}
153
157
154struct Handle(Arc<Fake>);
158struct Handle(Arc<Fake>);