fix(chat): a meeting chat you just joined loads and sends right away
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -15,6 +15,9 @@ async fn main() {
15
15
.with_folder_source(Arc::new(ChatsvcFolderSource::new(&session)));
16
16
match engine.refresh_folders().await {
17
17
Ok(()) => println!("# refresh folders ok"),
18
Err(error) => println!("# refresh folders failed: {}", error.to_string().chars().take(200).collect::<String>()),
18
Err(error) => println!(
19
"# refresh folders failed: {}",
20
error.to_string().chars().take(200).collect::<String>()
21
),
19
22
}
20
23
}
@@ -15,6 +15,9 @@ async fn main() {15
.with_folder_source(Arc::new(ChatsvcFolderSource::new(&session)));15
.with_folder_source(Arc::new(ChatsvcFolderSource::new(&session)));16
match engine.refresh_folders().await {16
match engine.refresh_folders().await {17
Ok(()) => println!("# refresh folders ok"),17
Ok(()) => println!("# refresh folders ok"),18
Err(error) => println!("# refresh folders failed: {}", error.to_string().chars().take(200).collect::<String>()),18
Err(error) => println!(19
"# refresh folders failed: {}",20
error.to_string().chars().take(200).collect::<String>()21
),19
}22
}20
}23
}@@ -52,7 +52,7 @@ impl<R: Remote> SyncEngine<R> {
52
52
mentions: &[MentionInput],
53
53
extras: &MessageExtras,
54
54
) -> Result<MessageRecord> {
55
let conversation = self.resolve(conversation_id)?;
55
let conversation = self.resolve(conversation_id).await?;
56
56
let (html, mentions) = outgoing(&conversation, html, mentions)?;
57
57
let sent = match (conversation, thread_root_id) {
58
58
(Conversation::Chat, None) => {
@@ -120,7 +120,7 @@ impl<R: Remote> SyncEngine<R> {
120
120
mentions: &[MentionInput],
121
121
extras: &MessageExtras,
122
122
) -> Result<MessageRecord> {
123
let conversation = self.resolve(conversation_id)?;
123
let conversation = self.resolve(conversation_id).await?;
124
124
let (html, mentions) = outgoing(&conversation, html, mentions)?;
125
125
let sent = match conversation {
126
126
Conversation::Chat => {
@@ -204,7 +204,7 @@ impl<R: Remote> SyncEngine<R> {
204
204
mentions: &[MentionInput],
205
205
extras: &MessageExtras,
206
206
) -> Result<MessageRecord> {
207
let conversation = self.resolve(channel_id)?;
207
let conversation = self.resolve(channel_id).await?;
208
208
let Conversation::Channel { team_id } = &conversation else {
209
209
return Err(Error::Unsupported("posting a root message to a chat"));
210
210
};
@@ -239,7 +239,7 @@ impl<R: Remote> SyncEngine<R> {
239
239
bytes: &[u8],
240
240
progress: impl Fn(u8) + Send + Sync,
241
241
) -> Result<UploadedFile> {
242
let destination = match self.resolve(conversation_id)? {
242
let destination = match self.resolve(conversation_id).await? {
243
243
Conversation::Chat => UploadDestination::ChatFiles,
244
244
Conversation::Channel { team_id } => {
245
245
UploadDestination::Folder(self.channel_folder(&team_id, conversation_id).await?)
@@ -262,7 +262,7 @@ impl<R: Remote> SyncEngine<R> {
262
262
conversation_id: &str,
263
263
uploaded: &UploadedFile,
264
264
) -> Result<()> {
265
if !matches!(self.resolve(conversation_id)?, Conversation::Chat) {
265
if !matches!(self.resolve(conversation_id).await?, Conversation::Chat) {
266
266
return Ok(());
267
267
}
268
268
let other_members = self.other_member_ids(conversation_id).await?;
@@ -314,7 +314,7 @@ impl<R: Remote> SyncEngine<R> {
314
314
conversation_id: &str,
315
315
message_id: &str,
316
316
) -> Result<Option<MessageRecord>> {
317
let fetched = match self.resolve(conversation_id)? {
317
let fetched = match self.resolve(conversation_id).await? {
318
318
Conversation::Chat => self.remote.chat_message(conversation_id, message_id).await,
319
319
Conversation::Channel { team_id } => {
320
320
self.fetch_channel_message(&team_id, conversation_id, message_id)
@@ -357,7 +357,7 @@ impl<R: Remote> SyncEngine<R> {
357
357
}
358
358
359
359
pub async fn mark_read(&self, conversation_id: &str) -> Result<()> {
360
if !matches!(self.resolve(conversation_id)?, Conversation::Chat) {
360
if !matches!(self.resolve(conversation_id).await?, Conversation::Chat) {
361
361
return Err(Error::Unsupported("marking a channel as read"));
362
362
}
363
363
let user_id = self.my_user_id().await?;
@@ -459,7 +459,7 @@ impl<R: Remote> SyncEngine<R> {
459
459
thread_root_id: Option<&str>,
460
460
active: bool,
461
461
) -> Result<()> {
462
let conversation = match (self.resolve(conversation_id)?, thread_root_id) {
462
let conversation = match (self.resolve(conversation_id).await?, thread_root_id) {
463
463
(Conversation::Chat, _) => ConversationRef::chat(conversation_id),
464
464
(Conversation::Channel { .. }, None) => ConversationRef::channel_root(conversation_id),
465
465
(Conversation::Channel { .. }, Some(root_id)) => {
@@ -526,7 +526,7 @@ impl<R: Remote> SyncEngine<R> {
526
526
html: &str,
527
527
mentions: &[MentionInput],
528
528
) -> Result<()> {
529
let conversation = self.resolve(conversation_id)?;
529
let conversation = self.resolve(conversation_id).await?;
530
530
let (mut html, mentions) = outgoing(&conversation, html, mentions)?;
531
531
let target = self.message_target(conversation_id, message_id)?;
532
532
let mut extras = MessageExtras::default();
@@ -556,7 +556,7 @@ impl<R: Remote> SyncEngine<R> {
556
556
}
557
557
558
558
fn message_target(&self, conversation_id: &str, message_id: &str) -> Result<MessageTarget> {
559
Ok(match self.resolve(conversation_id)? {
559
Ok(match self.resolve_stored(conversation_id)? {
560
560
Conversation::Chat => MessageTarget::chat(conversation_id, message_id),
561
561
Conversation::Channel { team_id } => {
562
562
let root_id = self
@@ -52,7 +52,7 @@ impl<R: Remote> SyncEngine<R> {52
mentions: &[MentionInput],52
mentions: &[MentionInput],53
extras: &MessageExtras,53
extras: &MessageExtras,54
) -> Result<MessageRecord> {54
) -> Result<MessageRecord> {55
let conversation = self.resolve(conversation_id)?;55
let conversation = self.resolve(conversation_id).await?;56
let (html, mentions) = outgoing(&conversation, html, mentions)?;56
let (html, mentions) = outgoing(&conversation, html, mentions)?;57
let sent = match (conversation, thread_root_id) {57
let sent = match (conversation, thread_root_id) {58
(Conversation::Chat, None) => {58
(Conversation::Chat, None) => {@@ -120,7 +120,7 @@ impl<R: Remote> SyncEngine<R> {120
mentions: &[MentionInput],120
mentions: &[MentionInput],121
extras: &MessageExtras,121
extras: &MessageExtras,122
) -> Result<MessageRecord> {122
) -> Result<MessageRecord> {123
let conversation = self.resolve(conversation_id)?;123
let conversation = self.resolve(conversation_id).await?;124
let (html, mentions) = outgoing(&conversation, html, mentions)?;124
let (html, mentions) = outgoing(&conversation, html, mentions)?;125
let sent = match conversation {125
let sent = match conversation {126
Conversation::Chat => {126
Conversation::Chat => {@@ -204,7 +204,7 @@ impl<R: Remote> SyncEngine<R> {204
mentions: &[MentionInput],204
mentions: &[MentionInput],205
extras: &MessageExtras,205
extras: &MessageExtras,206
) -> Result<MessageRecord> {206
) -> Result<MessageRecord> {207
let conversation = self.resolve(channel_id)?;207
let conversation = self.resolve(channel_id).await?;208
let Conversation::Channel { team_id } = &conversation else {208
let Conversation::Channel { team_id } = &conversation else {209
return Err(Error::Unsupported("posting a root message to a chat"));209
return Err(Error::Unsupported("posting a root message to a chat"));210
};210
};@@ -239,7 +239,7 @@ impl<R: Remote> SyncEngine<R> {239
bytes: &[u8],239
bytes: &[u8],240
progress: impl Fn(u8) + Send + Sync,240
progress: impl Fn(u8) + Send + Sync,241
) -> Result<UploadedFile> {241
) -> Result<UploadedFile> {242
let destination = match self.resolve(conversation_id)? {242
let destination = match self.resolve(conversation_id).await? {243
Conversation::Chat => UploadDestination::ChatFiles,243
Conversation::Chat => UploadDestination::ChatFiles,244
Conversation::Channel { team_id } => {244
Conversation::Channel { team_id } => {245
UploadDestination::Folder(self.channel_folder(&team_id, conversation_id).await?)245
UploadDestination::Folder(self.channel_folder(&team_id, conversation_id).await?)@@ -262,7 +262,7 @@ impl<R: Remote> SyncEngine<R> {262
conversation_id: &str,262
conversation_id: &str,263
uploaded: &UploadedFile,263
uploaded: &UploadedFile,264
) -> Result<()> {264
) -> Result<()> {265
if !matches!(self.resolve(conversation_id)?, Conversation::Chat) {265
if !matches!(self.resolve(conversation_id).await?, Conversation::Chat) {266
return Ok(());266
return Ok(());267
}267
}268
let other_members = self.other_member_ids(conversation_id).await?;268
let other_members = self.other_member_ids(conversation_id).await?;@@ -314,7 +314,7 @@ impl<R: Remote> SyncEngine<R> {314
conversation_id: &str,314
conversation_id: &str,315
message_id: &str,315
message_id: &str,316
) -> Result<Option<MessageRecord>> {316
) -> Result<Option<MessageRecord>> {317
let fetched = match self.resolve(conversation_id)? {317
let fetched = match self.resolve(conversation_id).await? {318
Conversation::Chat => self.remote.chat_message(conversation_id, message_id).await,318
Conversation::Chat => self.remote.chat_message(conversation_id, message_id).await,319
Conversation::Channel { team_id } => {319
Conversation::Channel { team_id } => {320
self.fetch_channel_message(&team_id, conversation_id, message_id)320
self.fetch_channel_message(&team_id, conversation_id, message_id)@@ -357,7 +357,7 @@ impl<R: Remote> SyncEngine<R> {357
}357
}358
358
359
pub async fn mark_read(&self, conversation_id: &str) -> Result<()> {359
pub async fn mark_read(&self, conversation_id: &str) -> Result<()> {360
if !matches!(self.resolve(conversation_id)?, Conversation::Chat) {360
if !matches!(self.resolve(conversation_id).await?, Conversation::Chat) {361
return Err(Error::Unsupported("marking a channel as read"));361
return Err(Error::Unsupported("marking a channel as read"));362
}362
}363
let user_id = self.my_user_id().await?;363
let user_id = self.my_user_id().await?;@@ -459,7 +459,7 @@ impl<R: Remote> SyncEngine<R> {459
thread_root_id: Option<&str>,459
thread_root_id: Option<&str>,460
active: bool,460
active: bool,461
) -> Result<()> {461
) -> Result<()> {462
let conversation = match (self.resolve(conversation_id)?, thread_root_id) {462
let conversation = match (self.resolve(conversation_id).await?, thread_root_id) {463
(Conversation::Chat, _) => ConversationRef::chat(conversation_id),463
(Conversation::Chat, _) => ConversationRef::chat(conversation_id),464
(Conversation::Channel { .. }, None) => ConversationRef::channel_root(conversation_id),464
(Conversation::Channel { .. }, None) => ConversationRef::channel_root(conversation_id),465
(Conversation::Channel { .. }, Some(root_id)) => {465
(Conversation::Channel { .. }, Some(root_id)) => {@@ -526,7 +526,7 @@ impl<R: Remote> SyncEngine<R> {526
html: &str,526
html: &str,527
mentions: &[MentionInput],527
mentions: &[MentionInput],528
) -> Result<()> {528
) -> Result<()> {529
let conversation = self.resolve(conversation_id)?;529
let conversation = self.resolve(conversation_id).await?;530
let (mut html, mentions) = outgoing(&conversation, html, mentions)?;530
let (mut html, mentions) = outgoing(&conversation, html, mentions)?;531
let target = self.message_target(conversation_id, message_id)?;531
let target = self.message_target(conversation_id, message_id)?;532
let mut extras = MessageExtras::default();532
let mut extras = MessageExtras::default();@@ -556,7 +556,7 @@ impl<R: Remote> SyncEngine<R> {556
}556
}557
557
558
fn message_target(&self, conversation_id: &str, message_id: &str) -> Result<MessageTarget> {558
fn message_target(&self, conversation_id: &str, message_id: &str) -> Result<MessageTarget> {559
Ok(match self.resolve(conversation_id)? {559
Ok(match self.resolve_stored(conversation_id)? {560
Conversation::Chat => MessageTarget::chat(conversation_id, message_id),560
Conversation::Chat => MessageTarget::chat(conversation_id, message_id),561
Conversation::Channel { team_id } => {561
Conversation::Channel { team_id } => {562
let root_id = self562
let root_id = self@@ -2,8 +2,8 @@ use std::collections::HashMap;
2
2
3
3
use serde_json::{Map, Value, json};
4
4
5
use crate::card_date::format_card_dates;
6
5
use crate::card_chart::{CardChart, is_chart_type, parse_chart};
6
use crate::card_date::format_card_dates;
7
7
use crate::card_inputs::{CardInput, RatingDisplay, merge_input_data, parse_input, parse_rating};
8
8
use crate::card_layout::{
9
9
ContainerLayout, HorizontalAlignment, parse_color_hex, parse_horizontal_alignment,
@@ -2,8 +2,8 @@ use std::collections::HashMap;2
2
3
use serde_json::{Map, Value, json};3
use serde_json::{Map, Value, json};4
4
5
use crate::card_date::format_card_dates;6
use crate::card_chart::{CardChart, is_chart_type, parse_chart};5
use crate::card_chart::{CardChart, is_chart_type, parse_chart};6
use crate::card_date::format_card_dates;7
use crate::card_inputs::{CardInput, RatingDisplay, merge_input_data, parse_input, parse_rating};7
use crate::card_inputs::{CardInput, RatingDisplay, merge_input_data, parse_input, parse_rating};8
use crate::card_layout::{8
use crate::card_layout::{9
ContainerLayout, HorizontalAlignment, parse_color_hex, parse_horizontal_alignment,9
ContainerLayout, HorizontalAlignment, parse_color_hex, parse_horizontal_alignment,@@ -13,7 +13,7 @@ use crate::error::{Error, Result};
13
13
use crate::events::CoreEvent;
14
14
use crate::folders::FolderSource;
15
15
use crate::links::{LinkPreview, has_stored_links};
16
use crate::mapping::{flatten_thread, message_record};
16
use crate::mapping::{chat_record, flatten_thread, message_record};
17
17
use crate::people::DirectoryCache;
18
18
use crate::presence::Presence;
19
19
use crate::preview::OwnedPreview;
@@ -192,7 +192,7 @@ impl<R: Remote> SyncEngine<R> {
192
192
}
193
193
194
194
pub async fn fetch_newer(&self, conversation_id: &str) -> Result<Delta> {
195
let mut delta = match self.resolve(conversation_id)? {
195
let mut delta = match self.resolve(conversation_id).await? {
196
196
Conversation::Chat => self.fetch_newer_chat(conversation_id).await?,
197
197
Conversation::Channel { team_id } => {
198
198
self.fetch_newer_channel(&team_id, conversation_id).await?
@@ -205,7 +205,7 @@ impl<R: Remote> SyncEngine<R> {
205
205
}
206
206
207
207
pub async fn refresh_thread(&self, conversation_id: &str, root_id: &str) -> Result<Delta> {
208
let Conversation::Channel { team_id } = self.resolve(conversation_id)? else {
208
let Conversation::Channel { team_id } = self.resolve(conversation_id).await? else {
209
209
return Err(Error::Unsupported("refreshing a thread of a chat"));
210
210
};
211
211
let delta = self
@@ -216,7 +216,7 @@ impl<R: Remote> SyncEngine<R> {
216
216
}
217
217
218
218
pub async fn load_older(&self, conversation_id: &str) -> Result<Vec<MessageRecord>> {
219
let conversation = self.resolve(conversation_id)?;
219
let conversation = self.resolve(conversation_id).await?;
220
220
if self.store.sync_state(conversation_id)?.is_none() {
221
221
self.fetch_newer(conversation_id).await?;
222
222
}
@@ -310,7 +310,32 @@ impl<R: Remote> SyncEngine<R> {
310
310
Ok(tenant.clone())
311
311
}
312
312
313
pub(crate) fn resolve(&self, conversation_id: &str) -> Result<Conversation> {
313
pub(crate) async fn resolve(&self, conversation_id: &str) -> Result<Conversation> {
314
match self.resolve_stored(conversation_id) {
315
Err(Error::UnknownConversation(_)) => self.fetch_unknown_chat(conversation_id).await,
316
resolved => resolved,
317
}
318
}
319
320
async fn fetch_unknown_chat(&self, conversation_id: &str) -> Result<Conversation> {
321
let chat = match self.remote.chat(conversation_id).await {
322
Ok(chat) => chat,
323
Err(Error::Graph(graph::Error::Session(session::Error::Api {
324
status: 403 | 404,
325
..
326
}))) => {
327
return Err(Error::UnknownConversation(conversation_id.to_owned()));
328
}
329
Err(error) => return Err(error),
330
};
331
let my_user_id = self.my_user_id().await?;
332
self.store
333
.upsert_chats(&[chat_record(&chat, &my_user_id)])?;
334
let _ = self.events.send(CoreEvent::SidebarChanged);
335
Ok(Conversation::Chat)
336
}
337
338
pub(crate) fn resolve_stored(&self, conversation_id: &str) -> Result<Conversation> {
314
339
if let Some(channel) = self.store.channel(conversation_id)? {
315
340
return Ok(Conversation::Channel {
316
341
team_id: channel.team_id,
@@ -13,7 +13,7 @@ use crate::error::{Error, Result};13
use crate::events::CoreEvent;13
use crate::events::CoreEvent;14
use crate::folders::FolderSource;14
use crate::folders::FolderSource;15
use crate::links::{LinkPreview, has_stored_links};15
use crate::links::{LinkPreview, has_stored_links};16
use crate::mapping::{flatten_thread, message_record};16
use crate::mapping::{chat_record, flatten_thread, message_record};17
use crate::people::DirectoryCache;17
use crate::people::DirectoryCache;18
use crate::presence::Presence;18
use crate::presence::Presence;19
use crate::preview::OwnedPreview;19
use crate::preview::OwnedPreview;@@ -192,7 +192,7 @@ impl<R: Remote> SyncEngine<R> {192
}192
}193
193
194
pub async fn fetch_newer(&self, conversation_id: &str) -> Result<Delta> {194
pub async fn fetch_newer(&self, conversation_id: &str) -> Result<Delta> {195
let mut delta = match self.resolve(conversation_id)? {195
let mut delta = match self.resolve(conversation_id).await? {196
Conversation::Chat => self.fetch_newer_chat(conversation_id).await?,196
Conversation::Chat => self.fetch_newer_chat(conversation_id).await?,197
Conversation::Channel { team_id } => {197
Conversation::Channel { team_id } => {198
self.fetch_newer_channel(&team_id, conversation_id).await?198
self.fetch_newer_channel(&team_id, conversation_id).await?@@ -205,7 +205,7 @@ impl<R: Remote> SyncEngine<R> {205
}205
}206
206
207
pub async fn refresh_thread(&self, conversation_id: &str, root_id: &str) -> Result<Delta> {207
pub async fn refresh_thread(&self, conversation_id: &str, root_id: &str) -> Result<Delta> {208
let Conversation::Channel { team_id } = self.resolve(conversation_id)? else {208
let Conversation::Channel { team_id } = self.resolve(conversation_id).await? else {209
return Err(Error::Unsupported("refreshing a thread of a chat"));209
return Err(Error::Unsupported("refreshing a thread of a chat"));210
};210
};211
let delta = self211
let delta = self@@ -216,7 +216,7 @@ impl<R: Remote> SyncEngine<R> {216
}216
}217
217
218
pub async fn load_older(&self, conversation_id: &str) -> Result<Vec<MessageRecord>> {218
pub async fn load_older(&self, conversation_id: &str) -> Result<Vec<MessageRecord>> {219
let conversation = self.resolve(conversation_id)?;219
let conversation = self.resolve(conversation_id).await?;220
if self.store.sync_state(conversation_id)?.is_none() {220
if self.store.sync_state(conversation_id)?.is_none() {221
self.fetch_newer(conversation_id).await?;221
self.fetch_newer(conversation_id).await?;222
}222
}@@ -310,7 +310,32 @@ impl<R: Remote> SyncEngine<R> {310
Ok(tenant.clone())310
Ok(tenant.clone())311
}311
}312
312
313
pub(crate) fn resolve(&self, conversation_id: &str) -> Result<Conversation> {313
pub(crate) async fn resolve(&self, conversation_id: &str) -> Result<Conversation> {314
match self.resolve_stored(conversation_id) {315
Err(Error::UnknownConversation(_)) => self.fetch_unknown_chat(conversation_id).await,316
resolved => resolved,317
}318
}319
320
async fn fetch_unknown_chat(&self, conversation_id: &str) -> Result<Conversation> {321
let chat = match self.remote.chat(conversation_id).await {322
Ok(chat) => chat,323
Err(Error::Graph(graph::Error::Session(session::Error::Api {324
status: 403 | 404,325
..326
}))) => {327
return Err(Error::UnknownConversation(conversation_id.to_owned()));328
}329
Err(error) => return Err(error),330
};331
let my_user_id = self.my_user_id().await?;332
self.store333
.upsert_chats(&[chat_record(&chat, &my_user_id)])?;334
let _ = self.events.send(CoreEvent::SidebarChanged);335
Ok(Conversation::Chat)336
}337
338
pub(crate) fn resolve_stored(&self, conversation_id: &str) -> Result<Conversation> {314
if let Some(channel) = self.store.channel(conversation_id)? {339
if let Some(channel) = self.store.channel(conversation_id)? {315
return Ok(Conversation::Channel {340
return Ok(Conversation::Channel {316
team_id: channel.team_id,341
team_id: channel.team_id,@@ -3,11 +3,11 @@ use std::future::Future;
3
3
use std::pin::Pin;
4
4
use std::sync::{Arc, Mutex};
5
5
6
use chatsvc::settings::{parse_chat_sections, parse_teams_order};
6
7
use chatsvc::{
7
8
ChannelNotificationLevel, ChannelNotifications, ChannelSettings, ChatSection,
8
9
ChatSectionSettings, Pins, UserSettings, pins::SessionTransport,
9
10
};
10
use chatsvc::settings::{parse_chat_sections, parse_teams_order};
11
11
use chrono::Utc;
12
12
use serde_json::Value;
13
13
use session::Session;
@@ -3,11 +3,11 @@ use std::future::Future;3
use std::pin::Pin;3
use std::pin::Pin;4
use std::sync::{Arc, Mutex};4
use std::sync::{Arc, Mutex};5
5
6
use chatsvc::settings::{parse_chat_sections, parse_teams_order};6
use chatsvc::{7
use chatsvc::{7
ChannelNotificationLevel, ChannelNotifications, ChannelSettings, ChatSection,8
ChannelNotificationLevel, ChannelNotifications, ChannelSettings, ChatSection,8
ChatSectionSettings, Pins, UserSettings, pins::SessionTransport,9
ChatSectionSettings, Pins, UserSettings, pins::SessionTransport,9
};10
};10
use chatsvc::settings::{parse_chat_sections, parse_teams_order};11
use chrono::Utc;11
use chrono::Utc;12
use serde_json::Value;12
use serde_json::Value;13
use session::Session;13
use session::Session;@@ -28,9 +28,9 @@ mod link_sync;
28
28
mod links;
29
29
mod mapping;
30
30
mod markdown;
31
mod meeting_join;
31
32
mod mentions;
32
33
mod message_actions;
33
mod meeting_join;
34
34
mod message_link;
35
35
mod message_window;
36
36
mod people;
@@ -79,10 +79,17 @@ pub use card_widgets::{
79
79
};
80
80
pub use card_width::{TargetWidth, WidthClass};
81
81
pub use chatsvc::{
82
CallDirection, CallLogEntry, CallOutcome, ChatApp, ForcedAvailability, ForcedKind, ForwardResult, Gif, PinnedMessage, PresenceStatus,
83
SavedMessage, ScheduledDraft, StatusNote, WindowDirection, WorkLocation, WorkLocationKind, WorkLocationSource,
82
CallDirection, CallLogEntry, CallOutcome, ChatApp, ForcedAvailability, ForcedKind,
83
ForwardResult, Gif, PinnedMessage, PresenceStatus, SavedMessage, ScheduledDraft, StatusNote,
84
WindowDirection, WorkLocation, WorkLocationKind, WorkLocationSource,
84
85
};
85
86
pub use chatsvc::{ChatSection, ChatSectionSettings};
87
pub use chatsvc::{
88
Language, LanguageSettings, MessageLanguage, Translation, TranslationBehavior,
89
TranslationStatus, TranslationTrigger, authoring_patch, behavior_patch, language_code,
90
parse_language_settings, target_patch,
91
};
92
pub use download::LibraryFile;
86
93
pub use draft::{
87
94
Draft, DraftLine, Edit, FormatState, LineKind, MAX_DEPTH, Mark, MarkKind, OBJECT_MARK,
88
95
SizeStep, TypingStyle, changed_span, has_markdown, link_url, map_offset, reverse_edits,
@@ -99,20 +106,19 @@ pub use graph::{
99
106
DriveEntry, DriveFolder, FileReference, HostedImage, KeptAttachment, MentionTarget,
100
107
MessageExtras, SharedFile, UploadedFile,
101
108
};
102
pub use download::LibraryFile;
103
109
pub use images::StoredImage;
104
110
pub use links::{LinkPreview, first_public_link, is_public_link, link_preview, public_links};
105
111
pub use mapping::{chat_record, message_record};
106
pub use message_window::{JumpPlan, WINDOW_PAGE_SIZE, WindowPage, jump_plan, without_islands};
107
112
pub use markdown::{card_markdown_to_html, escape_html, markdown_to_html, plain_text_to_html};
108
pub use mentions::{MentionInput, apply_mentions, plain_mention_spans};
109
113
pub use meeting_join::{
110
114
MeetingCode, MeetingLink, ThreadMeeting, find_meeting_link, meeting_code_from_id,
111
115
meeting_link_in_html, parse_meeting_link,
112
116
};
117
pub use mentions::{MentionInput, apply_mentions, plain_mention_spans};
113
118
pub use message_link::{
114
119
ChannelLinkInput, channel_message_link, channel_tab_link, chat_message_link,
115
120
};
121
pub use message_window::{JumpPlan, WINDOW_PAGE_SIZE, WindowPage, jump_plan, without_islands};
116
122
pub use people::{MentionCandidate, PersonCandidate, PersonSource};
117
123
pub use presence::{Activity, Availability, Presence};
118
124
pub use preview::preview_text;
@@ -126,12 +132,8 @@ pub use stored::{
126
132
AttachmentInfo, FileCard, FileKind, ImageKind, ImageRef, MentionInfo, PROFILE_LINK_PREFIX,
127
133
QuoteInfo, ReactionInfo, ReactionSummary, adaptive_cards, attachments, can_delete, can_edit,
128
134
card_texts, copy_text, files, images, linked_message_spans, mentions, message_quote,
129
message_spans, quotes, reaction_summaries, reactions, readable_text, translated_spans, user_mention_inputs,
130
};
131
pub use chatsvc::{
132
Language, LanguageSettings, MessageLanguage, Translation, TranslationBehavior,
133
TranslationStatus, TranslationTrigger, authoring_patch, behavior_patch, language_code,
134
parse_language_settings, target_patch,
135
message_spans, quotes, reaction_summaries, reactions, readable_text, translated_spans,
136
user_mention_inputs,
135
137
};
136
138
pub use time_zone::local_time;
137
139
pub use translation::{
@@ -28,9 +28,9 @@ mod link_sync;28
mod links;28
mod links;29
mod mapping;29
mod mapping;30
mod markdown;30
mod markdown;31
mod meeting_join;31
mod mentions;32
mod mentions;32
mod message_actions;33
mod message_actions;33
mod meeting_join;34
mod message_link;34
mod message_link;35
mod message_window;35
mod message_window;36
mod people;36
mod people;@@ -79,10 +79,17 @@ pub use card_widgets::{79
};79
};80
pub use card_width::{TargetWidth, WidthClass};80
pub use card_width::{TargetWidth, WidthClass};81
pub use chatsvc::{81
pub use chatsvc::{82
CallDirection, CallLogEntry, CallOutcome, ChatApp, ForcedAvailability, ForcedKind, ForwardResult, Gif, PinnedMessage, PresenceStatus,82
CallDirection, CallLogEntry, CallOutcome, ChatApp, ForcedAvailability, ForcedKind,83
SavedMessage, ScheduledDraft, StatusNote, WindowDirection, WorkLocation, WorkLocationKind, WorkLocationSource,83
ForwardResult, Gif, PinnedMessage, PresenceStatus, SavedMessage, ScheduledDraft, StatusNote,84
WindowDirection, WorkLocation, WorkLocationKind, WorkLocationSource,84
};85
};85
pub use chatsvc::{ChatSection, ChatSectionSettings};86
pub use chatsvc::{ChatSection, ChatSectionSettings};87
pub use chatsvc::{88
Language, LanguageSettings, MessageLanguage, Translation, TranslationBehavior,89
TranslationStatus, TranslationTrigger, authoring_patch, behavior_patch, language_code,90
parse_language_settings, target_patch,91
};92
pub use download::LibraryFile;86
pub use draft::{93
pub use draft::{87
Draft, DraftLine, Edit, FormatState, LineKind, MAX_DEPTH, Mark, MarkKind, OBJECT_MARK,94
Draft, DraftLine, Edit, FormatState, LineKind, MAX_DEPTH, Mark, MarkKind, OBJECT_MARK,88
SizeStep, TypingStyle, changed_span, has_markdown, link_url, map_offset, reverse_edits,95
SizeStep, TypingStyle, changed_span, has_markdown, link_url, map_offset, reverse_edits,@@ -99,20 +106,19 @@ pub use graph::{99
DriveEntry, DriveFolder, FileReference, HostedImage, KeptAttachment, MentionTarget,106
DriveEntry, DriveFolder, FileReference, HostedImage, KeptAttachment, MentionTarget,100
MessageExtras, SharedFile, UploadedFile,107
MessageExtras, SharedFile, UploadedFile,101
};108
};102
pub use download::LibraryFile;103
pub use images::StoredImage;109
pub use images::StoredImage;104
pub use links::{LinkPreview, first_public_link, is_public_link, link_preview, public_links};110
pub use links::{LinkPreview, first_public_link, is_public_link, link_preview, public_links};105
pub use mapping::{chat_record, message_record};111
pub use mapping::{chat_record, message_record};106
pub use message_window::{JumpPlan, WINDOW_PAGE_SIZE, WindowPage, jump_plan, without_islands};107
pub use markdown::{card_markdown_to_html, escape_html, markdown_to_html, plain_text_to_html};112
pub use markdown::{card_markdown_to_html, escape_html, markdown_to_html, plain_text_to_html};108
pub use mentions::{MentionInput, apply_mentions, plain_mention_spans};109
pub use meeting_join::{113
pub use meeting_join::{110
MeetingCode, MeetingLink, ThreadMeeting, find_meeting_link, meeting_code_from_id,114
MeetingCode, MeetingLink, ThreadMeeting, find_meeting_link, meeting_code_from_id,111
meeting_link_in_html, parse_meeting_link,115
meeting_link_in_html, parse_meeting_link,112
};116
};117
pub use mentions::{MentionInput, apply_mentions, plain_mention_spans};113
pub use message_link::{118
pub use message_link::{114
ChannelLinkInput, channel_message_link, channel_tab_link, chat_message_link,119
ChannelLinkInput, channel_message_link, channel_tab_link, chat_message_link,115
};120
};121
pub use message_window::{JumpPlan, WINDOW_PAGE_SIZE, WindowPage, jump_plan, without_islands};116
pub use people::{MentionCandidate, PersonCandidate, PersonSource};122
pub use people::{MentionCandidate, PersonCandidate, PersonSource};117
pub use presence::{Activity, Availability, Presence};123
pub use presence::{Activity, Availability, Presence};118
pub use preview::preview_text;124
pub use preview::preview_text;@@ -126,12 +132,8 @@ pub use stored::{126
AttachmentInfo, FileCard, FileKind, ImageKind, ImageRef, MentionInfo, PROFILE_LINK_PREFIX,132
AttachmentInfo, FileCard, FileKind, ImageKind, ImageRef, MentionInfo, PROFILE_LINK_PREFIX,127
QuoteInfo, ReactionInfo, ReactionSummary, adaptive_cards, attachments, can_delete, can_edit,133
QuoteInfo, ReactionInfo, ReactionSummary, adaptive_cards, attachments, can_delete, can_edit,128
card_texts, copy_text, files, images, linked_message_spans, mentions, message_quote,134
card_texts, copy_text, files, images, linked_message_spans, mentions, message_quote,129
message_spans, quotes, reaction_summaries, reactions, readable_text, translated_spans, user_mention_inputs,135
message_spans, quotes, reaction_summaries, reactions, readable_text, translated_spans,130
};136
user_mention_inputs,131
pub use chatsvc::{132
Language, LanguageSettings, MessageLanguage, Translation, TranslationBehavior,133
TranslationStatus, TranslationTrigger, authoring_patch, behavior_patch, language_code,134
parse_language_settings, target_patch,135
};137
};136
pub use time_zone::local_time;138
pub use time_zone::local_time;137
pub use translation::{139
pub use translation::{@@ -6,7 +6,7 @@ use crate::remote::Remote;
6
6
7
7
impl<R: Remote> SyncEngine<R> {
8
8
pub async fn channel_library_root(&self, channel_id: &str) -> Result<DriveEntry> {
9
let Conversation::Channel { team_id } = self.resolve(channel_id)? else {
9
let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
10
10
return Err(Error::Unsupported("a library for a chat"));
11
11
};
12
12
self.remote.channel_files_root(&team_id, channel_id).await
@@ -17,7 +17,7 @@ impl<R: Remote> SyncEngine<R> {
17
17
channel_id: &str,
18
18
tab_id: &str,
19
19
) -> Result<Option<String>> {
20
let Conversation::Channel { team_id } = self.resolve(channel_id)? else {
20
let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {
21
21
return Err(Error::Unsupported("a tab link for a chat"));
22
22
};
23
23
self.remote
@@ -6,7 +6,7 @@ use crate::remote::Remote;6
6
7
impl<R: Remote> SyncEngine<R> {7
impl<R: Remote> SyncEngine<R> {8
pub async fn channel_library_root(&self, channel_id: &str) -> Result<DriveEntry> {8
pub async fn channel_library_root(&self, channel_id: &str) -> Result<DriveEntry> {9
let Conversation::Channel { team_id } = self.resolve(channel_id)? else {9
let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {10
return Err(Error::Unsupported("a library for a chat"));10
return Err(Error::Unsupported("a library for a chat"));11
};11
};12
self.remote.channel_files_root(&team_id, channel_id).await12
self.remote.channel_files_root(&team_id, channel_id).await@@ -17,7 +17,7 @@ impl<R: Remote> SyncEngine<R> {17
channel_id: &str,17
channel_id: &str,18
tab_id: &str,18
tab_id: &str,19
) -> Result<Option<String>> {19
) -> Result<Option<String>> {20
let Conversation::Channel { team_id } = self.resolve(channel_id)? else {20
let Conversation::Channel { team_id } = self.resolve(channel_id).await? else {21
return Err(Error::Unsupported("a tab link for a chat"));21
return Err(Error::Unsupported("a tab link for a chat"));22
};22
};23
self.remote23
self.remote@@ -74,7 +74,7 @@ impl<R: Remote> SyncEngine<R> {
74
74
conversation_id: &str,
75
75
records: &mut [&mut MessageRecord],
76
76
) -> bool {
77
let Ok(conversation) = self.resolve(conversation_id) else {
77
let Ok(conversation) = self.resolve_stored(conversation_id) else {
78
78
return false;
79
79
};
80
80
let targets = link_conversations(conversation_id, &conversation, records);
@@ -74,7 +74,7 @@ impl<R: Remote> SyncEngine<R> {74
conversation_id: &str,74
conversation_id: &str,75
records: &mut [&mut MessageRecord],75
records: &mut [&mut MessageRecord],76
) -> bool {76
) -> bool {77
let Ok(conversation) = self.resolve(conversation_id) else {77
let Ok(conversation) = self.resolve_stored(conversation_id) else {78
return false;78
return false;79
};79
};80
let targets = link_conversations(conversation_id, &conversation, records);80
let targets = link_conversations(conversation_id, &conversation, records);@@ -33,7 +33,7 @@ impl<R: Remote> SyncEngine<R> {
33
33
.await?;
34
34
let refreshed = [result.thread_id.as_str(), target_conversation_id]
35
35
.into_iter()
36
.find(|conversation_id| self.resolve(conversation_id).is_ok());
36
.find(|conversation_id| self.resolve_stored(conversation_id).is_ok());
37
37
if let Some(conversation_id) = refreshed
38
38
&& let Err(error) = self.fetch_newer(conversation_id).await
39
39
{
@@ -95,7 +95,7 @@ impl<R: Remote> SyncEngine<R> {
95
95
}
96
96
97
97
pub async fn message_link(&self, conversation_id: &str, message_id: &str) -> Result<String> {
98
let Conversation::Channel { team_id } = self.resolve(conversation_id)? else {
98
let Conversation::Channel { team_id } = self.resolve(conversation_id).await? else {
99
99
let notes_oid = if conversation_id == NOTES_CHAT_ID {
100
100
Some(self.my_user_id().await?)
101
101
} else {
@@ -154,7 +154,7 @@ impl<R: Remote> SyncEngine<R> {
154
154
}
155
155
156
156
fn ensure_chat(&self, conversation_id: &str) -> Result<()> {
157
match self.resolve(conversation_id)? {
157
match self.resolve_stored(conversation_id)? {
158
158
Conversation::Chat => Ok(()),
159
159
Conversation::Channel { .. } => Err(Error::Unsupported("pinned messages in a channel")),
160
160
}
@@ -33,7 +33,7 @@ impl<R: Remote> SyncEngine<R> {33
.await?;33
.await?;34
let refreshed = [result.thread_id.as_str(), target_conversation_id]34
let refreshed = [result.thread_id.as_str(), target_conversation_id]35
.into_iter()35
.into_iter()36
.find(|conversation_id| self.resolve(conversation_id).is_ok());36
.find(|conversation_id| self.resolve_stored(conversation_id).is_ok());37
if let Some(conversation_id) = refreshed37
if let Some(conversation_id) = refreshed38
&& let Err(error) = self.fetch_newer(conversation_id).await38
&& let Err(error) = self.fetch_newer(conversation_id).await39
{39
{@@ -95,7 +95,7 @@ impl<R: Remote> SyncEngine<R> {95
}95
}96
96
97
pub async fn message_link(&self, conversation_id: &str, message_id: &str) -> Result<String> {97
pub async fn message_link(&self, conversation_id: &str, message_id: &str) -> Result<String> {98
let Conversation::Channel { team_id } = self.resolve(conversation_id)? else {98
let Conversation::Channel { team_id } = self.resolve(conversation_id).await? else {99
let notes_oid = if conversation_id == NOTES_CHAT_ID {99
let notes_oid = if conversation_id == NOTES_CHAT_ID {100
Some(self.my_user_id().await?)100
Some(self.my_user_id().await?)101
} else {101
} else {@@ -154,7 +154,7 @@ impl<R: Remote> SyncEngine<R> {154
}154
}155
155
156
fn ensure_chat(&self, conversation_id: &str) -> Result<()> {156
fn ensure_chat(&self, conversation_id: &str) -> Result<()> {157
match self.resolve(conversation_id)? {157
match self.resolve_stored(conversation_id)? {158
Conversation::Chat => Ok(()),158
Conversation::Chat => Ok(()),159
Conversation::Channel { .. } => Err(Error::Unsupported("pinned messages in a channel")),159
Conversation::Channel { .. } => Err(Error::Unsupported("pinned messages in a channel")),160
}160
}@@ -105,7 +105,7 @@ impl<R: Remote> SyncEngine<R> {
105
105
query: &str,
106
106
limit: usize,
107
107
) -> Result<Vec<MentionCandidate>> {
108
let conversation = self.resolve(conversation_id)?;
108
let conversation = self.resolve(conversation_id).await?;
109
109
let query = query.trim().trim_start_matches('@').trim().to_lowercase();
110
110
let my_user_id = self.store.meta(META_USER_ID)?.unwrap_or_default();
111
111
let mut seen: HashSet<String> = HashSet::from([my_user_id]);
@@ -105,7 +105,7 @@ impl<R: Remote> SyncEngine<R> {105
query: &str,105
query: &str,106
limit: usize,106
limit: usize,107
) -> Result<Vec<MentionCandidate>> {107
) -> Result<Vec<MentionCandidate>> {108
let conversation = self.resolve(conversation_id)?;108
let conversation = self.resolve(conversation_id).await?;109
let query = query.trim().trim_start_matches('@').trim().to_lowercase();109
let query = query.trim().trim_start_matches('@').trim().to_lowercase();110
let my_user_id = self.store.meta(META_USER_ID)?.unwrap_or_default();110
let my_user_id = self.store.meta(META_USER_ID)?.unwrap_or_default();111
let mut seen: HashSet<String> = HashSet::from([my_user_id]);111
let mut seen: HashSet<String> = HashSet::from([my_user_id]);@@ -180,7 +180,10 @@ impl<R: Remote> SyncEngine<R> {
180
180
181
181
/// Call when a chat opens. Channels are skipped.
182
182
pub async fn refresh_receipts(&self, conversation_id: &str) -> Result<()> {
183
if matches!(self.resolve(conversation_id)?, Conversation::Channel { .. }) {
183
if matches!(
184
self.resolve(conversation_id).await?,
185
Conversation::Channel { .. }
186
) {
184
187
return Ok(());
185
188
}
186
189
let my_user_id = self.my_user_id().await?;
@@ -180,7 +180,10 @@ impl<R: Remote> SyncEngine<R> {180
180
181
/// Call when a chat opens. Channels are skipped.181
/// Call when a chat opens. Channels are skipped.182
pub async fn refresh_receipts(&self, conversation_id: &str) -> Result<()> {182
pub async fn refresh_receipts(&self, conversation_id: &str) -> Result<()> {183
if matches!(self.resolve(conversation_id)?, Conversation::Channel { .. }) {183
if matches!(184
self.resolve(conversation_id).await?,185
Conversation::Channel { .. }186
) {184
return Ok(());187
return Ok(());185
}188
}186
let my_user_id = self.my_user_id().await?;189
let my_user_id = self.my_user_id().await?;@@ -2,9 +2,9 @@ use chatsvc::{
2
2
CallLogEntry, CardActions, ChatApp, ConversationRef, ConversationState, Conversations,
3
3
ForcedAvailability, ForwardResult, Gif, Gifs, InvokeRequest, InvokeResponse, Language,
4
4
LanguageSettings, LanguageSettingsClient, LinkInfo, MemberHorizon, MessageLanguage,
5
MessageLinks, MessageWindow, Messages, PinnedMessage, Pins, PresenceService, PresenceStatus, Receipts,
6
SavedMessage, ScheduledDraft, ScheduledDrafts, StatusNote, TranslateRequest, Translation,
7
TranslationTrigger, Translator, WindowDirection, WorkLocationKind,
5
MessageLinks, MessageWindow, Messages, PinnedMessage, Pins, PresenceService, PresenceStatus,
6
Receipts, SavedMessage, ScheduledDraft, ScheduledDrafts, StatusNote, TranslateRequest,
7
Translation, TranslationTrigger, Translator, WindowDirection, WorkLocationKind,
8
8
};
9
9
use chrono::{DateTime, Utc};
10
10
use graph::{
@@ -2,9 +2,9 @@ use chatsvc::{2
CallLogEntry, CardActions, ChatApp, ConversationRef, ConversationState, Conversations,2
CallLogEntry, CardActions, ChatApp, ConversationRef, ConversationState, Conversations,3
ForcedAvailability, ForwardResult, Gif, Gifs, InvokeRequest, InvokeResponse, Language,3
ForcedAvailability, ForwardResult, Gif, Gifs, InvokeRequest, InvokeResponse, Language,4
LanguageSettings, LanguageSettingsClient, LinkInfo, MemberHorizon, MessageLanguage,4
LanguageSettings, LanguageSettingsClient, LinkInfo, MemberHorizon, MessageLanguage,5
MessageLinks, MessageWindow, Messages, PinnedMessage, Pins, PresenceService, PresenceStatus, Receipts,5
MessageLinks, MessageWindow, Messages, PinnedMessage, Pins, PresenceService, PresenceStatus,6
SavedMessage, ScheduledDraft, ScheduledDrafts, StatusNote, TranslateRequest, Translation,6
Receipts, SavedMessage, ScheduledDraft, ScheduledDrafts, StatusNote, TranslateRequest,7
TranslationTrigger, Translator, WindowDirection, WorkLocationKind,7
Translation, TranslationTrigger, Translator, WindowDirection, WorkLocationKind,8
};8
};9
use chrono::{DateTime, Utc};9
use chrono::{DateTime, Utc};10
use graph::{10
use graph::{@@ -51,7 +51,7 @@ impl<R: Remote> SyncEngine<R> {
51
51
if conversation_id == NOTES_CHAT_ID {
52
52
return Err(Error::Unsupported("schedule send in the notes chat"));
53
53
}
54
let conversation = match (self.resolve(conversation_id)?, thread_root_id) {
54
let conversation = match (self.resolve_stored(conversation_id)?, thread_root_id) {
55
55
(Conversation::Chat, None) => ConversationRef::chat(conversation_id),
56
56
(Conversation::Channel { .. }, None) => ConversationRef::channel_root(conversation_id),
57
57
(Conversation::Channel { .. }, Some(root_id)) => {
@@ -51,7 +51,7 @@ impl<R: Remote> SyncEngine<R> {51
if conversation_id == NOTES_CHAT_ID {51
if conversation_id == NOTES_CHAT_ID {52
return Err(Error::Unsupported("schedule send in the notes chat"));52
return Err(Error::Unsupported("schedule send in the notes chat"));53
}53
}54
let conversation = match (self.resolve(conversation_id)?, thread_root_id) {54
let conversation = match (self.resolve_stored(conversation_id)?, thread_root_id) {55
(Conversation::Chat, None) => ConversationRef::chat(conversation_id),55
(Conversation::Chat, None) => ConversationRef::chat(conversation_id),56
(Conversation::Channel { .. }, None) => ConversationRef::channel_root(conversation_id),56
(Conversation::Channel { .. }, None) => ConversationRef::channel_root(conversation_id),57
(Conversation::Channel { .. }, Some(root_id)) => {57
(Conversation::Channel { .. }, Some(root_id)) => {@@ -192,11 +192,7 @@ impl<R: Remote> SyncEngine<R> {
192
192
Ok((my_user_id, page))
193
193
}
194
194
195
fn apply_older_chats(
196
&self,
197
fetched: Result<(String, ChatsPage)>,
198
epoch: u64,
199
) -> Result<usize> {
195
fn apply_older_chats(&self, fetched: Result<(String, ChatsPage)>, epoch: u64) -> Result<usize> {
200
196
let mut paging = self.chat_paging.lock().unwrap();
201
197
let (my_user_id, page) = match fetched {
202
198
Ok(fetched) => fetched,
@@ -192,11 +192,7 @@ impl<R: Remote> SyncEngine<R> {192
Ok((my_user_id, page))192
Ok((my_user_id, page))193
}193
}194
194
195
fn apply_older_chats(195
fn apply_older_chats(&self, fetched: Result<(String, ChatsPage)>, epoch: u64) -> Result<usize> {196
&self,197
fetched: Result<(String, ChatsPage)>,198
epoch: u64,199
) -> Result<usize> {200
let mut paging = self.chat_paging.lock().unwrap();196
let mut paging = self.chat_paging.lock().unwrap();201
let (my_user_id, page) = match fetched {197
let (my_user_id, page) = match fetched {202
Ok(fetched) => fetched,198
Ok(fetched) => fetched,@@ -17,7 +17,7 @@ const STAMP_CACHE_MESSAGES: usize = 100;
17
17
impl<R: Remote> SyncEngine<R> {
18
18
pub async fn language_stamps(&self, conversation_id: &str) -> Result<Vec<MessageLanguage>> {
19
19
let targets =
20
match self.resolve(conversation_id)? {
20
match self.resolve(conversation_id).await? {
21
21
Conversation::Chat => vec![ConversationRef::chat(conversation_id)],
22
22
Conversation::Channel { .. } => {
23
23
let cached =
@@ -58,7 +58,7 @@ impl<R: Remote> SyncEngine<R> {
58
58
to_language: &str,
59
59
trigger: &TranslationTrigger,
60
60
) -> Result<Vec<Translation>> {
61
let conversation = self.resolve(conversation_id)?;
61
let conversation = self.resolve(conversation_id).await?;
62
62
let mut translations = Vec::new();
63
63
match conversation {
64
64
Conversation::Chat => {
@@ -17,7 +17,7 @@ const STAMP_CACHE_MESSAGES: usize = 100;17
impl<R: Remote> SyncEngine<R> {17
impl<R: Remote> SyncEngine<R> {18
pub async fn language_stamps(&self, conversation_id: &str) -> Result<Vec<MessageLanguage>> {18
pub async fn language_stamps(&self, conversation_id: &str) -> Result<Vec<MessageLanguage>> {19
let targets =19
let targets =20
match self.resolve(conversation_id)? {20
match self.resolve(conversation_id).await? {21
Conversation::Chat => vec![ConversationRef::chat(conversation_id)],21
Conversation::Chat => vec![ConversationRef::chat(conversation_id)],22
Conversation::Channel { .. } => {22
Conversation::Channel { .. } => {23
let cached =23
let cached =@@ -58,7 +58,7 @@ impl<R: Remote> SyncEngine<R> {58
to_language: &str,58
to_language: &str,59
trigger: &TranslationTrigger,59
trigger: &TranslationTrigger,60
) -> Result<Vec<Translation>> {60
) -> Result<Vec<Translation>> {61
let conversation = self.resolve(conversation_id)?;61
let conversation = self.resolve(conversation_id).await?;62
let mut translations = Vec::new();62
let mut translations = Vec::new();63
match conversation {63
match conversation {64
Conversation::Chat => {64
Conversation::Chat => {@@ -48,7 +48,10 @@ fn digest_card_keeps_layout_text_and_actions() {
48
48
panic!("first item is a column set");
49
49
};
50
50
assert_eq!(columns[0].width, ColumnWidth::Auto);
51
assert_eq!(columns[0].layout.vertical_alignment, VerticalAlignment::Center);
51
assert_eq!(
52
columns[0].layout.vertical_alignment,
53
VerticalAlignment::Center
54
);
52
55
let CardElement::Image(image) = &columns[0].items[0].element else {
53
56
panic!("avatar column holds an image");
54
57
};
@@ -48,7 +48,10 @@ fn digest_card_keeps_layout_text_and_actions() {48
panic!("first item is a column set");48
panic!("first item is a column set");49
};49
};50
assert_eq!(columns[0].width, ColumnWidth::Auto);50
assert_eq!(columns[0].width, ColumnWidth::Auto);51
assert_eq!(columns[0].layout.vertical_alignment, VerticalAlignment::Center);51
assert_eq!(52
columns[0].layout.vertical_alignment,53
VerticalAlignment::Center54
);52
let CardElement::Image(image) = &columns[0].items[0].element else {55
let CardElement::Image(image) = &columns[0].items[0].element else {53
panic!("avatar column holds an image");56
panic!("avatar column holds an image");54
};57
};@@ -8,7 +8,9 @@ use graph::{
8
8
OutgoingMention, Photo, Presence, SharedFile, Team, UploadDestination, UploadedFile, User,
9
9
};
10
10
use serde_json::json;
11
use store::{ChannelLayoutRecord, ChannelRecord, ChannelTabRecord, Store, TeamLayoutRecord, TeamRecord};
11
use store::{
12
ChannelLayoutRecord, ChannelRecord, ChannelTabRecord, Store, TeamLayoutRecord, TeamRecord,
13
};
12
14
use teams_core::{
13
15
Availability, BoxFuture, ChatFolder, ChatSection, ChatSectionSettings, ChatsPage, CoreEvent,
14
16
DeltaPage, Error, FolderChange, FolderKind, FolderSource, MentionCandidate, MentionInput,
@@ -82,6 +84,8 @@ type ScheduledCall = (String, String, DateTime<Utc>, String);
82
84
#[derive(Default)]
83
85
struct Fake {
84
86
chats: Mutex<Vec<Chat>>,
87
fetchable_chats: Mutex<Vec<Chat>>,
88
single_chat_calls: Mutex<usize>,
85
89
chat_messages: Mutex<Vec<Message>>,
86
90
channel_pages: Mutex<Vec<Vec<Message>>>,
87
91
teams: Mutex<Vec<Team>>,
@@ -207,8 +211,22 @@ impl Remote for Handle {
207
211
Ok(self.chats_from(offset, top))
208
212
}
209
213
210
async fn chat(&self, _chat_id: &str) -> Result<Chat> {
211
unsupported()
214
async fn chat(&self, chat_id: &str) -> Result<Chat> {
215
*self.single_chat_calls.lock().unwrap() += 1;
216
let found = self
217
.fetchable_chats
218
.lock()
219
.unwrap()
220
.iter()
221
.find(|candidate| candidate.id == chat_id)
222
.cloned();
223
found.ok_or_else(|| {
224
Error::Graph(graph::Error::Session(session::Error::api(
225
404,
226
chat_id,
227
json!({}),
228
)))
229
})
212
230
}
213
231
214
232
async fn chat_members(&self, _chat_id: &str) -> Result<Vec<Member>> {
@@ -1174,11 +1192,25 @@ async fn a_chat_hidden_in_the_app_stays_hidden_until_a_newer_message_arrives() {
1174
1192
engine.refresh_sidebar_full().await.unwrap();
1175
1193
assert!(engine.sidebar().unwrap().chats.is_empty());
1176
1194
1177
*fake.chats.lock().unwrap() = vec![chat(CHAT, Some("Planning"), 10_000_000, 5, "user-ada", false)];
1195
*fake.chats.lock().unwrap() = vec![chat(
1196
CHAT,
1197
Some("Planning"),
1198
10_000_000,
1199
5,
1200
"user-ada",
1201
false,
1202
)];
1178
1203
engine.refresh_sidebar().await.unwrap();
1179
1204
assert_eq!(engine.sidebar().unwrap().chats.len(), 1);
1180
1205
1181
*fake.chats.lock().unwrap() = vec![chat(CHAT, Some("Planning"), 10_000_000, 5, "user-ada", false)];
1206
*fake.chats.lock().unwrap() = vec![chat(
1207
CHAT,
1208
Some("Planning"),
1209
10_000_000,
1210
5,
1211
"user-ada",
1212
false,
1213
)];
1182
1214
engine.refresh_sidebar_full().await.unwrap();
1183
1215
assert_eq!(engine.sidebar().unwrap().chats.len(), 1);
1184
1216
}
@@ -1489,6 +1521,37 @@ async fn send_message_converts_markdown_and_caches_the_answer() {
1489
1521
);
1490
1522
}
1491
1523
1524
#[tokio::test]
1525
async fn unknown_chat_is_fetched_stored_and_resolves() {
1526
let fake = Arc::new(Fake::default());
1527
let meeting_chat = "19:meeting_abc@thread.v2";
1528
*fake.fetchable_chats.lock().unwrap() =
1529
vec![chat(meeting_chat, Some("Standup"), 5, 5, ME, false)];
1530
fake.set_chat_messages(vec![message(1, 1, "<p>hello</p>")]);
1531
let engine = engine_with(&fake, SyncConfig::default());
1532
let delta = engine.fetch_newer(meeting_chat).await.unwrap();
1533
assert_eq!(delta.added.len(), 1);
1534
engine.fetch_newer(meeting_chat).await.unwrap();
1535
assert_eq!(*fake.single_chat_calls.lock().unwrap(), 1);
1536
engine.send_message(meeting_chat, "hi", None).await.unwrap();
1537
}
1538
1539
#[tokio::test]
1540
async fn unknown_chat_missing_remotely_stays_an_error() {
1541
let fake = Arc::new(Fake::default());
1542
let engine = engine_with(&fake, SyncConfig::default());
1543
assert!(matches!(
1544
engine.fetch_newer("19:meeting_gone@thread.v2").await,
1545
Err(Error::UnknownConversation(_))
1546
));
1547
assert!(matches!(
1548
engine
1549
.send_message("19:meeting_gone@thread.v2", "hi", None)
1550
.await,
1551
Err(Error::UnknownConversation(_))
1552
));
1553
}
1554
1492
1555
#[tokio::test]
1493
1556
async fn unknown_conversation_is_an_error() {
1494
1557
let fake = Arc::new(Fake::default());
@@ -2896,7 +2959,10 @@ async fn a_failing_folder_list_still_stores_the_team_layout_and_tabs() {
2896
2959
let error = engine.refresh_folders().await.unwrap_err();
2897
2960
2898
2961
assert!(error.to_string().contains("folders down"));
2899
assert_eq!(engine.store().channel_tabs("alpha-general").unwrap().len(), 1);
2962
assert_eq!(
2963
engine.store().channel_tabs("alpha-general").unwrap().len(),
2964
1
2965
);
2900
2966
assert!(
2901
2967
engine
2902
2968
.store()
@@ -4366,7 +4432,10 @@ async fn translating_in_an_unknown_conversation_fails() {
4366
4432
&teams_core::TranslationTrigger::OnDemand,
4367
4433
)
4368
4434
.await;
4369
assert!(matches!(outcome, Err(teams_core::Error::UnknownConversation(_))));
4435
assert!(matches!(
4436
outcome,
4437
Err(teams_core::Error::UnknownConversation(_))
4438
));
4370
4439
}
4371
4440
4372
4441
#[tokio::test]
@@ -4382,7 +4451,11 @@ async fn load_window_ingests_found_messages_oldest_first_and_keeps_cursors() {
4382
4451
4383
4452
let page = engine.load_window(CHAT, "m0003").await.unwrap();
4384
4453
4385
let ids: Vec<&str> = page.records.iter().map(|record| record.message_id.as_str()).collect();
4454
let ids: Vec<&str> = page
4455
.records
4456
.iter()
4457
.map(|record| record.message_id.as_str())
4458
.collect();
4386
4459
assert_eq!(ids, ["m0001", "m0003"]);
4387
4460
assert_eq!(page.oldest, Some(base() + Duration::minutes(1)));
4388
4461
assert_eq!(page.newest, Some(base() + Duration::minutes(3)));
@@ -4401,7 +4474,11 @@ async fn fetch_chat_message_does_not_store_the_message() {
4401
4474
let engine = chat_engine(&fake, small_pages()).await;
4402
4475
fake.set_chat_messages(vec![message(7, 7, "<p>pinned</p>")]);
4403
4476
4404
let record = engine.fetch_chat_message(CHAT, "m0007").await.unwrap().unwrap();
4477
let record = engine
4478
.fetch_chat_message(CHAT, "m0007")
4479
.await
4480
.unwrap()
4481
.unwrap();
4405
4482
4406
4483
assert_eq!(record.message_id, "m0007");
4407
4484
assert_eq!(engine.store().message_count(CHAT).unwrap(), 0);
@@ -8,7 +8,9 @@ use graph::{8
OutgoingMention, Photo, Presence, SharedFile, Team, UploadDestination, UploadedFile, User,8
OutgoingMention, Photo, Presence, SharedFile, Team, UploadDestination, UploadedFile, User,9
};9
};10
use serde_json::json;10
use serde_json::json;11
use store::{ChannelLayoutRecord, ChannelRecord, ChannelTabRecord, Store, TeamLayoutRecord, TeamRecord};11
use store::{12
ChannelLayoutRecord, ChannelRecord, ChannelTabRecord, Store, TeamLayoutRecord, TeamRecord,13
};12
use teams_core::{14
use teams_core::{13
Availability, BoxFuture, ChatFolder, ChatSection, ChatSectionSettings, ChatsPage, CoreEvent,15
Availability, BoxFuture, ChatFolder, ChatSection, ChatSectionSettings, ChatsPage, CoreEvent,14
DeltaPage, Error, FolderChange, FolderKind, FolderSource, MentionCandidate, MentionInput,16
DeltaPage, Error, FolderChange, FolderKind, FolderSource, MentionCandidate, MentionInput,@@ -82,6 +84,8 @@ type ScheduledCall = (String, String, DateTime<Utc>, String);82
#[derive(Default)]84
#[derive(Default)]83
struct Fake {85
struct Fake {84
chats: Mutex<Vec<Chat>>,86
chats: Mutex<Vec<Chat>>,87
fetchable_chats: Mutex<Vec<Chat>>,88
single_chat_calls: Mutex<usize>,85
chat_messages: Mutex<Vec<Message>>,89
chat_messages: Mutex<Vec<Message>>,86
channel_pages: Mutex<Vec<Vec<Message>>>,90
channel_pages: Mutex<Vec<Vec<Message>>>,87
teams: Mutex<Vec<Team>>,91
teams: Mutex<Vec<Team>>,@@ -207,8 +211,22 @@ impl Remote for Handle {207
Ok(self.chats_from(offset, top))211
Ok(self.chats_from(offset, top))208
}212
}209
213
210
async fn chat(&self, _chat_id: &str) -> Result<Chat> {214
async fn chat(&self, chat_id: &str) -> Result<Chat> {211
unsupported()215
*self.single_chat_calls.lock().unwrap() += 1;216
let found = self217
.fetchable_chats218
.lock()219
.unwrap()220
.iter()221
.find(|candidate| candidate.id == chat_id)222
.cloned();223
found.ok_or_else(|| {224
Error::Graph(graph::Error::Session(session::Error::api(225
404,226
chat_id,227
json!({}),228
)))229
})212
}230
}213
231
214
async fn chat_members(&self, _chat_id: &str) -> Result<Vec<Member>> {232
async fn chat_members(&self, _chat_id: &str) -> Result<Vec<Member>> {@@ -1174,11 +1192,25 @@ async fn a_chat_hidden_in_the_app_stays_hidden_until_a_newer_message_arrives() {1174
engine.refresh_sidebar_full().await.unwrap();1192
engine.refresh_sidebar_full().await.unwrap();1175
assert!(engine.sidebar().unwrap().chats.is_empty());1193
assert!(engine.sidebar().unwrap().chats.is_empty());1176
1194
1177
*fake.chats.lock().unwrap() = vec![chat(CHAT, Some("Planning"), 10_000_000, 5, "user-ada", false)];1195
*fake.chats.lock().unwrap() = vec![chat(1196
CHAT,1197
Some("Planning"),1198
10_000_000,1199
5,1200
"user-ada",1201
false,1202
)];1178
engine.refresh_sidebar().await.unwrap();1203
engine.refresh_sidebar().await.unwrap();1179
assert_eq!(engine.sidebar().unwrap().chats.len(), 1);1204
assert_eq!(engine.sidebar().unwrap().chats.len(), 1);1180
1205
1181
*fake.chats.lock().unwrap() = vec![chat(CHAT, Some("Planning"), 10_000_000, 5, "user-ada", false)];1206
*fake.chats.lock().unwrap() = vec![chat(1207
CHAT,1208
Some("Planning"),1209
10_000_000,1210
5,1211
"user-ada",1212
false,1213
)];1182
engine.refresh_sidebar_full().await.unwrap();1214
engine.refresh_sidebar_full().await.unwrap();1183
assert_eq!(engine.sidebar().unwrap().chats.len(), 1);1215
assert_eq!(engine.sidebar().unwrap().chats.len(), 1);1184
}1216
}@@ -1489,6 +1521,37 @@ async fn send_message_converts_markdown_and_caches_the_answer() {1489
);1521
);1490
}1522
}1491
1523
1524
#[tokio::test]1525
async fn unknown_chat_is_fetched_stored_and_resolves() {1526
let fake = Arc::new(Fake::default());1527
let meeting_chat = "19:meeting_abc@thread.v2";1528
*fake.fetchable_chats.lock().unwrap() =1529
vec![chat(meeting_chat, Some("Standup"), 5, 5, ME, false)];1530
fake.set_chat_messages(vec![message(1, 1, "<p>hello</p>")]);1531
let engine = engine_with(&fake, SyncConfig::default());1532
let delta = engine.fetch_newer(meeting_chat).await.unwrap();1533
assert_eq!(delta.added.len(), 1);1534
engine.fetch_newer(meeting_chat).await.unwrap();1535
assert_eq!(*fake.single_chat_calls.lock().unwrap(), 1);1536
engine.send_message(meeting_chat, "hi", None).await.unwrap();1537
}1538
1539
#[tokio::test]1540
async fn unknown_chat_missing_remotely_stays_an_error() {1541
let fake = Arc::new(Fake::default());1542
let engine = engine_with(&fake, SyncConfig::default());1543
assert!(matches!(1544
engine.fetch_newer("19:meeting_gone@thread.v2").await,1545
Err(Error::UnknownConversation(_))1546
));1547
assert!(matches!(1548
engine1549
.send_message("19:meeting_gone@thread.v2", "hi", None)1550
.await,1551
Err(Error::UnknownConversation(_))1552
));1553
}1554
1492
#[tokio::test]1555
#[tokio::test]1493
async fn unknown_conversation_is_an_error() {1556
async fn unknown_conversation_is_an_error() {1494
let fake = Arc::new(Fake::default());1557
let fake = Arc::new(Fake::default());@@ -2896,7 +2959,10 @@ async fn a_failing_folder_list_still_stores_the_team_layout_and_tabs() {2896
let error = engine.refresh_folders().await.unwrap_err();2959
let error = engine.refresh_folders().await.unwrap_err();2897
2960
2898
assert!(error.to_string().contains("folders down"));2961
assert!(error.to_string().contains("folders down"));2899
assert_eq!(engine.store().channel_tabs("alpha-general").unwrap().len(), 1);2962
assert_eq!(2963
engine.store().channel_tabs("alpha-general").unwrap().len(),2964
12965
);2900
assert!(2966
assert!(2901
engine2967
engine2902
.store()2968
.store()@@ -4366,7 +4432,10 @@ async fn translating_in_an_unknown_conversation_fails() {4366
&teams_core::TranslationTrigger::OnDemand,4432
&teams_core::TranslationTrigger::OnDemand,4367
)4433
)4368
.await;4434
.await;4369
assert!(matches!(outcome, Err(teams_core::Error::UnknownConversation(_))));4435
assert!(matches!(4436
outcome,4437
Err(teams_core::Error::UnknownConversation(_))4438
));4370
}4439
}4371
4440
4372
#[tokio::test]4441
#[tokio::test]@@ -4382,7 +4451,11 @@ async fn load_window_ingests_found_messages_oldest_first_and_keeps_cursors() {4382
4451
4383
let page = engine.load_window(CHAT, "m0003").await.unwrap();4452
let page = engine.load_window(CHAT, "m0003").await.unwrap();4384
4453
4385
let ids: Vec<&str> = page.records.iter().map(|record| record.message_id.as_str()).collect();4454
let ids: Vec<&str> = page4455
.records4456
.iter()4457
.map(|record| record.message_id.as_str())4458
.collect();4386
assert_eq!(ids, ["m0001", "m0003"]);4459
assert_eq!(ids, ["m0001", "m0003"]);4387
assert_eq!(page.oldest, Some(base() + Duration::minutes(1)));4460
assert_eq!(page.oldest, Some(base() + Duration::minutes(1)));4388
assert_eq!(page.newest, Some(base() + Duration::minutes(3)));4461
assert_eq!(page.newest, Some(base() + Duration::minutes(3)));@@ -4401,7 +4474,11 @@ async fn fetch_chat_message_does_not_store_the_message() {4401
let engine = chat_engine(&fake, small_pages()).await;4474
let engine = chat_engine(&fake, small_pages()).await;4402
fake.set_chat_messages(vec![message(7, 7, "<p>pinned</p>")]);4475
fake.set_chat_messages(vec![message(7, 7, "<p>pinned</p>")]);4403
4476
4404
let record = engine.fetch_chat_message(CHAT, "m0007").await.unwrap().unwrap();4477
let record = engine4478
.fetch_chat_message(CHAT, "m0007")4479
.await4480
.unwrap()4481
.unwrap();4405
4482
4406
assert_eq!(record.message_id, "m0007");4483
assert_eq!(record.message_id, "m0007");4407
assert_eq!(engine.store().message_count(CHAT).unwrap(), 0);4484
assert_eq!(engine.store().message_count(CHAT).unwrap(), 0);