feat(mentions): @Everyone in group chats and team tag mentions
- Mention picker: "Everyone" first in group chats, team tags after channel and team in channels (Graph teams/{id}/tags, cached 5 min, failures cached as none)
- Graph payload: Everyone as conversation identity type chat with the chat id, tags as mentioned.tag
- Quote replies with Everyone or a tag fall back to Graph replyWithQuote, like team mentions
- A received @Everyone in a chat counts as a mention for notifications
- Deviation: no Everyone in meeting chats and no roster limit (Teams flags and limits unknown); tags not offered in the new chat To field; a received tag mention toasts by the channel mention rule (tag membership not fetched)
- Payload shapes from Graph docs, not verified live
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -493,6 +493,13 @@ pub fn mention_candidates(conversation_id: &str, query: &str) -> Vec<MentionCand
493
493
source: PersonSource::Member,
494
494
})
495
495
});
496
let everyone = demo_chats()
497
.into_iter()
498
.find(|chat| chat.id == conversation_id && chat.kind == "group")
499
.map(|chat| MentionCandidate::Everyone {
500
chat_id: chat.id.to_owned(),
501
})
502
.filter(|candidate| matches(candidate.display_name()));
496
503
let scope: Vec<MentionCandidate> = if conversation_id.starts_with("demo-channel") {
497
504
[
498
505
MentionCandidate::Channel {
@@ -503,6 +510,11 @@ pub fn mention_candidates(conversation_id: &str, query: &str) -> Vec<MentionCand
503
510
team_id: "demo-team-1".to_owned(),
504
511
name: "Platform".to_owned(),
505
512
},
513
MentionCandidate::Tag {
514
tag_id: "demo-tag-design".to_owned(),
515
name: "Designers".to_owned(),
516
member_count: Some(3),
517
},
506
518
]
507
519
.into_iter()
508
520
.filter(|candidate| matches(candidate.display_name()))
@@ -510,7 +522,7 @@ pub fn mention_candidates(conversation_id: &str, query: &str) -> Vec<MentionCand
510
522
} else {
511
523
Vec::new()
512
524
};
513
people.chain(scope).collect()
525
everyone.into_iter().chain(people).chain(scope).collect()
514
526
}
515
527
516
528
pub fn send_in_chat(
@@ -2409,7 +2421,18 @@ mod tests {
2409
2421
assert_eq!(chat[0].display_name(), "Mara Lindqvist");
2410
2422
let channel = mention_candidates("demo-channel-1-1", "gen");
2411
2423
assert!(matches!(channel[0], MentionCandidate::Channel { .. }));
2412
assert_eq!(mention_candidates("demo-chat-release", "").len(), 5);
2424
let all = mention_candidates("demo-chat-release", "");
2425
assert_eq!(all.len(), 6);
2426
assert!(matches!(all[0], MentionCandidate::Everyone { .. }));
2427
assert!(
2428
mention_candidates("demo-chat-mara", "")
2429
.iter()
2430
.all(|candidate| !matches!(candidate, MentionCandidate::Everyone { .. }))
2431
);
2432
assert!(matches!(
2433
mention_candidates("demo-channel-1-1", "desi")[0],
2434
MentionCandidate::Tag { .. }
2435
));
2413
2436
}
2414
2437
2415
2438
#[test]
@@ -493,6 +493,13 @@ pub fn mention_candidates(conversation_id: &str, query: &str) -> Vec<MentionCand493
source: PersonSource::Member,493
source: PersonSource::Member,494
})494
})495
});495
});496
let everyone = demo_chats()497
.into_iter()498
.find(|chat| chat.id == conversation_id && chat.kind == "group")499
.map(|chat| MentionCandidate::Everyone {500
chat_id: chat.id.to_owned(),501
})502
.filter(|candidate| matches(candidate.display_name()));496
let scope: Vec<MentionCandidate> = if conversation_id.starts_with("demo-channel") {503
let scope: Vec<MentionCandidate> = if conversation_id.starts_with("demo-channel") {497
[504
[498
MentionCandidate::Channel {505
MentionCandidate::Channel {@@ -503,6 +510,11 @@ pub fn mention_candidates(conversation_id: &str, query: &str) -> Vec<MentionCand503
team_id: "demo-team-1".to_owned(),510
team_id: "demo-team-1".to_owned(),504
name: "Platform".to_owned(),511
name: "Platform".to_owned(),505
},512
},513
MentionCandidate::Tag {514
tag_id: "demo-tag-design".to_owned(),515
name: "Designers".to_owned(),516
member_count: Some(3),517
},506
]518
]507
.into_iter()519
.into_iter()508
.filter(|candidate| matches(candidate.display_name()))520
.filter(|candidate| matches(candidate.display_name()))@@ -510,7 +522,7 @@ pub fn mention_candidates(conversation_id: &str, query: &str) -> Vec<MentionCand510
} else {522
} else {511
Vec::new()523
Vec::new()512
};524
};513
people.chain(scope).collect()525
everyone.into_iter().chain(people).chain(scope).collect()514
}526
}515
527
516
pub fn send_in_chat(528
pub fn send_in_chat(@@ -2409,7 +2421,18 @@ mod tests {2409
assert_eq!(chat[0].display_name(), "Mara Lindqvist");2421
assert_eq!(chat[0].display_name(), "Mara Lindqvist");2410
let channel = mention_candidates("demo-channel-1-1", "gen");2422
let channel = mention_candidates("demo-channel-1-1", "gen");2411
assert!(matches!(channel[0], MentionCandidate::Channel { .. }));2423
assert!(matches!(channel[0], MentionCandidate::Channel { .. }));2412
assert_eq!(mention_candidates("demo-chat-release", "").len(), 5);2424
let all = mention_candidates("demo-chat-release", "");2425
assert_eq!(all.len(), 6);2426
assert!(matches!(all[0], MentionCandidate::Everyone { .. }));2427
assert!(2428
mention_candidates("demo-chat-mara", "")2429
.iter()2430
.all(|candidate| !matches!(candidate, MentionCandidate::Everyone { .. }))2431
);2432
assert!(matches!(2433
mention_candidates("demo-channel-1-1", "desi")[0],2434
MentionCandidate::Tag { .. }2435
));2413
}2436
}2414
2437
2415
#[test]2438
#[test]@@ -161,6 +161,8 @@ pub fn build_incoming(
161
161
_ => ChannelSignals::default(),
162
162
};
163
163
let chat = chat_signals(store, sidebar, &record.conversation_id, my_user_id);
164
let mentions_me = mentions_me(record, my_user_id)
165
|| (!matches!(kind, ChatKind::Channel { .. }) && teams_core::mentions_whole_chat(record));
164
166
Some(Incoming {
165
167
conversation_id: record.conversation_id.clone(),
166
168
message_id: record.message_id.clone(),
@@ -169,7 +171,7 @@ pub fn build_incoming(
169
171
sender_id: record.sender_id.clone(),
170
172
sender_name: record.sender_name.clone().unwrap_or_default(),
171
173
preview: preview_of(record),
172
mentions_me: mentions_me(record, my_user_id),
174
mentions_me,
173
175
muted: is_muted_chat(sidebar, &record.conversation_id),
174
176
signals,
175
177
chat,
@@ -593,6 +595,19 @@ mod tests {
593
595
assert!(!other.unwrap().mentions_me);
594
596
}
595
597
598
#[test]
599
fn everyone_in_a_group_chat_counts_as_a_mention_but_a_channel_mention_does_not() {
600
let store = Store::open_in_memory().unwrap();
601
let mut message = record("group", "u1", Utc::now(), "<at>Everyone</at>");
602
message.mentions_json =
603
r#"[{"user_id":null,"name":"Everyone","target_id":"group","group":true}]"#.into();
604
assert!(collect_one(message, &store).mentions_me);
605
let mut post = record("channel-open", "u1", Utc::now(), "<at>channel</at>");
606
post.mentions_json =
607
r#"[{"user_id":null,"name":"channel","target_id":"channel-open","group":true}]"#.into();
608
assert!(!collect_one(post, &store).mentions_me);
609
}
610
596
611
#[test]
597
612
fn unknown_conversation_yields_nothing() {
598
613
let message = record("nowhere", "u1", Utc::now(), "x");
@@ -161,6 +161,8 @@ pub fn build_incoming(161
_ => ChannelSignals::default(),161
_ => ChannelSignals::default(),162
};162
};163
let chat = chat_signals(store, sidebar, &record.conversation_id, my_user_id);163
let chat = chat_signals(store, sidebar, &record.conversation_id, my_user_id);164
let mentions_me = mentions_me(record, my_user_id)165
|| (!matches!(kind, ChatKind::Channel { .. }) && teams_core::mentions_whole_chat(record));164
Some(Incoming {166
Some(Incoming {165
conversation_id: record.conversation_id.clone(),167
conversation_id: record.conversation_id.clone(),166
message_id: record.message_id.clone(),168
message_id: record.message_id.clone(),@@ -169,7 +171,7 @@ pub fn build_incoming(169
sender_id: record.sender_id.clone(),171
sender_id: record.sender_id.clone(),170
sender_name: record.sender_name.clone().unwrap_or_default(),172
sender_name: record.sender_name.clone().unwrap_or_default(),171
preview: preview_of(record),173
preview: preview_of(record),172
mentions_me: mentions_me(record, my_user_id),174
mentions_me,173
muted: is_muted_chat(sidebar, &record.conversation_id),175
muted: is_muted_chat(sidebar, &record.conversation_id),174
signals,176
signals,175
chat,177
chat,@@ -593,6 +595,19 @@ mod tests {593
assert!(!other.unwrap().mentions_me);595
assert!(!other.unwrap().mentions_me);594
}596
}595
597
598
#[test]599
fn everyone_in_a_group_chat_counts_as_a_mention_but_a_channel_mention_does_not() {600
let store = Store::open_in_memory().unwrap();601
let mut message = record("group", "u1", Utc::now(), "<at>Everyone</at>");602
message.mentions_json =603
r#"[{"user_id":null,"name":"Everyone","target_id":"group","group":true}]"#.into();604
assert!(collect_one(message, &store).mentions_me);605
let mut post = record("channel-open", "u1", Utc::now(), "<at>channel</at>");606
post.mentions_json =607
r#"[{"user_id":null,"name":"channel","target_id":"channel-open","group":true}]"#.into();608
assert!(!collect_one(post, &store).mentions_me);609
}610
596
#[test]611
#[test]597
fn unknown_conversation_yields_nothing() {612
fn unknown_conversation_yields_nothing() {598
let message = record("nowhere", "u1", Utc::now(), "x");613
let message = record("nowhere", "u1", Utc::now(), "x");@@ -55,6 +55,7 @@ use super::fun_picker::{FunPicker, FunPickerEvent};
55
55
use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_join_chip};
56
56
use super::widgets::{icon, symbol};
57
57
use crate::app_state::AppState;
58
use crate::data::Directory;
58
59
use crate::emoji;
59
60
pub use crate::outgoing::{EditPreview, Outgoing, ReplyPreview};
60
61
use crate::remote_image::RemoteImage;
@@ -302,9 +303,36 @@ fn candidate_subtitle(candidate: &MentionCandidate) -> String {
302
303
.unwrap_or_default(),
303
304
MentionCandidate::Channel { .. } => "Channel".to_owned(),
304
305
MentionCandidate::Team { .. } => "Team".to_owned(),
306
MentionCandidate::Tag { .. } => "Tag".to_owned(),
307
MentionCandidate::Everyone { .. } => String::new(),
305
308
}
306
309
}
307
310
311
fn candidate_avatar(candidate: &MentionCandidate, directory: &Directory) -> AnyElement {
312
let name = candidate.display_name();
313
match candidate {
314
MentionCandidate::Person(person) => {
315
person_avatar(directory, Some(&person.user_id), name, 28.)
316
}
317
MentionCandidate::Everyone { .. } => symbol_avatar("group", 28., 14.),
318
MentionCandidate::Tag { .. } => symbol_avatar("tag", 28., 7.),
319
other => square_avatar(name, candidate_key(other), 28., 7.).into_any_element(),
320
}
321
}
322
323
fn symbol_avatar(symbol_name: &str, size: f32, radius: f32) -> AnyElement {
324
div()
325
.size(px(size))
326
.flex_none()
327
.flex()
328
.items_center()
329
.justify_center()
330
.rounded(px(radius))
331
.bg(theme::surface_raised())
332
.child(symbol(symbol_name, 16., theme::text()))
333
.into_any_element()
334
}
335
308
336
fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {
309
337
if let Some(typed) = emoji::typed_char(previous, value, cursor).filter(|typed| *typed != '\n') {
310
338
return StepKind::Typing {
@@ -370,6 +398,8 @@ fn candidate_key(candidate: &MentionCandidate) -> &str {
370
398
MentionCandidate::Person(person) => &person.user_id,
371
399
MentionCandidate::Channel { channel_id, .. } => channel_id,
372
400
MentionCandidate::Team { team_id, .. } => team_id,
401
MentionCandidate::Everyone { chat_id } => chat_id,
402
MentionCandidate::Tag { tag_id, .. } => tag_id,
373
403
}
374
404
}
375
405
@@ -2354,12 +2384,7 @@ impl Composer {
2354
2384
.enumerate()
2355
2385
.map(|(index, candidate)| {
2356
2386
let name = candidate.display_name().to_owned();
2357
let avatar = match candidate {
2358
MentionCandidate::Person(person) => {
2359
person_avatar(directory, Some(&person.user_id), &name, 28.)
2360
}
2361
other => square_avatar(&name, candidate_key(other), 28., 7.).into_any_element(),
2362
};
2387
let avatar = candidate_avatar(candidate, directory);
2363
2388
let subtitle = candidate_subtitle(candidate);
2364
2389
h_flex()
2365
2390
.id(ElementId::Name(format!("mention-row-{index}").into()))
@@ -55,6 +55,7 @@ use super::fun_picker::{FunPicker, FunPickerEvent};55
use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_join_chip};55
use super::link_preview::{ComposeLink, draft_link, link_preview_card, meeting_join_chip};56
use super::widgets::{icon, symbol};56
use super::widgets::{icon, symbol};57
use crate::app_state::AppState;57
use crate::app_state::AppState;58
use crate::data::Directory;58
use crate::emoji;59
use crate::emoji;59
pub use crate::outgoing::{EditPreview, Outgoing, ReplyPreview};60
pub use crate::outgoing::{EditPreview, Outgoing, ReplyPreview};60
use crate::remote_image::RemoteImage;61
use crate::remote_image::RemoteImage;@@ -302,9 +303,36 @@ fn candidate_subtitle(candidate: &MentionCandidate) -> String {302
.unwrap_or_default(),303
.unwrap_or_default(),303
MentionCandidate::Channel { .. } => "Channel".to_owned(),304
MentionCandidate::Channel { .. } => "Channel".to_owned(),304
MentionCandidate::Team { .. } => "Team".to_owned(),305
MentionCandidate::Team { .. } => "Team".to_owned(),306
MentionCandidate::Tag { .. } => "Tag".to_owned(),307
MentionCandidate::Everyone { .. } => String::new(),305
}308
}306
}309
}307
310
311
fn candidate_avatar(candidate: &MentionCandidate, directory: &Directory) -> AnyElement {312
let name = candidate.display_name();313
match candidate {314
MentionCandidate::Person(person) => {315
person_avatar(directory, Some(&person.user_id), name, 28.)316
}317
MentionCandidate::Everyone { .. } => symbol_avatar("group", 28., 14.),318
MentionCandidate::Tag { .. } => symbol_avatar("tag", 28., 7.),319
other => square_avatar(name, candidate_key(other), 28., 7.).into_any_element(),320
}321
}322
323
fn symbol_avatar(symbol_name: &str, size: f32, radius: f32) -> AnyElement {324
div()325
.size(px(size))326
.flex_none()327
.flex()328
.items_center()329
.justify_center()330
.rounded(px(radius))331
.bg(theme::surface_raised())332
.child(symbol(symbol_name, 16., theme::text()))333
.into_any_element()334
}335
308
fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {336
fn step_kind(previous: &str, value: &str, cursor: usize) -> StepKind {309
if let Some(typed) = emoji::typed_char(previous, value, cursor).filter(|typed| *typed != '\n') {337
if let Some(typed) = emoji::typed_char(previous, value, cursor).filter(|typed| *typed != '\n') {310
return StepKind::Typing {338
return StepKind::Typing {@@ -370,6 +398,8 @@ fn candidate_key(candidate: &MentionCandidate) -> &str {370
MentionCandidate::Person(person) => &person.user_id,398
MentionCandidate::Person(person) => &person.user_id,371
MentionCandidate::Channel { channel_id, .. } => channel_id,399
MentionCandidate::Channel { channel_id, .. } => channel_id,372
MentionCandidate::Team { team_id, .. } => team_id,400
MentionCandidate::Team { team_id, .. } => team_id,401
MentionCandidate::Everyone { chat_id } => chat_id,402
MentionCandidate::Tag { tag_id, .. } => tag_id,373
}403
}374
}404
}375
405
@@ -2354,12 +2384,7 @@ impl Composer {2354
.enumerate()2384
.enumerate()2355
.map(|(index, candidate)| {2385
.map(|(index, candidate)| {2356
let name = candidate.display_name().to_owned();2386
let name = candidate.display_name().to_owned();2357
let avatar = match candidate {2387
let avatar = candidate_avatar(candidate, directory);2358
MentionCandidate::Person(person) => {2359
person_avatar(directory, Some(&person.user_id), &name, 28.)2360
}2361
other => square_avatar(&name, candidate_key(other), 28., 7.).into_any_element(),2362
};2363
let subtitle = candidate_subtitle(candidate);2388
let subtitle = candidate_subtitle(candidate);2364
h_flex()2389
h_flex()2365
.id(ElementId::Name(format!("mention-row-{index}").into()))2390
.id(ElementId::Name(format!("mention-row-{index}").into()))@@ -14,7 +14,7 @@ use crate::events::CoreEvent;
14
14
use crate::folders::FolderSource;
15
15
use crate::links::{LinkPreview, has_stored_links};
16
16
use crate::mapping::{flatten_thread, message_record};
17
use crate::people::DirectoryCache;
17
use crate::people::{DirectoryCache, TagCache};
18
18
use crate::presence::Presence;
19
19
use crate::preview::OwnedPreview;
20
20
use crate::receipts::ReceiptCache;
@@ -123,6 +123,7 @@ pub struct SyncEngine<R: Remote = Graph> {
123
123
pub(crate) images_in_flight: Mutex<HashSet<String>>,
124
124
pub(crate) image_files: Option<ImageFileCache>,
125
125
pub(crate) directory_cache: Mutex<DirectoryCache>,
126
pub(crate) tag_cache: Mutex<TagCache>,
126
127
preview_changed: AtomicBool,
127
128
pub(crate) receipts: ReceiptCache,
128
129
pub(crate) channel_folders: Mutex<HashMap<String, DriveFolder>>,
@@ -160,6 +161,7 @@ impl<R: Remote> SyncEngine<R> {
160
161
images_in_flight: Mutex::new(HashSet::new()),
161
162
image_files: None,
162
163
directory_cache: Mutex::new(DirectoryCache::new()),
164
tag_cache: Mutex::new(TagCache::default()),
163
165
preview_changed: AtomicBool::new(false),
164
166
receipts: ReceiptCache::default(),
165
167
channel_folders: Mutex::new(HashMap::new()),
@@ -14,7 +14,7 @@ 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::{flatten_thread, message_record};17
use crate::people::DirectoryCache;17
use crate::people::{DirectoryCache, TagCache};18
use crate::presence::Presence;18
use crate::presence::Presence;19
use crate::preview::OwnedPreview;19
use crate::preview::OwnedPreview;20
use crate::receipts::ReceiptCache;20
use crate::receipts::ReceiptCache;@@ -123,6 +123,7 @@ pub struct SyncEngine<R: Remote = Graph> {123
pub(crate) images_in_flight: Mutex<HashSet<String>>,123
pub(crate) images_in_flight: Mutex<HashSet<String>>,124
pub(crate) image_files: Option<ImageFileCache>,124
pub(crate) image_files: Option<ImageFileCache>,125
pub(crate) directory_cache: Mutex<DirectoryCache>,125
pub(crate) directory_cache: Mutex<DirectoryCache>,126
pub(crate) tag_cache: Mutex<TagCache>,126
preview_changed: AtomicBool,127
preview_changed: AtomicBool,127
pub(crate) receipts: ReceiptCache,128
pub(crate) receipts: ReceiptCache,128
pub(crate) channel_folders: Mutex<HashMap<String, DriveFolder>>,129
pub(crate) channel_folders: Mutex<HashMap<String, DriveFolder>>,@@ -160,6 +161,7 @@ impl<R: Remote> SyncEngine<R> {160
images_in_flight: Mutex::new(HashSet::new()),161
images_in_flight: Mutex::new(HashSet::new()),161
image_files: None,162
image_files: None,162
directory_cache: Mutex::new(DirectoryCache::new()),163
directory_cache: Mutex::new(DirectoryCache::new()),164
tag_cache: Mutex::new(TagCache::default()),163
preview_changed: AtomicBool::new(false),165
preview_changed: AtomicBool::new(false),164
receipts: ReceiptCache::default(),166
receipts: ReceiptCache::default(),165
channel_folders: Mutex::new(HashMap::new()),167
channel_folders: Mutex::new(HashMap::new()),@@ -157,7 +157,7 @@ pub use meeting_join::{
157
157
pub use mentions::{MentionInput, apply_mentions, plain_mention_spans};
158
158
pub use message_link::{
159
159
ChannelAddress, ChannelLinkInput, channel_link, channel_message_link, channel_tab_link,
160
chat_message_link, team_link,
160
chat_message_link, outlook_compose_link, team_link,
161
161
};
162
162
pub use message_window::{JumpPlan, WINDOW_PAGE_SIZE, WindowPage, jump_plan, without_islands};
163
163
pub use notes_chat::{is_notes_chat, notes_chat_title};
@@ -175,7 +175,7 @@ pub use stored::{
175
175
AttachmentInfo, FileCard, FileKind, ImageKind, ImageRef, MentionInfo, PROFILE_LINK_PREFIX,
176
176
QuoteInfo, ReactionInfo, ReactionSummary, adaptive_cards, attachments, can_delete, can_edit,
177
177
card_texts, copy_text, files, images, linked_message_spans, linked_message_spans_with,
178
mentions, message_quote, message_spans, quote_html, quotes, reaction_summaries, reactions,
178
mentions, mentions_whole_chat, message_quote, message_spans, quote_html, quotes, reaction_summaries, reactions,
179
179
readable_text, translated_spans, user_mention_inputs,
180
180
};
181
181
pub use table::{Cell, PICKER_COLUMNS, PICKER_ROWS, TABLE_MARK, Table, TableEdit};
@@ -157,7 +157,7 @@ pub use meeting_join::{157
pub use mentions::{MentionInput, apply_mentions, plain_mention_spans};157
pub use mentions::{MentionInput, apply_mentions, plain_mention_spans};158
pub use message_link::{158
pub use message_link::{159
ChannelAddress, ChannelLinkInput, channel_link, channel_message_link, channel_tab_link,159
ChannelAddress, ChannelLinkInput, channel_link, channel_message_link, channel_tab_link,160
chat_message_link, team_link,160
chat_message_link, outlook_compose_link, team_link,161
};161
};162
pub use message_window::{JumpPlan, WINDOW_PAGE_SIZE, WindowPage, jump_plan, without_islands};162
pub use message_window::{JumpPlan, WINDOW_PAGE_SIZE, WindowPage, jump_plan, without_islands};163
pub use notes_chat::{is_notes_chat, notes_chat_title};163
pub use notes_chat::{is_notes_chat, notes_chat_title};@@ -175,7 +175,7 @@ pub use stored::{175
AttachmentInfo, FileCard, FileKind, ImageKind, ImageRef, MentionInfo, PROFILE_LINK_PREFIX,175
AttachmentInfo, FileCard, FileKind, ImageKind, ImageRef, MentionInfo, PROFILE_LINK_PREFIX,176
QuoteInfo, ReactionInfo, ReactionSummary, adaptive_cards, attachments, can_delete, can_edit,176
QuoteInfo, ReactionInfo, ReactionSummary, adaptive_cards, attachments, can_delete, can_edit,177
card_texts, copy_text, files, images, linked_message_spans, linked_message_spans_with,177
card_texts, copy_text, files, images, linked_message_spans, linked_message_spans_with,178
mentions, message_quote, message_spans, quote_html, quotes, reaction_summaries, reactions,178
mentions, mentions_whole_chat, message_quote, message_spans, quote_html, quotes, reaction_summaries, reactions,179
readable_text, translated_spans, user_mention_inputs,179
readable_text, translated_spans, user_mention_inputs,180
};180
};181
pub use table::{Cell, PICKER_COLUMNS, PICKER_ROWS, TABLE_MARK, Table, TableEdit};181
pub use table::{Cell, PICKER_COLUMNS, PICKER_ROWS, TABLE_MARK, Table, TableEdit};@@ -41,6 +41,24 @@ impl MentionInput {
41
41
text: text.to_owned(),
42
42
}
43
43
}
44
45
pub fn everyone(chat_id: &str, text: &str) -> Self {
46
MentionInput {
47
target: MentionTarget::Everyone {
48
chat_id: chat_id.to_owned(),
49
},
50
text: text.to_owned(),
51
}
52
}
53
54
pub fn tag(tag_id: &str, text: &str) -> Self {
55
MentionInput {
56
target: MentionTarget::Tag {
57
tag_id: tag_id.to_owned(),
58
},
59
text: text.to_owned(),
60
}
61
}
44
62
}
45
63
46
64
fn same_char(expected: char, actual: char, ignore_case: bool) -> bool {
@@ -244,11 +262,15 @@ pub fn apply_mentions(html: &str, inputs: &[MentionInput]) -> (String, Vec<Outgo
244
262
}
245
263
246
264
pub(crate) fn ensure_allowed_in_chat(inputs: &[MentionInput]) -> Result<()> {
247
if inputs
248
.iter()
249
.any(|input| !matches!(input.target, MentionTarget::User { .. }))
250
{
251
return Err(Error::Unsupported("a channel or team mention in a chat"));
265
if inputs.iter().any(|input| {
266
!matches!(
267
input.target,
268
MentionTarget::User { .. } | MentionTarget::Everyone { .. }
269
)
270
}) {
271
return Err(Error::Unsupported(
272
"a channel, team or tag mention in a chat",
273
));
252
274
}
253
275
Ok(())
254
276
}
@@ -416,6 +438,8 @@ mod tests {
416
438
#[test]
417
439
fn chats_only_take_user_mentions() {
418
440
assert!(ensure_allowed_in_chat(&[MentionInput::user("u", "A")]).is_ok());
441
assert!(ensure_allowed_in_chat(&[MentionInput::everyone("19:g", "Everyone")]).is_ok());
419
442
assert!(ensure_allowed_in_chat(&[MentionInput::team("t", "Squad")]).is_err());
443
assert!(ensure_allowed_in_chat(&[MentionInput::tag("tag-1", "Design")]).is_err());
420
444
}
421
445
}
@@ -41,6 +41,24 @@ impl MentionInput {41
text: text.to_owned(),41
text: text.to_owned(),42
}42
}43
}43
}44
45
pub fn everyone(chat_id: &str, text: &str) -> Self {46
MentionInput {47
target: MentionTarget::Everyone {48
chat_id: chat_id.to_owned(),49
},50
text: text.to_owned(),51
}52
}53
54
pub fn tag(tag_id: &str, text: &str) -> Self {55
MentionInput {56
target: MentionTarget::Tag {57
tag_id: tag_id.to_owned(),58
},59
text: text.to_owned(),60
}61
}44
}62
}45
63
46
fn same_char(expected: char, actual: char, ignore_case: bool) -> bool {64
fn same_char(expected: char, actual: char, ignore_case: bool) -> bool {@@ -244,11 +262,15 @@ pub fn apply_mentions(html: &str, inputs: &[MentionInput]) -> (String, Vec<Outgo244
}262
}245
263
246
pub(crate) fn ensure_allowed_in_chat(inputs: &[MentionInput]) -> Result<()> {264
pub(crate) fn ensure_allowed_in_chat(inputs: &[MentionInput]) -> Result<()> {247
if inputs265
if inputs.iter().any(|input| {248
.iter()266
!matches!(249
.any(|input| !matches!(input.target, MentionTarget::User { .. }))267
input.target,250
{268
MentionTarget::User { .. } | MentionTarget::Everyone { .. }251
return Err(Error::Unsupported("a channel or team mention in a chat"));269
)270
}) {271
return Err(Error::Unsupported(272
"a channel, team or tag mention in a chat",273
));252
}274
}253
Ok(())275
Ok(())254
}276
}@@ -416,6 +438,8 @@ mod tests {416
#[test]438
#[test]417
fn chats_only_take_user_mentions() {439
fn chats_only_take_user_mentions() {418
assert!(ensure_allowed_in_chat(&[MentionInput::user("u", "A")]).is_ok());440
assert!(ensure_allowed_in_chat(&[MentionInput::user("u", "A")]).is_ok());441
assert!(ensure_allowed_in_chat(&[MentionInput::everyone("19:g", "Everyone")]).is_ok());419
assert!(ensure_allowed_in_chat(&[MentionInput::team("t", "Squad")]).is_err());442
assert!(ensure_allowed_in_chat(&[MentionInput::team("t", "Squad")]).is_err());443
assert!(ensure_allowed_in_chat(&[MentionInput::tag("tag-1", "Design")]).is_err());420
}444
}421
}445
}@@ -3,6 +3,7 @@ use serde_json::json;
3
3
4
4
const LINK_HOST: &str = "https://teams.microsoft.com";
5
5
const DEEP_LINK_HOST: &str = "https://teams.cloud.microsoft";
6
const OUTLOOK_COMPOSE: &str = "https://outlook.office.com/mail/deeplink/compose";
6
7
7
8
const ENCODE_COMPONENT: &AsciiSet = &NON_ALPHANUMERIC
8
9
.remove(b'-')
@@ -31,6 +32,15 @@ fn encode(value: &str) -> String {
31
32
utf8_percent_encode(value, ENCODE_COMPONENT).to_string()
32
33
}
33
34
35
/// Outlook on the web opens a new mail with this subject and plain text body; nothing is sent.
36
pub fn outlook_compose_link(subject: &str, body: &str) -> String {
37
format!(
38
"{OUTLOOK_COMPOSE}?subject={}&body={}",
39
encode(subject),
40
encode(body)
41
)
42
}
43
34
44
/// `notes_oid` is the own object id, needed for the notes chat only.
35
45
pub fn chat_message_link(
36
46
conversation_id: &str,
@@ -113,6 +123,14 @@ mod tests {
113
123
);
114
124
}
115
125
126
#[test]
127
fn outlook_compose_link_encodes_subject_and_body() {
128
assert_eq!(
129
outlook_compose_link("Release & plan", "Ada\nhi there"),
130
"https://outlook.office.com/mail/deeplink/compose?subject=Release%20%26%20plan&body=Ada%0Ahi%20there"
131
);
132
}
133
116
134
#[test]
117
135
fn notes_link_carries_the_object_id() {
118
136
assert_eq!(
@@ -3,6 +3,7 @@ use serde_json::json;3
3
4
const LINK_HOST: &str = "https://teams.microsoft.com";4
const LINK_HOST: &str = "https://teams.microsoft.com";5
const DEEP_LINK_HOST: &str = "https://teams.cloud.microsoft";5
const DEEP_LINK_HOST: &str = "https://teams.cloud.microsoft";6
const OUTLOOK_COMPOSE: &str = "https://outlook.office.com/mail/deeplink/compose";6
7
7
const ENCODE_COMPONENT: &AsciiSet = &NON_ALPHANUMERIC8
const ENCODE_COMPONENT: &AsciiSet = &NON_ALPHANUMERIC8
.remove(b'-')9
.remove(b'-')@@ -31,6 +32,15 @@ fn encode(value: &str) -> String {31
utf8_percent_encode(value, ENCODE_COMPONENT).to_string()32
utf8_percent_encode(value, ENCODE_COMPONENT).to_string()32
}33
}33
34
35
/// Outlook on the web opens a new mail with this subject and plain text body; nothing is sent.36
pub fn outlook_compose_link(subject: &str, body: &str) -> String {37
format!(38
"{OUTLOOK_COMPOSE}?subject={}&body={}",39
encode(subject),40
encode(body)41
)42
}43
34
/// `notes_oid` is the own object id, needed for the notes chat only.44
/// `notes_oid` is the own object id, needed for the notes chat only.35
pub fn chat_message_link(45
pub fn chat_message_link(36
conversation_id: &str,46
conversation_id: &str,@@ -113,6 +123,14 @@ mod tests {113
);123
);114
}124
}115
125
126
#[test]127
fn outlook_compose_link_encodes_subject_and_body() {128
assert_eq!(129
outlook_compose_link("Release & plan", "Ada\nhi there"),130
"https://outlook.office.com/mail/deeplink/compose?subject=Release%20%26%20plan&body=Ada%0Ahi%20there"131
);132
}133
116
#[test]134
#[test]117
fn notes_link_carries_the_object_id() {135
fn notes_link_carries_the_object_id() {118
assert_eq!(136
assert_eq!(@@ -1,7 +1,7 @@
1
1
use std::collections::HashSet;
2
2
use std::time::{Duration, Instant};
3
3
4
use graph::User;
4
use graph::{Tag, User};
5
5
6
6
use crate::engine::{Conversation, META_USER_ID, SyncEngine};
7
7
use crate::error::Result;
@@ -11,6 +11,9 @@ const DIRECTORY_CACHE_TTL: Duration = Duration::from_secs(300);
11
11
const DIRECTORY_CACHE_MAX_QUERIES: usize = 64;
12
12
const DIRECTORY_MIN_QUERY_CHARS: usize = 2;
13
13
const RECENT_SENDERS_SCANNED: usize = 200;
14
const TAG_CACHE_TTL: Duration = Duration::from_secs(300);
15
const GROUP_CHAT_KIND: &str = "group";
16
pub const EVERYONE_MENTION_TEXT: &str = "Everyone";
14
17
15
18
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16
19
pub enum PersonSource {
@@ -30,15 +33,32 @@ pub struct PersonCandidate {
30
33
#[derive(Debug, Clone, PartialEq, Eq)]
31
34
pub enum MentionCandidate {
32
35
Person(PersonCandidate),
33
Channel { channel_id: String, name: String },
34
Team { team_id: String, name: String },
36
Channel {
37
channel_id: String,
38
name: String,
39
},
40
Team {
41
team_id: String,
42
name: String,
43
},
44
Everyone {
45
chat_id: String,
46
},
47
Tag {
48
tag_id: String,
49
name: String,
50
member_count: Option<u32>,
51
},
35
52
}
36
53
37
54
impl MentionCandidate {
38
55
pub fn display_name(&self) -> &str {
39
56
match self {
40
57
MentionCandidate::Person(person) => &person.display_name,
41
MentionCandidate::Channel { name, .. } | MentionCandidate::Team { name, .. } => name,
58
MentionCandidate::Channel { name, .. }
59
| MentionCandidate::Team { name, .. }
60
| MentionCandidate::Tag { name, .. } => name,
61
MentionCandidate::Everyone { .. } => EVERYONE_MENTION_TEXT,
42
62
}
43
63
}
44
64
@@ -52,10 +72,31 @@ impl MentionCandidate {
52
72
crate::MentionInput::channel(channel_id, name)
53
73
}
54
74
MentionCandidate::Team { team_id, name } => crate::MentionInput::team(team_id, name),
75
MentionCandidate::Everyone { chat_id } => {
76
crate::MentionInput::everyone(chat_id, EVERYONE_MENTION_TEXT)
77
}
78
MentionCandidate::Tag { tag_id, name, .. } => crate::MentionInput::tag(tag_id, name),
55
79
}
56
80
}
57
81
}
58
82
83
#[derive(Default)]
84
pub(crate) struct TagCache {
85
entries: std::collections::HashMap<String, (Instant, Vec<Tag>)>,
86
}
87
88
impl TagCache {
89
fn get(&self, team_id: &str) -> Option<Vec<Tag>> {
90
let (stored_at, tags) = self.entries.get(team_id)?;
91
(stored_at.elapsed() < TAG_CACHE_TTL).then(|| tags.clone())
92
}
93
94
fn put(&mut self, team_id: &str, tags: Vec<Tag>) {
95
self.entries
96
.insert(team_id.to_owned(), (Instant::now(), tags));
97
}
98
}
99
59
100
pub(crate) struct DirectoryCache {
60
101
entries: std::collections::HashMap<String, (Instant, Vec<User>)>,
61
102
}
@@ -97,8 +138,19 @@ impl<R: Remote> SyncEngine<R> {
97
138
Ok(users)
98
139
}
99
140
100
/// Autocomplete for `@`: members of the conversation first, then (channels) the channel and its team,
101
/// then the directory. A failing directory search still returns the local part.
141
/// The team's tags, cached in memory for five minutes per team; a failed load is cached as no tags.
142
pub async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> {
143
if let Some(cached) = self.tag_lock().get(team_id) {
144
return Ok(cached);
145
}
146
let tags = self.remote.team_tags(team_id).await;
147
self.tag_lock()
148
.put(team_id, tags.as_ref().cloned().unwrap_or_default());
149
tags
150
}
151
152
/// Autocomplete for `@`: Everyone in a group chat, members of the conversation, then (channels) the channel,
153
/// its team and the team's tags, then the directory. A failing tag or directory lookup still returns the local part.
102
154
pub async fn mention_candidates(
103
155
&self,
104
156
conversation_id: &str,
@@ -110,18 +162,23 @@ impl<R: Remote> SyncEngine<R> {
110
162
let my_user_id = self.store.meta(META_USER_ID)?.unwrap_or_default();
111
163
let mut seen: HashSet<String> = HashSet::from([my_user_id]);
112
164
113
let mut candidates: Vec<MentionCandidate> = ranked(
165
let mut candidates: Vec<MentionCandidate> =
166
ranked(self.everyone_entry(conversation_id)?.into_iter(), &query);
167
candidates.extend(ranked(
114
168
self.local_people(conversation_id)?
115
169
.into_iter()
116
170
.filter(|person| seen.insert(person.user_id.clone()))
117
171
.map(MentionCandidate::Person),
118
172
&query,
119
);
173
));
120
174
if let Conversation::Channel { team_id } = &conversation {
121
175
candidates.extend(ranked(
122
176
self.scope_entries(conversation_id, team_id)?,
123
177
&query,
124
178
));
179
if let Ok(tags) = self.team_tags(team_id).await {
180
candidates.extend(ranked(tags.into_iter().map(tag_candidate), &query));
181
}
125
182
}
126
183
let local_people = candidates
127
184
.iter()
@@ -172,6 +229,14 @@ impl<R: Remote> SyncEngine<R> {
172
229
.collect())
173
230
}
174
231
232
fn everyone_entry(&self, conversation_id: &str) -> Result<Option<MentionCandidate>> {
233
Ok(self
234
.store
235
.chat(conversation_id)?
236
.filter(|chat| chat.kind.eq_ignore_ascii_case(GROUP_CHAT_KIND))
237
.map(|chat| MentionCandidate::Everyone { chat_id: chat.id }))
238
}
239
175
240
fn scope_entries(
176
241
&self,
177
242
channel_id: &str,
@@ -194,6 +259,12 @@ impl<R: Remote> SyncEngine<R> {
194
259
Ok(channel.into_iter().chain(team))
195
260
}
196
261
262
fn tag_lock(&self) -> std::sync::MutexGuard<'_, TagCache> {
263
self.tag_cache
264
.lock()
265
.unwrap_or_else(|poisoned| poisoned.into_inner())
266
}
267
197
268
fn directory_lock(&self) -> std::sync::MutexGuard<'_, DirectoryCache> {
198
269
self.directory_cache
199
270
.lock()
@@ -201,6 +272,14 @@ impl<R: Remote> SyncEngine<R> {
201
272
}
202
273
}
203
274
275
fn tag_candidate(tag: Tag) -> MentionCandidate {
276
MentionCandidate::Tag {
277
tag_id: tag.id,
278
name: tag.display_name,
279
member_count: tag.member_count,
280
}
281
}
282
204
283
fn directory_person(user: User) -> PersonCandidate {
205
284
PersonCandidate {
206
285
display_name: user
@@ -323,6 +402,32 @@ mod tests {
323
402
name: "Squad".to_owned(),
324
403
};
325
404
assert_eq!(team.to_mention(), crate::MentionInput::team("t", "Squad"));
405
let everyone = MentionCandidate::Everyone {
406
chat_id: "19:g".to_owned(),
407
};
408
assert_eq!(
409
everyone.to_mention(),
410
crate::MentionInput::everyone("19:g", "Everyone")
411
);
412
let tag = MentionCandidate::Tag {
413
tag_id: "tag-1".to_owned(),
414
name: "Design".to_owned(),
415
member_count: Some(3),
416
};
417
assert_eq!(
418
tag.to_mention(),
419
crate::MentionInput::tag("tag-1", "Design")
420
);
421
}
422
423
#[test]
424
fn everyone_matches_its_name_like_any_candidate() {
425
let everyone = || MentionCandidate::Everyone {
426
chat_id: "19:g".to_owned(),
427
};
428
assert_eq!(ranked([everyone()].into_iter(), "ev").len(), 1);
429
assert_eq!(ranked([everyone()].into_iter(), "").len(), 1);
430
assert!(ranked([everyone()].into_iter(), "ada").is_empty());
326
431
}
327
432
328
433
#[test]
@@ -1,7 +1,7 @@1
use std::collections::HashSet;1
use std::collections::HashSet;2
use std::time::{Duration, Instant};2
use std::time::{Duration, Instant};3
3
4
use graph::User;4
use graph::{Tag, User};5
5
6
use crate::engine::{Conversation, META_USER_ID, SyncEngine};6
use crate::engine::{Conversation, META_USER_ID, SyncEngine};7
use crate::error::Result;7
use crate::error::Result;@@ -11,6 +11,9 @@ const DIRECTORY_CACHE_TTL: Duration = Duration::from_secs(300);11
const DIRECTORY_CACHE_MAX_QUERIES: usize = 64;11
const DIRECTORY_CACHE_MAX_QUERIES: usize = 64;12
const DIRECTORY_MIN_QUERY_CHARS: usize = 2;12
const DIRECTORY_MIN_QUERY_CHARS: usize = 2;13
const RECENT_SENDERS_SCANNED: usize = 200;13
const RECENT_SENDERS_SCANNED: usize = 200;14
const TAG_CACHE_TTL: Duration = Duration::from_secs(300);15
const GROUP_CHAT_KIND: &str = "group";16
pub const EVERYONE_MENTION_TEXT: &str = "Everyone";14
17
15
#[derive(Debug, Clone, Copy, PartialEq, Eq)]18
#[derive(Debug, Clone, Copy, PartialEq, Eq)]16
pub enum PersonSource {19
pub enum PersonSource {@@ -30,15 +33,32 @@ pub struct PersonCandidate {30
#[derive(Debug, Clone, PartialEq, Eq)]33
#[derive(Debug, Clone, PartialEq, Eq)]31
pub enum MentionCandidate {34
pub enum MentionCandidate {32
Person(PersonCandidate),35
Person(PersonCandidate),33
Channel { channel_id: String, name: String },36
Channel {34
Team { team_id: String, name: String },37
channel_id: String,38
name: String,39
},40
Team {41
team_id: String,42
name: String,43
},44
Everyone {45
chat_id: String,46
},47
Tag {48
tag_id: String,49
name: String,50
member_count: Option<u32>,51
},35
}52
}36
53
37
impl MentionCandidate {54
impl MentionCandidate {38
pub fn display_name(&self) -> &str {55
pub fn display_name(&self) -> &str {39
match self {56
match self {40
MentionCandidate::Person(person) => &person.display_name,57
MentionCandidate::Person(person) => &person.display_name,41
MentionCandidate::Channel { name, .. } | MentionCandidate::Team { name, .. } => name,58
MentionCandidate::Channel { name, .. }59
| MentionCandidate::Team { name, .. }60
| MentionCandidate::Tag { name, .. } => name,61
MentionCandidate::Everyone { .. } => EVERYONE_MENTION_TEXT,42
}62
}43
}63
}44
64
@@ -52,10 +72,31 @@ impl MentionCandidate {52
crate::MentionInput::channel(channel_id, name)72
crate::MentionInput::channel(channel_id, name)53
}73
}54
MentionCandidate::Team { team_id, name } => crate::MentionInput::team(team_id, name),74
MentionCandidate::Team { team_id, name } => crate::MentionInput::team(team_id, name),75
MentionCandidate::Everyone { chat_id } => {76
crate::MentionInput::everyone(chat_id, EVERYONE_MENTION_TEXT)77
}78
MentionCandidate::Tag { tag_id, name, .. } => crate::MentionInput::tag(tag_id, name),55
}79
}56
}80
}57
}81
}58
82
83
#[derive(Default)]84
pub(crate) struct TagCache {85
entries: std::collections::HashMap<String, (Instant, Vec<Tag>)>,86
}87
88
impl TagCache {89
fn get(&self, team_id: &str) -> Option<Vec<Tag>> {90
let (stored_at, tags) = self.entries.get(team_id)?;91
(stored_at.elapsed() < TAG_CACHE_TTL).then(|| tags.clone())92
}93
94
fn put(&mut self, team_id: &str, tags: Vec<Tag>) {95
self.entries96
.insert(team_id.to_owned(), (Instant::now(), tags));97
}98
}99
59
pub(crate) struct DirectoryCache {100
pub(crate) struct DirectoryCache {60
entries: std::collections::HashMap<String, (Instant, Vec<User>)>,101
entries: std::collections::HashMap<String, (Instant, Vec<User>)>,61
}102
}@@ -97,8 +138,19 @@ impl<R: Remote> SyncEngine<R> {97
Ok(users)138
Ok(users)98
}139
}99
140
100
/// Autocomplete for `@`: members of the conversation first, then (channels) the channel and its team,141
/// The team's tags, cached in memory for five minutes per team; a failed load is cached as no tags.101
/// then the directory. A failing directory search still returns the local part.142
pub async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> {143
if let Some(cached) = self.tag_lock().get(team_id) {144
return Ok(cached);145
}146
let tags = self.remote.team_tags(team_id).await;147
self.tag_lock()148
.put(team_id, tags.as_ref().cloned().unwrap_or_default());149
tags150
}151
152
/// Autocomplete for `@`: Everyone in a group chat, members of the conversation, then (channels) the channel,153
/// its team and the team's tags, then the directory. A failing tag or directory lookup still returns the local part.102
pub async fn mention_candidates(154
pub async fn mention_candidates(103
&self,155
&self,104
conversation_id: &str,156
conversation_id: &str,@@ -110,18 +162,23 @@ impl<R: Remote> SyncEngine<R> {110
let my_user_id = self.store.meta(META_USER_ID)?.unwrap_or_default();162
let my_user_id = self.store.meta(META_USER_ID)?.unwrap_or_default();111
let mut seen: HashSet<String> = HashSet::from([my_user_id]);163
let mut seen: HashSet<String> = HashSet::from([my_user_id]);112
164
113
let mut candidates: Vec<MentionCandidate> = ranked(165
let mut candidates: Vec<MentionCandidate> =166
ranked(self.everyone_entry(conversation_id)?.into_iter(), &query);167
candidates.extend(ranked(114
self.local_people(conversation_id)?168
self.local_people(conversation_id)?115
.into_iter()169
.into_iter()116
.filter(|person| seen.insert(person.user_id.clone()))170
.filter(|person| seen.insert(person.user_id.clone()))117
.map(MentionCandidate::Person),171
.map(MentionCandidate::Person),118
&query,172
&query,119
);173
));120
if let Conversation::Channel { team_id } = &conversation {174
if let Conversation::Channel { team_id } = &conversation {121
candidates.extend(ranked(175
candidates.extend(ranked(122
self.scope_entries(conversation_id, team_id)?,176
self.scope_entries(conversation_id, team_id)?,123
&query,177
&query,124
));178
));179
if let Ok(tags) = self.team_tags(team_id).await {180
candidates.extend(ranked(tags.into_iter().map(tag_candidate), &query));181
}125
}182
}126
let local_people = candidates183
let local_people = candidates127
.iter()184
.iter()@@ -172,6 +229,14 @@ impl<R: Remote> SyncEngine<R> {172
.collect())229
.collect())173
}230
}174
231
232
fn everyone_entry(&self, conversation_id: &str) -> Result<Option<MentionCandidate>> {233
Ok(self234
.store235
.chat(conversation_id)?236
.filter(|chat| chat.kind.eq_ignore_ascii_case(GROUP_CHAT_KIND))237
.map(|chat| MentionCandidate::Everyone { chat_id: chat.id }))238
}239
175
fn scope_entries(240
fn scope_entries(176
&self,241
&self,177
channel_id: &str,242
channel_id: &str,@@ -194,6 +259,12 @@ impl<R: Remote> SyncEngine<R> {194
Ok(channel.into_iter().chain(team))259
Ok(channel.into_iter().chain(team))195
}260
}196
261
262
fn tag_lock(&self) -> std::sync::MutexGuard<'_, TagCache> {263
self.tag_cache264
.lock()265
.unwrap_or_else(|poisoned| poisoned.into_inner())266
}267
197
fn directory_lock(&self) -> std::sync::MutexGuard<'_, DirectoryCache> {268
fn directory_lock(&self) -> std::sync::MutexGuard<'_, DirectoryCache> {198
self.directory_cache269
self.directory_cache199
.lock()270
.lock()@@ -201,6 +272,14 @@ impl<R: Remote> SyncEngine<R> {201
}272
}202
}273
}203
274
275
fn tag_candidate(tag: Tag) -> MentionCandidate {276
MentionCandidate::Tag {277
tag_id: tag.id,278
name: tag.display_name,279
member_count: tag.member_count,280
}281
}282
204
fn directory_person(user: User) -> PersonCandidate {283
fn directory_person(user: User) -> PersonCandidate {205
PersonCandidate {284
PersonCandidate {206
display_name: user285
display_name: user@@ -323,6 +402,32 @@ mod tests {323
name: "Squad".to_owned(),402
name: "Squad".to_owned(),324
};403
};325
assert_eq!(team.to_mention(), crate::MentionInput::team("t", "Squad"));404
assert_eq!(team.to_mention(), crate::MentionInput::team("t", "Squad"));405
let everyone = MentionCandidate::Everyone {406
chat_id: "19:g".to_owned(),407
};408
assert_eq!(409
everyone.to_mention(),410
crate::MentionInput::everyone("19:g", "Everyone")411
);412
let tag = MentionCandidate::Tag {413
tag_id: "tag-1".to_owned(),414
name: "Design".to_owned(),415
member_count: Some(3),416
};417
assert_eq!(418
tag.to_mention(),419
crate::MentionInput::tag("tag-1", "Design")420
);421
}422
423
#[test]424
fn everyone_matches_its_name_like_any_candidate() {425
let everyone = || MentionCandidate::Everyone {426
chat_id: "19:g".to_owned(),427
};428
assert_eq!(ranked([everyone()].into_iter(), "ev").len(), 1);429
assert_eq!(ranked([everyone()].into_iter(), "").len(), 1);430
assert!(ranked([everyone()].into_iter(), "ada").is_empty());326
}431
}327
432
328
#[test]433
#[test]@@ -20,7 +20,7 @@ use chatsvc::{
20
20
use chrono::{DateTime, Utc};
21
21
use graph::{
22
22
Channel, Chat, DriveEntry, DriveFolder, Graph, Member, Message, MessageExtras, MessageTarget,
23
OutgoingMention, Photo, Presence, SharedFile, Team, UploadDestination, UploadedFile, User,
23
OutgoingMention, Photo, Presence, SharedFile, Tag, Team, UploadDestination, UploadedFile, User,
24
24
};
25
25
26
26
use crate::error::{Error, Result};
@@ -181,6 +181,10 @@ pub trait Remote {
181
181
) -> Result<Chat>;
182
182
async fn search_people(&self, query: &str) -> Result<Vec<User>>;
183
183
184
async fn team_tags(&self, _team_id: &str) -> Result<Vec<Tag>> {
185
Err(Error::Unsupported("team tags"))
186
}
187
184
188
async fn reply_with_quote(
185
189
&self,
186
190
_chat_id: &str,
@@ -917,6 +921,10 @@ impl Remote for Graph {
917
921
Ok(Graph::search_people(self, query).await?)
918
922
}
919
923
924
async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> {
925
Ok(Graph::team_tags(self, team_id).await?)
926
}
927
920
928
async fn reply_with_quote(
921
929
&self,
922
930
chat_id: &str,
@@ -20,7 +20,7 @@ use chatsvc::{20
use chrono::{DateTime, Utc};20
use chrono::{DateTime, Utc};21
use graph::{21
use graph::{22
Channel, Chat, DriveEntry, DriveFolder, Graph, Member, Message, MessageExtras, MessageTarget,22
Channel, Chat, DriveEntry, DriveFolder, Graph, Member, Message, MessageExtras, MessageTarget,23
OutgoingMention, Photo, Presence, SharedFile, Team, UploadDestination, UploadedFile, User,23
OutgoingMention, Photo, Presence, SharedFile, Tag, Team, UploadDestination, UploadedFile, User,24
};24
};25
25
26
use crate::error::{Error, Result};26
use crate::error::{Error, Result};@@ -181,6 +181,10 @@ pub trait Remote {181
) -> Result<Chat>;181
) -> Result<Chat>;182
async fn search_people(&self, query: &str) -> Result<Vec<User>>;182
async fn search_people(&self, query: &str) -> Result<Vec<User>>;183
183
184
async fn team_tags(&self, _team_id: &str) -> Result<Vec<Tag>> {185
Err(Error::Unsupported("team tags"))186
}187
184
async fn reply_with_quote(188
async fn reply_with_quote(185
&self,189
&self,186
_chat_id: &str,190
_chat_id: &str,@@ -917,6 +921,10 @@ impl Remote for Graph {917
Ok(Graph::search_people(self, query).await?)921
Ok(Graph::search_people(self, query).await?)918
}922
}919
923
924
async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> {925
Ok(Graph::team_tags(self, team_id).await?)926
}927
920
async fn reply_with_quote(928
async fn reply_with_quote(921
&self,929
&self,922
chat_id: &str,930
chat_id: &str,@@ -208,6 +208,13 @@ pub fn mentions(record: &MessageRecord) -> Vec<MentionInfo> {
208
208
infos
209
209
}
210
210
211
/// An @Everyone of a group chat: Graph names the chat itself as the mentioned conversation. Only meaningful in chats, a channel mention looks the same in its channel.
212
pub fn mentions_whole_chat(record: &MessageRecord) -> bool {
213
mentions(record).iter().any(|mention| {
214
mention.group && mention.target_id.as_deref() == Some(record.conversation_id.as_str())
215
})
216
}
217
211
218
pub fn quotes(record: &MessageRecord) -> Vec<QuoteInfo> {
212
219
attachments(record)
213
220
.into_iter()
@@ -208,6 +208,13 @@ pub fn mentions(record: &MessageRecord) -> Vec<MentionInfo> {208
infos208
infos209
}209
}210
210
211
/// An @Everyone of a group chat: Graph names the chat itself as the mentioned conversation. Only meaningful in chats, a channel mention looks the same in its channel.212
pub fn mentions_whole_chat(record: &MessageRecord) -> bool {213
mentions(record).iter().any(|mention| {214
mention.group && mention.target_id.as_deref() == Some(record.conversation_id.as_str())215
})216
}217
211
pub fn quotes(record: &MessageRecord) -> Vec<QuoteInfo> {218
pub fn quotes(record: &MessageRecord) -> Vec<QuoteInfo> {212
attachments(record)219
attachments(record)213
.into_iter()220
.into_iter()@@ -178,7 +178,7 @@ mod tests {
178
178
}
179
179
180
180
#[test]
181
fn channel_and_team_mentions_have_no_chatsvc_shape() {
181
fn group_mentions_have_no_chatsvc_shape() {
182
182
for target in [
183
183
MentionTarget::Channel {
184
184
channel_id: "19:c@thread.tacv2".into(),
@@ -186,6 +186,12 @@ mod tests {
186
186
MentionTarget::Team {
187
187
team_id: "team-1".into(),
188
188
},
189
MentionTarget::Everyone {
190
chat_id: "19:g@thread.v2".into(),
191
},
192
MentionTarget::Tag {
193
tag_id: "tag-1".into(),
194
},
189
195
] {
190
196
let mentions = [mention(0, target)];
191
197
assert!(quote_reply_properties("e(), &mentions, None).is_none());
@@ -178,7 +178,7 @@ mod tests {178
}178
}179
179
180
#[test]180
#[test]181
fn channel_and_team_mentions_have_no_chatsvc_shape() {181
fn group_mentions_have_no_chatsvc_shape() {182
for target in [182
for target in [183
MentionTarget::Channel {183
MentionTarget::Channel {184
channel_id: "19:c@thread.tacv2".into(),184
channel_id: "19:c@thread.tacv2".into(),@@ -186,6 +186,12 @@ mod tests {186
MentionTarget::Team {186
MentionTarget::Team {187
team_id: "team-1".into(),187
team_id: "team-1".into(),188
},188
},189
MentionTarget::Everyone {190
chat_id: "19:g@thread.v2".into(),191
},192
MentionTarget::Tag {193
tag_id: "tag-1".into(),194
},189
] {195
] {190
let mentions = [mention(0, target)];196
let mentions = [mention(0, target)];191
assert!(quote_reply_properties("e(), &mentions, None).is_none());197
assert!(quote_reply_properties("e(), &mentions, None).is_none());@@ -1084,6 +1084,16 @@ impl Remote for Handle {
1084
1084
Ok(())
1085
1085
}
1086
1086
1087
async fn team_tags(&self, team_id: &str) -> Result<Vec<graph::Tag>> {
1088
self.record(format!("tags {team_id}"));
1089
Ok(vec![
1090
serde_json::from_value(
1091
json!({"id": "tag-design", "displayName": "Designers", "memberCount": 4}),
1092
)
1093
.unwrap(),
1094
])
1095
}
1096
1087
1097
async fn search_people(&self, query: &str) -> Result<Vec<User>> {
1088
1098
self.record(format!("search {query}"));
1089
1099
let configured = self.directory_users.lock().unwrap().clone();
@@ -4023,9 +4033,14 @@ async fn people_candidates_list_members_first_then_the_directory_without_duplica
4023
4033
];
4024
4034
let engine = chat_engine(&fake, small_pages()).await;
4025
4035
4026
let everyone = engine.mention_candidates(CHAT, "", 10).await.unwrap();
4027
assert_eq!(everyone.len(), 1);
4028
assert_eq!(everyone[0].display_name(), "Ada Example");
4036
let all = engine.mention_candidates(CHAT, "", 10).await.unwrap();
4037
assert_eq!(all.len(), 2);
4038
assert!(matches!(&all[0], MentionCandidate::Everyone { chat_id } if chat_id == CHAT));
4039
assert_eq!(
4040
all[0].to_mention(),
4041
MentionInput::everyone(CHAT, "Everyone")
4042
);
4043
assert_eq!(all[1].display_name(), "Ada Example");
4029
4044
assert!(!fake.calls().iter().any(|call| call.starts_with("search")));
4030
4045
4031
4046
let found = engine.mention_candidates(CHAT, "@ada", 10).await.unwrap();
@@ -4067,12 +4082,30 @@ async fn channel_candidates_offer_recent_senders_the_channel_and_its_team() {
4067
4082
let engine = channel_engine(&fake).await;
4068
4083
engine.fetch_newer(CHANNEL).await.unwrap();
4069
4084
let all = engine.mention_candidates(CHANNEL, "", 10).await.unwrap();
4070
assert_eq!(all.len(), 3);
4085
assert_eq!(all.len(), 4);
4071
4086
assert!(matches!(&all[0], MentionCandidate::Person(person) if person.user_id == "user-ada"));
4072
4087
assert!(
4073
4088
matches!(&all[1], MentionCandidate::Channel { channel_id, .. } if channel_id == CHANNEL)
4074
4089
);
4075
4090
assert!(matches!(&all[2], MentionCandidate::Team { team_id, .. } if team_id == "team-1"));
4091
assert!(
4092
matches!(&all[3], MentionCandidate::Tag { tag_id, member_count: Some(4), .. } if tag_id == "tag-design")
4093
);
4094
let design = engine
4095
.mention_candidates(CHANNEL, "desi", 10)
4096
.await
4097
.unwrap();
4098
assert_eq!(
4099
design[0].to_mention(),
4100
MentionInput::tag("tag-design", "Designers")
4101
);
4102
engine.mention_candidates(CHANNEL, "", 10).await.unwrap();
4103
let tag_loads = fake
4104
.calls()
4105
.into_iter()
4106
.filter(|call| call.starts_with("tags"))
4107
.count();
4108
assert_eq!(tag_loads, 1);
4076
4109
let squad = engine.mention_candidates(CHANNEL, "squ", 10).await.unwrap();
4077
4110
assert_eq!(squad[0].to_mention(), MentionInput::team("team-1", "Squad"));
4078
4111
}
@@ -1084,6 +1084,16 @@ impl Remote for Handle {1084
Ok(())1084
Ok(())1085
}1085
}1086
1086
1087
async fn team_tags(&self, team_id: &str) -> Result<Vec<graph::Tag>> {1088
self.record(format!("tags {team_id}"));1089
Ok(vec![1090
serde_json::from_value(1091
json!({"id": "tag-design", "displayName": "Designers", "memberCount": 4}),1092
)1093
.unwrap(),1094
])1095
}1096
1087
async fn search_people(&self, query: &str) -> Result<Vec<User>> {1097
async fn search_people(&self, query: &str) -> Result<Vec<User>> {1088
self.record(format!("search {query}"));1098
self.record(format!("search {query}"));1089
let configured = self.directory_users.lock().unwrap().clone();1099
let configured = self.directory_users.lock().unwrap().clone();@@ -4023,9 +4033,14 @@ async fn people_candidates_list_members_first_then_the_directory_without_duplica4023
];4033
];4024
let engine = chat_engine(&fake, small_pages()).await;4034
let engine = chat_engine(&fake, small_pages()).await;4025
4035
4026
let everyone = engine.mention_candidates(CHAT, "", 10).await.unwrap();4036
let all = engine.mention_candidates(CHAT, "", 10).await.unwrap();4027
assert_eq!(everyone.len(), 1);4037
assert_eq!(all.len(), 2);4028
assert_eq!(everyone[0].display_name(), "Ada Example");4038
assert!(matches!(&all[0], MentionCandidate::Everyone { chat_id } if chat_id == CHAT));4039
assert_eq!(4040
all[0].to_mention(),4041
MentionInput::everyone(CHAT, "Everyone")4042
);4043
assert_eq!(all[1].display_name(), "Ada Example");4029
assert!(!fake.calls().iter().any(|call| call.starts_with("search")));4044
assert!(!fake.calls().iter().any(|call| call.starts_with("search")));4030
4045
4031
let found = engine.mention_candidates(CHAT, "@ada", 10).await.unwrap();4046
let found = engine.mention_candidates(CHAT, "@ada", 10).await.unwrap();@@ -4067,12 +4082,30 @@ async fn channel_candidates_offer_recent_senders_the_channel_and_its_team() {4067
let engine = channel_engine(&fake).await;4082
let engine = channel_engine(&fake).await;4068
engine.fetch_newer(CHANNEL).await.unwrap();4083
engine.fetch_newer(CHANNEL).await.unwrap();4069
let all = engine.mention_candidates(CHANNEL, "", 10).await.unwrap();4084
let all = engine.mention_candidates(CHANNEL, "", 10).await.unwrap();4070
assert_eq!(all.len(), 3);4085
assert_eq!(all.len(), 4);4071
assert!(matches!(&all[0], MentionCandidate::Person(person) if person.user_id == "user-ada"));4086
assert!(matches!(&all[0], MentionCandidate::Person(person) if person.user_id == "user-ada"));4072
assert!(4087
assert!(4073
matches!(&all[1], MentionCandidate::Channel { channel_id, .. } if channel_id == CHANNEL)4088
matches!(&all[1], MentionCandidate::Channel { channel_id, .. } if channel_id == CHANNEL)4074
);4089
);4075
assert!(matches!(&all[2], MentionCandidate::Team { team_id, .. } if team_id == "team-1"));4090
assert!(matches!(&all[2], MentionCandidate::Team { team_id, .. } if team_id == "team-1"));4091
assert!(4092
matches!(&all[3], MentionCandidate::Tag { tag_id, member_count: Some(4), .. } if tag_id == "tag-design")4093
);4094
let design = engine4095
.mention_candidates(CHANNEL, "desi", 10)4096
.await4097
.unwrap();4098
assert_eq!(4099
design[0].to_mention(),4100
MentionInput::tag("tag-design", "Designers")4101
);4102
engine.mention_candidates(CHANNEL, "", 10).await.unwrap();4103
let tag_loads = fake4104
.calls()4105
.into_iter()4106
.filter(|call| call.starts_with("tags"))4107
.count();4108
assert_eq!(tag_loads, 1);4076
let squad = engine.mention_candidates(CHANNEL, "squ", 10).await.unwrap();4109
let squad = engine.mention_candidates(CHANNEL, "squ", 10).await.unwrap();4077
assert_eq!(squad[0].to_mention(), MentionInput::team("team-1", "Squad"));4110
assert_eq!(squad[0].to_mention(), MentionInput::team("team-1", "Squad"));4078
}4111
}@@ -4,7 +4,7 @@ use serde_json::Value;
4
4
use session::{ApiResponse, GRAPH, Method, Request, Scope, Session};
5
5
6
6
use crate::error::{Error, Result};
7
use crate::models::{Channel, Chat, Member, Message, Team, User};
7
use crate::models::{Channel, Chat, Member, Message, Tag, Team, User};
8
8
use crate::page::Page;
9
9
use crate::urls;
10
10
@@ -115,6 +115,11 @@ impl Graph {
115
115
.await
116
116
}
117
117
118
pub async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> {
119
self.get_all(&urls::team_tags(team_id), Scope::graph("TeamworkTag.Read"))
120
.await
121
}
122
118
123
pub async fn channels(&self, team_id: &str) -> Result<Vec<Channel>> {
119
124
self.get_all(
120
125
&urls::channels(team_id),
@@ -4,7 +4,7 @@ use serde_json::Value;4
use session::{ApiResponse, GRAPH, Method, Request, Scope, Session};4
use session::{ApiResponse, GRAPH, Method, Request, Scope, Session};5
5
6
use crate::error::{Error, Result};6
use crate::error::{Error, Result};7
use crate::models::{Channel, Chat, Member, Message, Team, User};7
use crate::models::{Channel, Chat, Member, Message, Tag, Team, User};8
use crate::page::Page;8
use crate::page::Page;9
use crate::urls;9
use crate::urls;10
10
@@ -115,6 +115,11 @@ impl Graph {115
.await115
.await116
}116
}117
117
118
pub async fn team_tags(&self, team_id: &str) -> Result<Vec<Tag>> {119
self.get_all(&urls::team_tags(team_id), Scope::graph("TeamworkTag.Read"))120
.await121
}122
118
pub async fn channels(&self, team_id: &str) -> Result<Vec<Channel>> {123
pub async fn channels(&self, team_id: &str) -> Result<Vec<Channel>> {119
self.get_all(124
self.get_all(120
&urls::channels(team_id),125
&urls::channels(team_id),@@ -23,7 +23,7 @@ pub use files::{
23
23
pub use library::DriveEntry;
24
24
pub use models::{
25
25
Attachment, Body, Channel, Chat, ChatViewpoint, Identity, Member, Mention, Message, Photo,
26
Presence, Reaction, Sender, Team, UNKNOWN_USER_NAME, User,
26
Presence, Reaction, Sender, Tag, Team, UNKNOWN_USER_NAME, User,
27
27
};
28
28
pub use outgoing::{
29
29
FileReference, HostedImage, KeptAttachment, MentionTarget, MessageExtras, OutgoingMention,
@@ -23,7 +23,7 @@ pub use files::{23
pub use library::DriveEntry;23
pub use library::DriveEntry;24
pub use models::{24
pub use models::{25
Attachment, Body, Channel, Chat, ChatViewpoint, Identity, Member, Mention, Message, Photo,25
Attachment, Body, Channel, Chat, ChatViewpoint, Identity, Member, Mention, Message, Photo,26
Presence, Reaction, Sender, Team, UNKNOWN_USER_NAME, User,26
Presence, Reaction, Sender, Tag, Team, UNKNOWN_USER_NAME, User,27
};27
};28
pub use outgoing::{28
pub use outgoing::{29
FileReference, HostedImage, KeptAttachment, MentionTarget, MessageExtras, OutgoingMention,29
FileReference, HostedImage, KeptAttachment, MentionTarget, MessageExtras, OutgoingMention,@@ -237,6 +237,14 @@ pub struct Team {
237
237
pub display_name: String,
238
238
}
239
239
240
#[derive(Debug, Clone, Deserialize, PartialEq)]
241
#[serde(rename_all = "camelCase")]
242
pub struct Tag {
243
pub id: String,
244
pub display_name: String,
245
pub member_count: Option<u32>,
246
}
247
240
248
#[derive(Debug, Clone, Deserialize, PartialEq)]
241
249
#[serde(rename_all = "camelCase")]
242
250
pub struct Channel {
@@ -237,6 +237,14 @@ pub struct Team {237
pub display_name: String,237
pub display_name: String,238
}238
}239
239
240
#[derive(Debug, Clone, Deserialize, PartialEq)]241
#[serde(rename_all = "camelCase")]242
pub struct Tag {243
pub id: String,244
pub display_name: String,245
pub member_count: Option<u32>,246
}247
240
#[derive(Debug, Clone, Deserialize, PartialEq)]248
#[derive(Debug, Clone, Deserialize, PartialEq)]241
#[serde(rename_all = "camelCase")]249
#[serde(rename_all = "camelCase")]242
pub struct Channel {250
pub struct Channel {@@ -10,6 +10,8 @@ pub enum MentionTarget {
10
10
User { user_id: String },
11
11
Channel { channel_id: String },
12
12
Team { team_id: String },
13
Everyone { chat_id: String },
14
Tag { tag_id: String },
13
15
}
14
16
15
17
/// `id` matches the `<at id="n">` tag in the html body.
@@ -32,6 +34,12 @@ impl OutgoingMention {
32
34
MentionTarget::Team { team_id } => json!({
33
35
"conversation": {"id": team_id, "displayName": self.text, "conversationIdentityType": "team"}
34
36
}),
37
MentionTarget::Everyone { chat_id } => json!({
38
"conversation": {"id": chat_id, "displayName": self.text, "conversationIdentityType": "chat"}
39
}),
40
MentionTarget::Tag { tag_id } => json!({
41
"tag": {"id": tag_id, "displayName": self.text}
42
}),
35
43
};
36
44
json!({"id": self.id, "mentionText": self.text, "mentioned": mentioned})
37
45
}
@@ -232,6 +240,34 @@ mod tests {
232
240
assert_eq!(team["mentioned"]["conversation"]["id"], "t");
233
241
}
234
242
243
#[test]
244
fn everyone_and_tag_mentions_match_the_documented_payload() {
245
let everyone = mention(
246
0,
247
"Everyone",
248
MentionTarget::Everyone {
249
chat_id: "19:g@thread.v2".into(),
250
},
251
)
252
.to_json();
253
assert_eq!(
254
everyone["mentioned"],
255
json!({"conversation": {"id": "19:g@thread.v2", "displayName": "Everyone", "conversationIdentityType": "chat"}})
256
);
257
let tag = mention(
258
1,
259
"Designers",
260
MentionTarget::Tag {
261
tag_id: "tag-1".into(),
262
},
263
)
264
.to_json();
265
assert_eq!(
266
tag,
267
json!({"id": 1, "mentionText": "Designers", "mentioned": {"tag": {"id": "tag-1", "displayName": "Designers"}}})
268
);
269
}
270
235
271
#[test]
236
272
fn body_without_mentions_has_no_mentions_key() {
237
273
let none = MessageExtras::default();
@@ -10,6 +10,8 @@ pub enum MentionTarget {10
User { user_id: String },10
User { user_id: String },11
Channel { channel_id: String },11
Channel { channel_id: String },12
Team { team_id: String },12
Team { team_id: String },13
Everyone { chat_id: String },14
Tag { tag_id: String },13
}15
}14
16
15
/// `id` matches the `<at id="n">` tag in the html body.17
/// `id` matches the `<at id="n">` tag in the html body.@@ -32,6 +34,12 @@ impl OutgoingMention {32
MentionTarget::Team { team_id } => json!({34
MentionTarget::Team { team_id } => json!({33
"conversation": {"id": team_id, "displayName": self.text, "conversationIdentityType": "team"}35
"conversation": {"id": team_id, "displayName": self.text, "conversationIdentityType": "team"}34
}),36
}),37
MentionTarget::Everyone { chat_id } => json!({38
"conversation": {"id": chat_id, "displayName": self.text, "conversationIdentityType": "chat"}39
}),40
MentionTarget::Tag { tag_id } => json!({41
"tag": {"id": tag_id, "displayName": self.text}42
}),35
};43
};36
json!({"id": self.id, "mentionText": self.text, "mentioned": mentioned})44
json!({"id": self.id, "mentionText": self.text, "mentioned": mentioned})37
}45
}@@ -232,6 +240,34 @@ mod tests {232
assert_eq!(team["mentioned"]["conversation"]["id"], "t");240
assert_eq!(team["mentioned"]["conversation"]["id"], "t");233
}241
}234
242
243
#[test]244
fn everyone_and_tag_mentions_match_the_documented_payload() {245
let everyone = mention(246
0,247
"Everyone",248
MentionTarget::Everyone {249
chat_id: "19:g@thread.v2".into(),250
},251
)252
.to_json();253
assert_eq!(254
everyone["mentioned"],255
json!({"conversation": {"id": "19:g@thread.v2", "displayName": "Everyone", "conversationIdentityType": "chat"}})256
);257
let tag = mention(258
1,259
"Designers",260
MentionTarget::Tag {261
tag_id: "tag-1".into(),262
},263
)264
.to_json();265
assert_eq!(266
tag,267
json!({"id": 1, "mentionText": "Designers", "mentioned": {"tag": {"id": "tag-1", "displayName": "Designers"}}})268
);269
}270
235
#[test]271
#[test]236
fn body_without_mentions_has_no_mentions_key() {272
fn body_without_mentions_has_no_mentions_key() {237
let none = MessageExtras::default();273
let none = MessageExtras::default();@@ -265,6 +265,13 @@ pub fn joined_teams() -> String {
265
265
format!("{GRAPH}/v1.0/me/joinedTeams?$select=id,displayName")
266
266
}
267
267
268
pub fn team_tags(team_id: &str) -> String {
269
format!(
270
"{GRAPH}/v1.0/teams/{}/tags?$select=id,displayName,memberCount",
271
segment(team_id)
272
)
273
}
274
268
275
pub fn channels(team_id: &str) -> String {
269
276
format!(
270
277
"{GRAPH}/v1.0/teams/{}/channels?$select=id,displayName,membershipType",
@@ -265,6 +265,13 @@ pub fn joined_teams() -> String {265
format!("{GRAPH}/v1.0/me/joinedTeams?$select=id,displayName")265
format!("{GRAPH}/v1.0/me/joinedTeams?$select=id,displayName")266
}266
}267
267
268
pub fn team_tags(team_id: &str) -> String {269
format!(270
"{GRAPH}/v1.0/teams/{}/tags?$select=id,displayName,memberCount",271
segment(team_id)272
)273
}274
268
pub fn channels(team_id: &str) -> String {275
pub fn channels(team_id: &str) -> String {269
format!(276
format!(270
"{GRAPH}/v1.0/teams/{}/channels?$select=id,displayName,membershipType",277
"{GRAPH}/v1.0/teams/{}/channels?$select=id,displayName,membershipType",