BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / demo.rs

demo.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
demo.rs 88.6 KiB Download Raw
1use std::collections::HashMap;
2use std::path::PathBuf;
3use std::sync::OnceLock;
4use std::time::Instant;
5
6use chrono::{DateTime, Duration, Local, TimeZone, Utc};
7use gpui_kit::{App, Entity};
8use store::{
9 ChannelLayoutRecord, ChannelMentions, ChannelNotificationLevel, ChannelNotifications,
10 ChannelRecord, ChannelTabRecord, ChatRecord, MemberRecord, MessageImportance, MessageRecord,
11 Store, TeamLayoutRecord, TeamRecord,
12};
13use teams_core::{
14 ANNOUNCEMENT_BANNER_TYPE, Activity, ActivityHorizons, ActivityItem, ActivitySnapshot,
15 CallEvent, CallPhase, CallType, CardActionOutcome, ChatApp, Gif, Language, LanguageSettings,
16 LinkPreview, MentionCandidate, NOTES_CHAT_ID, PersonCandidate, PersonSource, PinnedMessage,
17 SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior, TranslationStatus,
18};
19
20use crate::app_state::{AppState, Selection};
21use crate::card_actions::{CardAnswer, CardTask};
22use crate::data::{AvatarState, FolderInfo, FolderKind, Person, PresenceKind};
23use crate::demo_gifs;
24use crate::message_actions::ForwardSource;
25
26static SEARCHABLE_GIFS: OnceLock<Vec<Gif>> = OnceLock::new();
27
28pub const DEMO_USER_ID: &str = "demo-me";
29const DEMO_USER_NAME: &str = "Dana Demo";
30const DEMO_USER_EMAIL: &str = "dana.demo@example.com";
31const DEMO_TIME_ZONE: &str = "W. Europe Standard Time";
32const PHOTO_SIZE: usize = 48;
33const DEMO_PHOTO_SIDE: usize = 240;
34const STAGING_IMAGE_KEY: &str = "demo://staging-dashboard";
35const PENDING_IMAGE_KEY: &str = "demo://pending-screenshot";
36const STAGING_SIZE: (usize, usize) = (960, 540);
37const LINK_IMAGE_KEY: &str =
38 "https://de-prod.asyncgw.teams.microsoft.com/urlp/v1/url/image/Thumbnail?url=demo";
39const LINK_IMAGE_SIZE: (u32, u32) = (320, 180);
40const PRIORITY_CHAT: &str = "demo-chat-priya";
41const BOT_CHAT: &str = "demo-chat-wiki-bot";
42const BOT_NAME: &str = "Wiki Bot";
43const ECHO_CHAT: &str = "demo-chat-echo";
44const ECHO_BOT_ID: &str = "28:demo-echo";
45const BOT_APP_NAME: &str = "Wiki Cloud";
46const BOT_ID: &str = "00000000-0000-0000-0000-00000000b07a";
47const CARD_ANSWER_DELAY: std::time::Duration = std::time::Duration::from_millis(700);
48const CARD_PERSON_URL: &str = "https://avatars.githubusercontent.com/u/9919?s=64";
49const CARD_PAGE_URL: &str = "https://avatars.githubusercontent.com/u/9919?s=64";
50const NEW_CHAT_PREFIX: &str = "demo-chat-new-";
51const PEOPLE_DIRECTORY: [(&str, &str, &str, &str); 5] = [
52 (
53 MARA_ID,
54 "Mara Lindqvist",
55 "Product Owner",
56 "mara.lindqvist@example.com",
57 ),
58 (
59 JONAS_ID,
60 "Jonas Ortega",
61 "Backend Engineer",
62 "jonas.ortega@example.com",
63 ),
64 (
65 PRIYA_ID,
66 "Priya Nair",
67 "Engineering Manager",
68 "priya.nair@example.com",
69 ),
70 (
71 LEA_ID,
72 "Lea Schneider",
73 "Customer Success",
74 "lea.schneider@example.com",
75 ),
76 (
77 TOBIAS_ID,
78 "Tobias Klein",
79 "Support Engineer",
80 "tobias.klein@example.com",
81 ),
82];
83
84struct Palette {
85 background: [u8; 3],
86 skin: [u8; 3],
87 hair: [u8; 3],
88 shirt: [u8; 3],
89}
90
91const MARA: Palette = Palette {
92 background: [0x3f, 0x5f, 0x7a],
93 skin: [0xe0, 0xb2, 0x93],
94 hair: [0xd9, 0xa4, 0x41],
95 shirt: [0x1e, 0x29, 0x3b],
96};
97const PRIYA: Palette = Palette {
98 background: [0x4b, 0x3b, 0x5c],
99 skin: [0x9a, 0x6a, 0x4a],
100 hair: [0x1c, 0x19, 0x17],
101 shirt: [0xbe, 0x12, 0x3c],
102};
103const TOBIAS: Palette = Palette {
104 background: [0x3b, 0x4a, 0x3f],
105 skin: [0xf1, 0xc7, 0xa5],
106 hair: [0x57, 0x53, 0x4e],
107 shirt: [0x0f, 0x76, 0x6e],
108};
109
110pub const MARA_ID: &str = "demo-mara";
111pub const JONAS_ID: &str = "demo-jonas";
112pub const PRIYA_ID: &str = "demo-priya";
113pub const LEA_ID: &str = "demo-lea";
114pub const TOBIAS_ID: &str = "demo-tobias";
115
116const DEMO_PRIVATE_CHANNEL: &str = "Runbooks";
117const DEMO_TEAMS: [(&str, &str, [&str; 3]); 4] = [
118 (
119 "demo-team-1",
120 "Platform",
121 ["General", "Incidents", "Releases"],
122 ),
123 ("demo-team-2", "Product", ["General", "Roadmap", "Feedback"]),
124 (
125 "demo-team-3",
126 "Operations",
127 ["General", "On call", "Runbooks"],
128 ),
129 (
130 "demo-team-4",
131 "Archive 2025",
132 ["General", "Trade fair", "Office move"],
133 ),
134];
135const DEMO_TEAM_ORDER: [&str; 4] = ["demo-team-2", "demo-team-1", "demo-team-3", "demo-team-4"];
136const DEMO_HIDDEN_TEAM: &str = "demo-team-4";
137const DEMO_HIDDEN_CHANNEL: &str = "demo-channel-3-3";
138const DEMO_CHANNEL_MENTIONS: [(&str, ChannelMentions); 4] = [
139 ("demo-channel-1-2", mentions(2, 0, 0)),
140 ("demo-channel-2-1", mentions(0, 1, 0)),
141 (DEMO_HIDDEN_CHANNEL, mentions(1, 0, 0)),
142 ("demo-channel-4-2", mentions(1, 0, 1)),
143];
144const PINNED_CHANNEL: &str = "demo-channel-1-1";
145const PINNED_POST: &str = "t3";
146
147const fn mentions(personal: u32, channel: u32, team: u32) -> ChannelMentions {
148 ChannelMentions {
149 personal,
150 channel,
151 team,
152 }
153}
154const DEMO_CHANNEL_NOTIFICATIONS: [(&str, ChannelNotificationLevel, bool); 4] = [
155 (
156 "demo-channel-1-1",
157 ChannelNotificationLevel::BannerAndFeed,
158 false,
159 ),
160 (
161 "demo-channel-1-2",
162 ChannelNotificationLevel::BannerAndFeed,
163 true,
164 ),
165 ("demo-channel-1-3", ChannelNotificationLevel::Off, false),
166 ("demo-channel-2-2", ChannelNotificationLevel::Off, false),
167];
168
169const UNREAD_CHAT: &str = "demo-chat-atlas";
170const RELEASE_CHAT: &str = "demo-chat-release";
171const PINNED_MESSAGE: &str = "m5b";
172const FRENCH_MESSAGE: &str = "m10";
173const SPANISH_MESSAGE: &str = "m11";
174const SAVED_MESSAGES: [&str; 2] = ["m4", "m5c"];
175const FORWARD_ITEMTYPE: &str = "http://schema.skype.com/Forward";
176const FAVORITES_ID: &str = "demo-folder-favorites";
177const CUSTOMERS_FOLDER: &str = "demo-folder-customers";
178const ATLAS_FOLDER: &str = "demo-folder-atlas";
179const TODO_FOLDER: &str = "demo-folder-todo";
180const MUTED_CHATS: [&str; 6] = [
181 "demo-chat-muted-lunch",
182 "demo-chat-muted-offsite",
183 "demo-chat-muted-kudos",
184 "demo-chat-muted-bikes",
185 "demo-chat-muted-book",
186 "demo-chat-muted-games",
187];
188
189fn member(user_id: &str, name: &str) -> MemberRecord {
190 MemberRecord {
191 user_id: Some(user_id.to_owned()),
192 display_name: name.to_owned(),
193 }
194}
195
196fn people(extra: &[(&str, &str)]) -> Vec<MemberRecord> {
197 std::iter::once(member(DEMO_USER_ID, DEMO_USER_NAME))
198 .chain(extra.iter().map(|(id, name)| member(id, name)))
199 .collect()
200}
201
202pub fn at(days_ago: i64, hour: u32, minute: u32) -> DateTime<Utc> {
203 let day = Local::now().date_naive() - Duration::days(days_ago);
204 let local = day.and_hms_opt(hour, minute, 0).expect("valid time");
205 Local
206 .from_local_datetime(&local)
207 .earliest()
208 .map_or_else(Utc::now, |time| time.with_timezone(&Utc))
209}
210
211struct DemoChat {
212 id: &'static str,
213 kind: &'static str,
214 title: &'static str,
215 members: Vec<MemberRecord>,
216 time: DateTime<Utc>,
217 unread: bool,
218 preview: Option<(&'static str, &'static str, &'static str)>,
219 deleted: bool,
220}
221
222fn demo_chats() -> Vec<DemoChat> {
223 let group = |extra: &[(&str, &str)]| people(extra);
224 vec![
225 DemoChat {
226 id: BOT_CHAT,
227 kind: "oneOnOne",
228 title: BOT_NAME,
229 members: people(&[]),
230 time: at(0, 13, 45),
231 unread: true,
232 preview: Some(("", BOT_NAME, "Mara Lindqvist edited your page")),
233 deleted: false,
234 },
235 DemoChat {
236 id: "demo-chat-mara",
237 kind: "oneOnOne",
238 title: "Mara Lindqvist",
239 members: people(&[(MARA_ID, "Mara Lindqvist")]),
240 time: at(0, 13, 40),
241 unread: false,
242 preview: Some((MARA_ID, "Mara Lindqvist", "Sure, 2 pm works")),
243 deleted: false,
244 },
245 DemoChat {
246 id: RELEASE_CHAT,
247 kind: "group",
248 title: "Release planning",
249 members: group(&[
250 (MARA_ID, "Mara Lindqvist"),
251 (JONAS_ID, "Jonas Ortega"),
252 (PRIYA_ID, "Priya Nair"),
253 (LEA_ID, "Lea Schneider"),
254 ]),
255 time: at(0, 13, 35),
256 unread: false,
257 preview: Some((
258 DEMO_USER_ID,
259 DEMO_USER_NAME,
260 "Build 42 is green, see pipeline",
261 )),
262 deleted: false,
263 },
264 DemoChat {
265 id: "demo-chat-customer-1",
266 kind: "group",
267 title: "Customer North - Operations",
268 members: group(&[(LEA_ID, "Lea Schneider"), (TOBIAS_ID, "Tobias Klein")]),
269 time: at(0, 12, 50),
270 unread: true,
271 preview: Some((LEA_ID, "Lea Schneider", "Access is enabled now")),
272 deleted: false,
273 },
274 DemoChat {
275 id: "demo-chat-customer-2",
276 kind: "group",
277 title: "Customer South - Rollout",
278 members: group(&[(JONAS_ID, "Jonas Ortega"), (PRIYA_ID, "Priya Nair")]),
279 time: at(0, 9, 5),
280 unread: true,
281 preview: Some((JONAS_ID, "Jonas Ortega", "Meeting is set for Friday")),
282 deleted: false,
283 },
284 DemoChat {
285 id: "demo-chat-customer-3",
286 kind: "group",
287 title: "Customer West - Support",
288 members: group(&[(TOBIAS_ID, "Tobias Klein"), (LEA_ID, "Lea Schneider")]),
289 time: at(1, 16, 0),
290 unread: false,
291 preview: Some((TOBIAS_ID, "Tobias Klein", "Ticket is closed")),
292 deleted: false,
293 },
294 DemoChat {
295 id: "demo-chat-customer-4",
296 kind: "group",
297 title: "Customer East - Pilot",
298 members: group(&[(MARA_ID, "Mara Lindqvist"), (PRIYA_ID, "Priya Nair")]),
299 time: at(3, 10, 0),
300 unread: false,
301 preview: Some((DEMO_USER_ID, DEMO_USER_NAME, "I'll send the documents")),
302 deleted: false,
303 },
304 DemoChat {
305 id: "demo-chat-atlas",
306 kind: "group",
307 title: "Atlas core team",
308 members: group(&[
309 (PRIYA_ID, "Priya Nair"),
310 (LEA_ID, "Lea Schneider"),
311 (MARA_ID, "Mara Lindqvist"),
312 ]),
313 time: at(0, 13, 12),
314 unread: true,
315 preview: Some((PRIYA_ID, "Priya Nair", "Who is taking the review?")),
316 deleted: false,
317 },
318 DemoChat {
319 id: ECHO_CHAT,
320 kind: "oneOnOne",
321 title: "Echo",
322 members: people(&[(ECHO_BOT_ID, "Echo")]),
323 time: at(0, 11, 20),
324 unread: false,
325 preview: Some(("", "", "Recording is ready")),
326 deleted: false,
327 },
328 DemoChat {
329 id: NOTES_CHAT_ID,
330 kind: "oneOnOne",
331 title: "Dana Demo (You)",
332 members: people(&[]),
333 time: at(0, 8, 20),
334 unread: false,
335 preview: Some((DEMO_USER_ID, DEMO_USER_NAME, "Release notes draft")),
336 deleted: false,
337 },
338 DemoChat {
339 id: "demo-chat-jonas",
340 kind: "oneOnOne",
341 title: "Jonas Ortega",
342 members: people(&[(JONAS_ID, "Jonas Ortega")]),
343 time: at(0, 11, 2),
344 unread: false,
345 preview: Some((DEMO_USER_ID, DEMO_USER_NAME, "Thanks, it's merged")),
346 deleted: false,
347 },
348 DemoChat {
349 id: "demo-chat-priya",
350 kind: "oneOnOne",
351 title: "Priya Nair",
352 members: people(&[(PRIYA_ID, "Priya Nair")]),
353 time: at(0, 10, 47),
354 unread: false,
355 preview: Some((PRIYA_ID, "Priya Nair", "Sent an image")),
356 deleted: false,
357 },
358 DemoChat {
359 id: "demo-chat-tobias",
360 kind: "oneOnOne",
361 title: "Tobias Klein",
362 members: people(&[(TOBIAS_ID, "Tobias Klein")]),
363 time: at(2, 9, 30),
364 unread: false,
365 preview: Some((DEMO_USER_ID, DEMO_USER_NAME, "Forwarded a message")),
366 deleted: false,
367 },
368 DemoChat {
369 id: "demo-chat-allhands",
370 kind: "group",
371 title: "All-hands announcements",
372 members: group(&[(LEA_ID, "Lea Schneider"), (MARA_ID, "Mara Lindqvist")]),
373 time: at(0, 9, 0),
374 unread: true,
375 preview: Some((LEA_ID, "Lea Schneider", "New vacation policy from November")),
376 deleted: false,
377 },
378 DemoChat {
379 id: "demo-chat-design",
380 kind: "group",
381 title: "Design review",
382 members: group(&[(MARA_ID, "Mara Lindqvist"), (TOBIAS_ID, "Tobias Klein")]),
383 time: at(2, 15, 0),
384 unread: false,
385 preview: Some((MARA_ID, "Mara Lindqvist", "alt")),
386 deleted: true,
387 },
388 DemoChat {
389 id: "demo-chat-quarterly",
390 kind: "group",
391 title: "Quarterly numbers, finance review and planning 2027",
392 members: group(&[(LEA_ID, "Lea Schneider"), (JONAS_ID, "Jonas Ortega")]),
393 time: at(4, 11, 0),
394 unread: false,
395 preview: Some((LEA_ID, "Lea Schneider", "Draft attached")),
396 deleted: false,
397 },
398 DemoChat {
399 id: "demo-chat-meeting-standup",
400 kind: "meeting",
401 title: "Daily standup",
402 members: group(&[(JONAS_ID, "Jonas Ortega"), (PRIYA_ID, "Priya Nair")]),
403 time: at(0, 9, 45),
404 unread: true,
405 preview: Some(("", "", "Recording is ready")),
406 deleted: false,
407 },
408 DemoChat {
409 id: "demo-chat-meeting-retro",
410 kind: "meeting",
411 title: "Sprint retrospective",
412 members: group(&[(MARA_ID, "Mara Lindqvist"), (TOBIAS_ID, "Tobias Klein")]),
413 time: at(3, 15, 30),
414 unread: false,
415 preview: Some((MARA_ID, "Mara Lindqvist", "Notes are in the wiki")),
416 deleted: false,
417 },
418 DemoChat {
419 id: "demo-chat-muted-lunch",
420 kind: "group",
421 title: "Lunch crew",
422 members: group(&[(JONAS_ID, "Jonas Ortega"), (LEA_ID, "Lea Schneider")]),
423 time: at(0, 12, 5),
424 unread: true,
425 preview: Some((JONAS_ID, "Jonas Ortega", "\u{1F4F7} GIF")),
426 deleted: false,
427 },
428 DemoChat {
429 id: "demo-chat-muted-offsite",
430 kind: "group",
431 title: "Team offsite 2027",
432 members: group(&[(LEA_ID, "Lea Schneider"), (LEA_ID, "Lea Schneider")]),
433 time: at(1, 16, 20),
434 unread: false,
435 preview: Some((LEA_ID, "Lea Schneider", "Voting closes tomorrow")),
436 deleted: false,
437 },
438 DemoChat {
439 id: "demo-chat-muted-kudos",
440 kind: "group",
441 title: "Kudos corner",
442 members: group(&[(MARA_ID, "Mara Lindqvist"), (LEA_ID, "Lea Schneider")]),
443 time: at(2, 10, 0),
444 unread: false,
445 preview: Some((MARA_ID, "Mara Lindqvist", "Thanks for the release!")),
446 deleted: false,
447 },
448 DemoChat {
449 id: "demo-chat-muted-bikes",
450 kind: "group",
451 title: "Bike to work",
452 members: group(&[(TOBIAS_ID, "Tobias Klein"), (LEA_ID, "Lea Schneider")]),
453 time: at(4, 8, 15),
454 unread: false,
455 preview: Some((TOBIAS_ID, "Tobias Klein", "Sent a file")),
456 deleted: false,
457 },
458 DemoChat {
459 id: "demo-chat-muted-book",
460 kind: "group",
461 title: "Book club",
462 members: group(&[(PRIYA_ID, "Priya Nair"), (LEA_ID, "Lea Schneider")]),
463 time: at(6, 19, 40),
464 unread: false,
465 preview: Some((PRIYA_ID, "Priya Nair", "Sent a card")),
466 deleted: false,
467 },
468 DemoChat {
469 id: "demo-chat-muted-games",
470 kind: "group",
471 title: "Board game night",
472 members: group(&[(JONAS_ID, "Jonas Ortega"), (LEA_ID, "Lea Schneider")]),
473 time: at(9, 18, 0),
474 unread: false,
475 preview: Some((JONAS_ID, "Jonas Ortega", "Who brings the snacks?")),
476 deleted: false,
477 },
478 ]
479}
480
481pub fn mention_candidates(conversation_id: &str, query: &str) -> Vec<MentionCandidate> {
482 let needle = query.trim().to_lowercase();
483 let matches = |name: &str| needle.is_empty() || name.to_lowercase().contains(&needle);
484 let people = PEOPLE_DIRECTORY
485 .iter()
486 .filter(|(_, name, _, _)| matches(name))
487 .map(|(user_id, name, job_title, mail)| {
488 MentionCandidate::Person(PersonCandidate {
489 user_id: (*user_id).to_owned(),
490 display_name: (*name).to_owned(),
491 mail: Some((*mail).to_owned()),
492 job_title: Some((*job_title).to_owned()),
493 source: PersonSource::Member,
494 })
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()));
503 let scope: Vec<MentionCandidate> = if conversation_id.starts_with("demo-channel") {
504 [
505 MentionCandidate::Channel {
506 channel_id: conversation_id.to_owned(),
507 name: "General".to_owned(),
508 },
509 MentionCandidate::Team {
510 team_id: "demo-team-1".to_owned(),
511 name: "Platform".to_owned(),
512 },
513 MentionCandidate::Tag {
514 tag_id: "demo-tag-design".to_owned(),
515 name: "Designers".to_owned(),
516 member_count: Some(3),
517 },
518 ]
519 .into_iter()
520 .filter(|candidate| matches(candidate.display_name()))
521 .collect()
522 } else {
523 Vec::new()
524 };
525 everyone.into_iter().chain(people).chain(scope).collect()
526}
527
528pub fn send_in_chat(
529 chat: &ChatRecord,
530 preview: &str,
531 html: &str,
532 now: DateTime<Utc>,
533) -> (ChatRecord, MessageRecord) {
534 let mut chat = chat.clone();
535 chat.last_message_at = Some(now);
536 chat.preview_at = Some(now);
537 chat.last_message_preview = Some(preview.to_owned());
538 chat.last_message_sender_id = Some(DEMO_USER_ID.to_owned());
539 chat.last_message_sender_name = Some(DEMO_USER_NAME.to_owned());
540 chat.last_message_deleted = false;
541 chat.unread = false;
542 let record = message(
543 &chat.id,
544 &format!("demo-sent-{}", now.timestamp_millis()),
545 None,
546 (DEMO_USER_ID, DEMO_USER_NAME),
547 now,
548 html,
549 "[]",
550 false,
551 );
552 (chat, record)
553}
554
555pub fn new_chat(
556 existing: &[ChatRecord],
557 people: &[(String, String)],
558 topic: Option<&str>,
559 preview: &str,
560 html: &str,
561 now: DateTime<Utc>,
562) -> (ChatRecord, MessageRecord) {
563 let number = existing
564 .iter()
565 .filter(|chat| chat.id.starts_with(NEW_CHAT_PREFIX))
566 .count()
567 + 1;
568 let one_on_one = people.len() == 1;
569 let members = std::iter::once(member(DEMO_USER_ID, DEMO_USER_NAME))
570 .chain(people.iter().map(|(user_id, name)| member(user_id, name)))
571 .collect();
572 let chat = ChatRecord {
573 id: format!("{NEW_CHAT_PREFIX}{number}"),
574 kind: if one_on_one { "oneOnOne" } else { "group" }.to_owned(),
575 title: if one_on_one {
576 String::new()
577 } else {
578 topic.unwrap_or_default().to_owned()
579 },
580 member_summary: people
581 .iter()
582 .map(|(_, name)| name.as_str())
583 .collect::<Vec<_>>()
584 .join(", "),
585 members,
586 ..Default::default()
587 };
588 send_in_chat(&chat, preview, html, now)
589}
590
591fn image_directory() -> PathBuf {
592 std::env::temp_dir().join("rusty-teams-demo")
593}
594
595pub fn search_gifs(query: &str) -> Vec<Gif> {
596 let query = query.trim().to_lowercase();
597 SEARCHABLE_GIFS
598 .get()
599 .into_iter()
600 .flatten()
601 .filter(|gif| gif.title.to_lowercase().contains(&query))
602 .cloned()
603 .collect()
604}
605
606pub fn language_settings() -> LanguageSettings {
607 LanguageSettings {
608 display_locale: Some("en-US".to_owned()),
609 target_locale: Some("en".to_owned()),
610 behavior: TranslationBehavior::Ask,
611 authoring_locales: vec!["de-DE".to_owned(), "en-US".to_owned()],
612 preferences: serde_json::Map::new(),
613 }
614}
615
616pub fn language_list() -> Vec<Language> {
617 [
618 ("de", "German"),
619 ("en", "English"),
620 ("es", "Spanish"),
621 ("fr", "French"),
622 ("it", "Italian"),
623 ("ja", "Japanese"),
624 ("nl", "Dutch"),
625 ("pt", "Portuguese"),
626 ]
627 .into_iter()
628 .map(|(code, name)| Language {
629 code: code.to_owned(),
630 name: name.to_owned(),
631 })
632 .collect()
633}
634
635pub fn language_stamps(conversation_id: &str) -> HashMap<String, String> {
636 if conversation_id != RELEASE_CHAT {
637 return HashMap::new();
638 }
639 HashMap::from([
640 (
641 FRENCH_MESSAGE.to_owned(),
642 "languages=fr:100;en:12;length:104;&detector=Bling".to_owned(),
643 ),
644 (
645 SPANISH_MESSAGE.to_owned(),
646 "languages=es:100;pt:31;length:94;&detector=Bling".to_owned(),
647 ),
648 ])
649}
650
651pub fn translations(message_ids: &[String]) -> Vec<Translation> {
652 let translated = |message_id: &str| match message_id {
653 FRENCH_MESSAGE => Some(
654 "<p>Hello everyone, <strong>version 0.2</strong> is ready. Can you check the checklist before Friday?</p>",
655 ),
656 SPANISH_MESSAGE => Some(
657 "<p>Thanks for the heads-up. I will test the build this afternoon and let you know if anything breaks.</p>",
658 ),
659 _ => None,
660 };
661 message_ids
662 .iter()
663 .map(|message_id| Translation {
664 message_id: message_id.clone(),
665 version: None,
666 status: if translated(message_id).is_some() {
667 TranslationStatus::Done
668 } else {
669 TranslationStatus::Failed
670 },
671 content_html: translated(message_id).map(str::to_owned),
672 subject: None,
673 title: None,
674 })
675 .collect()
676}
677
678pub fn channel_read_until(channel_id: &str) -> Option<DateTime<Utc>> {
679 (channel_id == PINNED_CHANNEL).then(|| at(0, 11, 0))
680}
681
682pub fn first_unread(conversation_id: &str) -> Option<String> {
683 (conversation_id == UNREAD_CHAT).then(|| "u3".to_owned())
684}
685
686pub fn read_message_ids(records: &[MessageRecord]) -> std::collections::HashSet<String> {
687 let newest = records.iter().max_by_key(|record| record.created_at);
688 records
689 .iter()
690 .filter(|record| {
691 Some(record.message_id.as_str()) != newest.map(|newest| newest.message_id.as_str())
692 })
693 .map(|record| record.message_id.clone())
694 .collect()
695}
696
697pub fn start_session(state: &Entity<AppState>, cx: &mut App) {
698 state.update(cx, |state, cx| {
699 seed_directory(state);
700 state.demo_live_meetings();
701 state.select(first_selection(), cx);
702 });
703}
704
705pub fn first_selection() -> Selection {
706 Selection::Chat(RELEASE_CHAT.to_owned())
707}
708
709pub fn activity_snapshot() -> ActivitySnapshot {
710 let item = |message_id: &str,
711 activity_type: &str,
712 subtype: &str,
713 conversation_id: &str,
714 thread_type: &str,
715 source_message_id: &str,
716 actor: (&str, &str),
717 preview: &str,
718 time: DateTime<Utc>,
719 read: bool| ActivityItem {
720 message_id: message_id.to_owned(),
721 activity_id: message_id.to_owned(),
722 activity_type: activity_type.to_owned(),
723 activity_subtype: subtype.to_owned(),
724 source_thread_id: conversation_id.to_owned(),
725 source_message_id: (!source_message_id.is_empty()).then(|| source_message_id.to_owned()),
726 source_reply_chain_id: (!source_message_id.is_empty())
727 .then(|| source_message_id.to_owned()),
728 source_user_id: Some(format!("8:orgid:{}", actor.0)),
729 source_user_name: actor.1.to_owned(),
730 preview: preview.to_owned(),
731 preview_template: "hasText".to_owned(),
732 thread_type: Some(thread_type.to_owned()),
733 count: 1,
734 timestamp_ms: time.timestamp_millis(),
735 version_ms: time.timestamp_millis(),
736 read_flag: read,
737 ..ActivityItem::default()
738 };
739 let items = vec![
740 item(
741 "demo-activity-1",
742 "replyInChat",
743 "",
744 UNREAD_CHAT,
745 "chat",
746 "u3",
747 (LEA_ID, "Lea Schneider"),
748 "Who is taking the review?",
749 at(0, 13, 12),
750 false,
751 ),
752 ActivityItem {
753 count: 2,
754 ..item(
755 "demo-activity-2",
756 "reactionInChat",
757 "laugh",
758 RELEASE_CHAT,
759 "chat",
760 "m3",
761 (PRIYA_ID, "Priya Nair"),
762 "I'll take the changelog.",
763 at(0, 13, 20),
764 false,
765 )
766 },
767 item(
768 "demo-activity-3",
769 "mention",
770 "person",
771 "demo-channel-1-1",
772 "topic",
773 "t1",
774 (MARA_ID, "Mara Lindqvist"),
775 "@Dana can you approve the merge? The pipeline is waiting.",
776 at(0, 11, 40),
777 false,
778 ),
779 item(
780 "demo-activity-4",
781 "mentionInChat",
782 "person",
783 "demo-chat-allhands",
784 "chat",
785 "demo-allhands-policy",
786 (LEA_ID, "Lea Schneider"),
787 "@Dana please read the new vacation policy before Friday.",
788 at(0, 9, 0),
789 false,
790 ),
791 item(
792 "demo-activity-5",
793 "follow",
794 "channelNewMessage",
795 "demo-channel-1-3",
796 "topic",
797 "demo-release-post",
798 (MARA_ID, "Mara Lindqvist"),
799 "Release 4.2 is tagged, notes are in the wiki.",
800 at(1, 17, 30),
801 true,
802 ),
803 item(
804 "demo-activity-6",
805 "call",
806 "missedCall",
807 "demo-chat-customer-3",
808 "chat",
809 "",
810 (TOBIAS_ID, "Tobias Klein"),
811 "",
812 at(1, 16, 0),
813 true,
814 ),
815 ActivityItem {
816 source_thread_id: String::new(),
817 source_message_id: Some("1".to_owned()),
818 source_reply_chain_id: None,
819 source_user_id: None,
820 source_app_name: Some("Meeting Recaps".to_owned()),
821 preview_template: "previewUnavailable".to_owned(),
822 template_parameters: [("subject".to_owned(), "Following: Sprint Review ".to_owned())]
823 .into(),
824 event_start_ms: Some(at(1, 10, 0).timestamp_millis()),
825 event_end_ms: Some(at(1, 11, 0).timestamp_millis()),
826 ..item(
827 "demo-activity-7",
828 "msGraph",
829 "recapIsReadyForFollowedMeetingsV2",
830 "",
831 "",
832 "",
833 ("", "Meeting Recaps"),
834 "You're following this meeting",
835 at(1, 11, 30),
836 true,
837 )
838 },
839 ];
840 ActivitySnapshot {
841 items,
842 horizons: ActivityHorizons::default(),
843 }
844}
845
846pub fn seed(store: &Store) {
847 let chats: Vec<ChatRecord> = demo_chats()
848 .into_iter()
849 .map(|demo| ChatRecord {
850 id: demo.id.to_owned(),
851 kind: demo.kind.to_owned(),
852 title: if demo.kind == "oneOnOne" {
853 String::new()
854 } else {
855 demo.title.to_owned()
856 },
857 member_summary: demo.title.to_owned(),
858 last_message_at: Some(demo.time),
859 unread: demo.unread,
860 members: demo.members,
861 last_message_preview: demo.preview.map(|(_, _, text)| text.to_owned()),
862 last_message_sender_id: demo.preview.map(|(id, _, _)| id.to_owned()),
863 last_message_sender_name: demo.preview.map(|(_, name, _)| name.to_owned()),
864 last_message_deleted: demo.deleted,
865 ..Default::default()
866 })
867 .collect();
868 let _ = store.upsert_chats(&chats);
869 for chat_id in MUTED_CHATS {
870 let _ = store.set_chat_muted(chat_id, true);
871 }
872 let teams: Vec<TeamRecord> = DEMO_TEAMS
873 .iter()
874 .map(|(id, name, _)| TeamRecord {
875 id: (*id).to_owned(),
876 name: (*name).to_owned(),
877 })
878 .collect();
879 let _ = store.upsert_teams(&teams);
880 let mut channels = Vec::new();
881 for (team_index, (team_id, _, names)) in DEMO_TEAMS.iter().enumerate() {
882 for (channel_index, name) in names.iter().enumerate() {
883 channels.push(ChannelRecord {
884 id: format!("demo-channel-{}-{}", team_index + 1, channel_index + 1),
885 team_id: (*team_id).to_owned(),
886 name: (*name).to_owned(),
887 membership_type: (*name == DEMO_PRIVATE_CHANNEL).then(|| "private".to_owned()),
888 last_message_at: Some(at(channel_index as i64, 12, 10)),
889 unread: (team_index == 0 && channel_index == 1)
890 || (team_index == 1 && channel_index == 0),
891 });
892 }
893 }
894 for channel in channels.iter_mut().filter(|channel| {
895 DEMO_CHANNEL_MENTIONS
896 .iter()
897 .any(|(id, _)| *id == channel.id)
898 }) {
899 channel.unread = true;
900 }
901 let _ = store.upsert_channels(&channels);
902 let _ = store.replace_team_layout(&demo_team_layout(&channels));
903 let _ = store.replace_channel_mentions(
904 &DEMO_CHANNEL_MENTIONS
905 .iter()
906 .map(|(id, mentions)| ((*id).to_owned(), *mentions))
907 .collect::<Vec<_>>(),
908 );
909 let _ = store.set_meta("me_user_id", DEMO_USER_ID);
910 let _ = store.set_meta("me_display_name", DEMO_USER_NAME);
911 let _ = store.upsert_messages(&release_messages());
912 let _ = store.upsert_messages(&unread_messages());
913 let _ = store.upsert_messages(&channel_messages());
914 let _ = store.upsert_messages(&priority_messages());
915 let _ = store.upsert_messages(&notes_messages());
916 let _ = store.upsert_messages(&meeting_link_messages());
917 let _ = store.upsert_messages(&standup_messages());
918 let _ = store.upsert_messages(&call_messages());
919 let _ = store.upsert_messages(&crate::demo_meetings::meeting_messages());
920 let _ = store.upsert_messages(&bot_messages());
921 seed_agent_access(store);
922}
923
924pub fn agent_meeting_draft() -> mcp::MeetingDraft {
925 let start = at(-1, 10, 0);
926 mcp::MeetingDraft {
927 subject: "Release 42 go/no-go".to_owned(),
928 start,
929 end: start + Duration::minutes(30),
930 attendees: vec![
931 "mara.lindqvist@example.com".to_owned(),
932 "jonas.ortega@example.com".to_owned(),
933 ],
934 description:
935 "Walk through the regression results and decide on Friday's rollout.\nOwner: Mara"
936 .to_owned(),
937 }
938}
939
940const AGENT_DEMO_PROPOSAL: &str = "I ran the regression suite on staging: 412 passed, 0 failed. The release candidate is good to ship, @Mara Lindqvist.";
941
942fn seed_agent_access(store: &Store) {
943 let selected =
944 |ids: &[&str]| mcp::Access::Selected(ids.iter().map(|id| (*id).to_owned()).collect());
945 mcp::save_policy(
946 store,
947 &mcp::AgentPolicy {
948 enabled: true,
949 chats: selected(&[RELEASE_CHAT, "demo-chat-mara", "demo-chat-meeting-standup"]),
950 channels: selected(&["demo-channel-1-1"]),
951 write: true,
952 calendar: true,
953 transcripts: false,
954 meetings: true,
955 ..mcp::AgentPolicy::default()
956 },
957 );
958 let _ = store.insert_agent_proposal(&store::AgentProposalRecord {
959 id: "demo-proposal".to_owned(),
960 conversation_id: RELEASE_CHAT.to_owned(),
961 reply_to_message_id: Some("m1".to_owned()),
962 text: AGENT_DEMO_PROPOSAL.to_owned(),
963 mentions: vec![store::AgentProposalMention {
964 user_id: MARA_ID.to_owned(),
965 name: "Mara Lindqvist".to_owned(),
966 }],
967 images: vec![store::AttachmentImage {
968 name: "image-1.png".to_owned(),
969 format: "image/png".to_owned(),
970 bytes: encode_png(&MARA),
971 width: Some(PHOTO_SIZE as u32),
972 height: Some(PHOTO_SIZE as u32),
973 }],
974 agent: Some("claude".to_owned()),
975 session_id: None,
976 created_at: Utc::now() - Duration::minutes(1),
977 state: "pending".to_owned(),
978 resolved_at: None,
979 });
980 let _ = store.insert_agent_reaction(&store::AgentReactionRecord {
981 id: "demo-reaction".to_owned(),
982 conversation_id: "demo-chat-mara".to_owned(),
983 message_id: "ml1".to_owned(),
984 emoji: "\u{1F44D}".to_owned(),
985 agent: Some("claude".to_owned()),
986 session_id: None,
987 created_at: Utc::now() - Duration::minutes(1),
988 state: "pending".to_owned(),
989 resolved_at: None,
990 });
991}
992
993fn photo(palette: &Palette) -> AvatarState {
994 crate::data::avatar_state_from("image/png", encode_png(palette), false)
995}
996
997pub fn seed_directory(state: &mut AppState) {
998 state.own_status = crate::own_status::demo_status();
999 state.own_email = DEMO_USER_EMAIL.to_owned();
1000 state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());
1001 state.translation.settings = Some(language_settings());
1002 state.apply_date_locale();
1003 state.translation.languages = language_list();
1004 let directory = &mut state.directory;
1005 directory.me = Some(Person {
1006 user_id: DEMO_USER_ID.to_owned(),
1007 display_name: DEMO_USER_NAME.to_owned(),
1008 });
1009 let ids = |list: &[&str]| list.iter().map(|id| (*id).to_owned()).collect::<Vec<_>>();
1010 directory.folders = vec![
1011 FolderInfo {
1012 id: FAVORITES_ID.to_owned(),
1013 name: String::new(),
1014 kind: FolderKind::Favorites,
1015 expanded: None,
1016 conversation_ids: ids(&["demo-chat-mara", RELEASE_CHAT]),
1017 },
1018 FolderInfo {
1019 id: CUSTOMERS_FOLDER.to_owned(),
1020 name: "Customers".to_owned(),
1021 kind: FolderKind::UserCreated,
1022 expanded: None,
1023 conversation_ids: ids(&[
1024 "demo-chat-customer-1",
1025 "demo-chat-customer-2",
1026 "demo-chat-customer-3",
1027 "demo-chat-customer-4",
1028 ]),
1029 },
1030 FolderInfo {
1031 id: ATLAS_FOLDER.to_owned(),
1032 name: "Project Atlas".to_owned(),
1033 kind: FolderKind::UserCreated,
1034 expanded: None,
1035 conversation_ids: ids(&["demo-chat-atlas", "demo-chat-jonas"]),
1036 },
1037 FolderInfo {
1038 id: TODO_FOLDER.to_owned(),
1039 name: "To do".to_owned(),
1040 kind: FolderKind::UserCreated,
1041 expanded: None,
1042 conversation_ids: Vec::new(),
1043 },
1044 ];
1045 state.bot_apps.insert(BOT_CHAT.to_owned(), vec![bot_app()]);
1046 let directory = &mut state.directory;
1047 directory.pinned_channels = ids(&["demo-channel-1-1", "demo-channel-3-2"]);
1048 directory
1049 .unread_counts
1050 .insert("demo-chat-atlas".to_owned(), 5);
1051 directory
1052 .unread_counts
1053 .insert("demo-chat-customer-1".to_owned(), 2);
1054 directory
1055 .unread_counts
1056 .insert("demo-chat-customer-2".to_owned(), 1);
1057 directory
1058 .unread_counts
1059 .insert("demo-chat-allhands".to_owned(), 120);
1060 directory
1061 .unread_importance
1062 .insert(UNREAD_CHAT.to_owned(), MessageImportance::Urgent);
1063 directory
1064 .unread_importance
1065 .insert("demo-chat-customer-1".to_owned(), MessageImportance::High);
1066 directory.set_avatar(MARA_ID, photo(&MARA));
1067 directory.set_avatar(PRIYA_ID, photo(&PRIYA));
1068 directory.set_avatar(TOBIAS_ID, photo(&TOBIAS));
1069 for (user_id, kind) in [
1070 (MARA_ID, PresenceKind::Available),
1071 (JONAS_ID, PresenceKind::Busy),
1072 (PRIYA_ID, PresenceKind::Away),
1073 (TOBIAS_ID, PresenceKind::Offline),
1074 (LEA_ID, PresenceKind::Busy),
1075 (DEMO_USER_ID, PresenceKind::Available),
1076 ] {
1077 directory.set_presence(user_id, kind);
1078 }
1079 directory.set_activity(JONAS_ID, Some(Activity::InACall));
1080 directory.set_activity(LEA_ID, Some(Activity::InAConferenceCall));
1081 let directory_path = image_directory();
1082 if std::fs::create_dir_all(&directory_path).is_ok() {
1083 let path = directory_path.join("staging-dashboard.png");
1084 let png = encode_rgb(STAGING_SIZE.0, STAGING_SIZE.1, staging_pixel);
1085 if std::fs::write(&path, png).is_ok() {
1086 state.directory.set_image(STAGING_IMAGE_KEY, &path);
1087 state.directory.set_image(LINK_IMAGE_KEY, &path);
1088 }
1089 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1090 state.directory.set_image(
1091 demo_gifs::RECEIVED_GIF_KEY,
1092 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
1093 );
1094 }
1095 state.typing.start(
1096 "demo-chat-mara",
1097 MARA_ID,
1098 "Mara Lindqvist",
1099 Instant::now(),
1100 Utc::now(),
1101 );
1102 state.collapsed.insert(CUSTOMERS_FOLDER.to_owned());
1103 state.last_sync = Some(Utc::now());
1104 state.apply_bot_titles();
1105 seed_message_actions(state);
1106}
1107
1108fn seed_message_actions(state: &mut AppState) {
1109 state.pins.insert(
1110 PINNED_CHANNEL.to_owned(),
1111 vec![PinnedMessage {
1112 message_id: PINNED_POST.to_owned(),
1113 pinned_at: Some(at(0, 9, 45)),
1114 parent_id: None,
1115 }],
1116 );
1117 state.pins.insert(
1118 RELEASE_CHAT.to_owned(),
1119 vec![PinnedMessage {
1120 message_id: PINNED_MESSAGE.to_owned(),
1121 pinned_at: Some(at(0, 11, 30)),
1122 parent_id: None,
1123 }],
1124 );
1125 let ids: Vec<String> = SAVED_MESSAGES.iter().map(|id| (*id).to_owned()).collect();
1126 let records = state
1127 .store
1128 .messages_by_id(RELEASE_CHAT, &ids)
1129 .unwrap_or_default();
1130 let saved = SAVED_MESSAGES
1131 .iter()
1132 .enumerate()
1133 .filter_map(|(position, id)| {
1134 let record = records.get(*id)?;
1135 Some(SavedMessage {
1136 conversation_id: record.conversation_id.clone(),
1137 message_id: record.message_id.clone(),
1138 root_id: record.message_id.clone(),
1139 author_id: record.sender_id.clone(),
1140 author_name: record.sender_name.clone(),
1141 preview: crate::rows::reply_excerpt(record),
1142 saved_at: at(position as i64, 15, 20),
1143 topic: None,
1144 })
1145 })
1146 .collect();
1147 state.saved.replace(saved);
1148}
1149
1150pub fn forwarded_message(
1151 chat: &ChatRecord,
1152 source: &ForwardSource,
1153 comment: &str,
1154 now: DateTime<Utc>,
1155) -> (ChatRecord, MessageRecord) {
1156 let comment_html = if comment.is_empty() {
1157 String::new()
1158 } else {
1159 format!("<p>{}</p>", teams_core::escape_html(comment))
1160 };
1161 let quotes: String = source
1162 .messages
1163 .iter()
1164 .map(|item| {
1165 format!(
1166 "<blockquote itemscope=\"\" itemtype=\"{FORWARD_ITEMTYPE}\" itemid=\"{}\"><strong>{}</strong><p>{}</p></blockquote>",
1167 teams_core::escape_html(&item.message_id),
1168 teams_core::escape_html(&item.author),
1169 teams_core::escape_html(&item.text),
1170 )
1171 })
1172 .collect();
1173 let preview = source
1174 .messages
1175 .first()
1176 .map(|item| item.text.as_str())
1177 .unwrap_or_default();
1178 send_in_chat(chat, preview, &format!("{comment_html}{quotes}"), now)
1179}
1180
1181#[allow(clippy::too_many_arguments)]
1182fn message(
1183 conversation: &str,
1184 id: &str,
1185 reply_to: Option<&str>,
1186 sender: (&str, &str),
1187 time: DateTime<Utc>,
1188 html: &str,
1189 reactions_json: &str,
1190 edited: bool,
1191) -> MessageRecord {
1192 MessageRecord {
1193 conversation_id: conversation.to_owned(),
1194 message_id: id.to_owned(),
1195 reply_to_id: reply_to.map(str::to_owned),
1196 sender_id: Some(sender.0.to_owned()),
1197 sender_name: Some(sender.1.to_owned()),
1198 sender_application_id: None,
1199 links_json: "[]".to_owned(),
1200 created_at: time,
1201 edited_at: edited.then_some(time + Duration::minutes(2)),
1202 deleted: false,
1203 body_html: html.to_owned(),
1204 attachments_json: "[]".to_owned(),
1205 reactions_json: reactions_json.to_owned(),
1206 mentions_json: "[]".to_owned(),
1207 subject: None,
1208 call_event_json: None,
1209 importance: Default::default(),
1210 }
1211}
1212
1213pub fn roster_record(
1214 conversation: &str,
1215 id: &str,
1216 time: DateTime<Utc>,
1217 event: &teams_core::roster_event::RosterEvent,
1218) -> MessageRecord {
1219 MessageRecord {
1220 conversation_id: conversation.to_owned(),
1221 message_id: id.to_owned(),
1222 created_at: time,
1223 links_json: "[]".to_owned(),
1224 attachments_json: "[]".to_owned(),
1225 reactions_json: "[]".to_owned(),
1226 mentions_json: "[]".to_owned(),
1227 call_event_json: Some(event.to_json()),
1228 ..MessageRecord::default()
1229 }
1230}
1231
1232fn call_record(
1233 conversation: &str,
1234 id: &str,
1235 time: DateTime<Utc>,
1236 event: CallEvent,
1237) -> MessageRecord {
1238 MessageRecord {
1239 conversation_id: conversation.to_owned(),
1240 message_id: id.to_owned(),
1241 created_at: time,
1242 links_json: "[]".to_owned(),
1243 attachments_json: "[]".to_owned(),
1244 reactions_json: "[]".to_owned(),
1245 mentions_json: "[]".to_owned(),
1246 call_event_json: Some(event.to_json()),
1247 ..MessageRecord::default()
1248 }
1249}
1250
1251fn call_event(
1252 phase: CallPhase,
1253 call_id: &str,
1254 initiator: (&str, &str),
1255 duration_seconds: Option<u64>,
1256 participant_ids: &[&str],
1257) -> CallEvent {
1258 CallEvent {
1259 phase,
1260 call_type: CallType::Call,
1261 call_id: call_id.to_owned(),
1262 duration_seconds,
1263 initiator_id: Some(initiator.0.to_owned()),
1264 initiator_name: Some(initiator.1.to_owned()),
1265 participant_ids: participant_ids.iter().map(|id| (*id).to_owned()).collect(),
1266 participant_names: Vec::new(),
1267 recording: None,
1268 }
1269}
1270
1271fn call_messages() -> Vec<MessageRecord> {
1272 let mara = (MARA_ID, "Mara Lindqvist");
1273 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1274 let jonas = (JONAS_ID, "Jonas Ortega");
1275 let both = [DEMO_USER_ID, MARA_ID];
1276 vec![
1277 call_record(
1278 "demo-chat-mara",
1279 "call-1-started",
1280 at(0, 12, 4),
1281 call_event(CallPhase::Started, "demo-call-1", me, None, &[]),
1282 ),
1283 call_record(
1284 "demo-chat-mara",
1285 "call-1-ended",
1286 at(0, 12, 16),
1287 call_event(CallPhase::Ended, "demo-call-1", me, Some(723), &both),
1288 ),
1289 call_record(
1290 "demo-chat-mara",
1291 "call-2-started",
1292 at(0, 13, 9),
1293 call_event(CallPhase::Started, "demo-call-2", mara, None, &[]),
1294 ),
1295 call_record(
1296 "demo-chat-mara",
1297 "call-2-ended",
1298 at(0, 13, 10),
1299 call_event(CallPhase::Ended, "demo-call-2", mara, Some(60), &[MARA_ID]),
1300 ),
1301 call_record(
1302 "demo-chat-meeting-standup",
1303 "call-3-started",
1304 at(0, 9, 50),
1305 CallEvent {
1306 call_type: CallType::Meeting,
1307 ..call_event(CallPhase::Started, "demo-call-3", jonas, None, &[])
1308 },
1309 ),
1310 ]
1311}
1312
1313fn with_importance(mut record: MessageRecord, importance: MessageImportance) -> MessageRecord {
1314 record.importance = importance;
1315 record
1316}
1317
1318fn with_subject(mut record: MessageRecord, subject: &str) -> MessageRecord {
1319 record.subject = Some(subject.to_owned());
1320 record
1321}
1322
1323fn with_attachments(mut record: MessageRecord, attachments_json: &str) -> MessageRecord {
1324 record.attachments_json = attachments_json.to_owned();
1325 record
1326}
1327
1328fn with_links(mut record: MessageRecord, links_json: String) -> MessageRecord {
1329 record.links_json = links_json;
1330 record
1331}
1332
1333pub fn link_preview(url: &str) -> Option<LinkPreview> {
1334 Some(LinkPreview {
1335 url: url.to_owned(),
1336 title: Some("Release checklist Q4".to_owned()),
1337 description: Some(
1338 "Everything that has to be green before the release candidate goes out on Friday."
1339 .to_owned(),
1340 ),
1341 image_url: Some(LINK_IMAGE_KEY.to_owned()),
1342 image_width: Some(LINK_IMAGE_SIZE.0),
1343 image_height: Some(LINK_IMAGE_SIZE.1),
1344 })
1345}
1346
1347fn bot_messages() -> Vec<MessageRecord> {
1348 let card = serde_json::json!({
1349 "type": "AdaptiveCard",
1350 "body": [
1351 {"type": "ColumnSet", "columns": [
1352 {"type": "Column", "width": "auto", "verticalContentAlignment": "center", "items": [
1353 {"type": "Image", "url": CARD_PERSON_URL, "size": "small", "style": "person", "height": "32px"}
1354 ]},
1355 {"type": "Column", "width": "stretch", "verticalContentAlignment": "center", "items": [
1356 {"type": "TextBlock", "size": "medium", "weight": "bolder", "wrap": true, "text": "Mara Lindqvist edited your page"}
1357 ]}
1358 ]},
1359 {"type": "ColumnSet", "separator": true, "columns": [
1360 {"type": "Column", "width": "auto", "items": [
1361 {"type": "Image", "url": CARD_PAGE_URL, "width": "24px", "height": "24px"}
1362 ]},
1363 {"type": "Column", "width": "stretch", "items": [
1364 {"type": "TextBlock", "weight": "bolder", "wrap": true, "text": "[**Release Checklist Q4**](https://example.com/wiki/release-checklist) in [**Platform**](https://example.com/wiki/platform)"},
1365 {"type": "TextBlock", "spacing": "small", "isSubtle": true, "wrap": true, "text": "Owned by: Dana Demo"}
1366 ]}
1367 ]},
1368 {"type": "TextBlock", "id": "owner-note", "isVisible": false, "isSubtle": true, "wrap": true, "text": "Owner notes are only shown on request."},
1369 {"type": "ActionSet", "actions": [
1370 {"type": "Action.OpenUrl", "title": "View page", "url": "https://example.com/wiki/release-checklist"},
1371 {"type": "Action.OpenUrl", "title": "View changes", "url": "https://example.com/wiki/release-checklist/changes"},
1372 {"type": "Action.Submit", "title": "Watch page", "data": {"action": "watch"}},
1373 {"type": "Action.Submit", "title": "Stop watching", "data": {"action": "unwatch"}},
1374 {"type": "Action.Submit", "title": "Settings", "data": {"msteams": {"type": "task/fetch"}}},
1375 {"type": "Action.ToggleVisibility", "title": "Owner notes", "targetElements": ["owner-note"]},
1376 {"type": "Action.ShowCard", "title": "Details", "card": {"body": [
1377 {"type": "TextBlock", "wrap": true, "text": "Last edited by **Mara Lindqvist** on Tuesday."}
1378 ]}}
1379 ]}
1380 ]
1381 });
1382 let mut messages = vec![
1383 bot_card_message("b1", at(0, 13, 45), &card),
1384 bot_card_message("b2", at(0, 13, 52), &input_card()),
1385 bot_card_message(
1386 "b3",
1387 at(0, 13, 58),
1388 &crate::demo_input_cards::all_inputs_card(),
1389 ),
1390 ];
1391 messages.extend(
1392 crate::demo_cards::behaviour_cards()
1393 .iter()
1394 .zip(0u32..)
1395 .map(|(card, index)| bot_card_message(&format!("g{index}"), at(0, 14, index), card)),
1396 );
1397 messages.extend(crate::demo_chart_cards::cards().iter().zip(0..).map(
1398 |(chart_card, minute)| {
1399 bot_card_message(&format!("c{minute}"), at(0, 15, minute), chart_card)
1400 },
1401 ));
1402 messages
1403}
1404
1405fn bot_card_message(id: &str, time: DateTime<Utc>, card: &serde_json::Value) -> MessageRecord {
1406 let attachments = serde_json::json!([{
1407 "content_type": "application/vnd.microsoft.card.adaptive",
1408 "name": null,
1409 "url": null,
1410 "text": null,
1411 "content": card.to_string()
1412 }]);
1413 let mut record = with_attachments(
1414 message(
1415 BOT_CHAT,
1416 id,
1417 None,
1418 ("", BOT_NAME),
1419 time,
1420 &format!("<attachment id=\"{id}\"></attachment>"),
1421 "[]",
1422 false,
1423 ),
1424 &attachments.to_string(),
1425 );
1426 record.sender_id = None;
1427 record.sender_application_id = Some(BOT_ID.to_owned());
1428 record
1429}
1430
1431fn input_card() -> serde_json::Value {
1432 serde_json::json!({
1433 "type": "AdaptiveCard",
1434 "body": [
1435 {"type": "TextBlock", "size": "medium", "weight": "bolder", "text": "Release request"},
1436 {"type": "Input.Text", "id": "title", "label": "Title", "placeholder": "Short summary", "isRequired": true, "errorMessage": "Give the release a title"},
1437 {"type": "Input.Text", "id": "notes", "label": "Notes", "placeholder": "Anything the reviewers should know", "isMultiline": true},
1438 {"type": "Input.Text", "id": "token", "label": "Access code", "style": "Password", "regex": "^\\d{4}$", "errorMessage": "Enter four digits"},
1439 {"type": "ColumnSet", "columns": [
1440 {"type": "Column", "width": "stretch", "items": [
1441 {"type": "Input.Number", "id": "count", "label": "Servers", "placeholder": "1-20", "min": 1, "max": 20, "value": 4}
1442 ]},
1443 {"type": "Column", "width": "stretch", "items": [
1444 {"type": "Input.Date", "id": "day", "label": "Release day", "value": "2026-11-02"}
1445 ]},
1446 {"type": "Column", "width": "stretch", "items": [
1447 {"type": "Input.Time", "id": "hour", "label": "Start time", "value": "09:30"}
1448 ]}
1449 ]},
1450 {"type": "Input.ChoiceSet", "id": "channel", "label": "Channel", "placeholder": "Pick a channel", "isRequired": true, "choices": [
1451 {"title": "Stable", "value": "stable"}, {"title": "Beta", "value": "beta"}, {"title": "Nightly", "value": "nightly"}
1452 ]},
1453 {"type": "Input.ChoiceSet", "id": "region", "label": "Region", "style": "expanded", "value": "eu", "choices": [
1454 {"title": "Europe", "value": "eu"}, {"title": "North America", "value": "na"}
1455 ]},
1456 {"type": "Input.ChoiceSet", "id": "checks", "label": "Checks", "style": "expanded", "isMultiSelect": true, "value": "lint", "choices": [
1457 {"title": "Lint", "value": "lint"}, {"title": "Unit tests", "value": "unit"}, {"title": "Smoke tests", "value": "smoke"}
1458 ]},
1459 {"type": "Input.Toggle", "id": "notify", "title": "Notify the team", "value": "yes", "valueOn": "yes", "valueOff": "no"}
1460 ],
1461 "actions": [
1462 {"type": "Action.Submit", "title": "Request release", "data": {"action": "release"}},
1463 {"type": "Action.Submit", "title": "Cancel", "associatedInputs": "none", "data": {"action": "cancel"}}
1464 ]
1465 })
1466}
1467
1468fn bot_app() -> ChatApp {
1469 ChatApp {
1470 app_id: "demo-app-wiki".to_owned(),
1471 name: BOT_APP_NAME.to_owned(),
1472 bot_ids: vec![BOT_ID.to_owned()],
1473 small_image_url: None,
1474 accent_color: None,
1475 web_application_resource: None,
1476 }
1477}
1478
1479pub async fn card_answer(task: CardTask) -> CardAnswer {
1480 tokio::time::sleep(CARD_ANSWER_DELAY).await;
1481 let data = match task {
1482 CardTask::Submit(_) => {
1483 return Ok((
1484 CardActionOutcome::Message("Settings saved".into()),
1485 Some((bot_app(), BOT_ID.to_owned())),
1486 ));
1487 }
1488 CardTask::Action(action) => match action.invoke_payload() {
1489 Some(payload) => payload.value,
1490 None => return Err("Not supported".to_owned()),
1491 },
1492 };
1493 let outcome = if data.pointer("/data/type").and_then(|kind| kind.as_str()) == Some("task/fetch")
1494 {
1495 CardActionOutcome::Dialog(TaskDialog {
1496 title: None,
1497 width: 520,
1498 height: 300,
1499 kind: TaskDialogKind::Card(settings_card().to_string()),
1500 })
1501 } else if data.get("action").and_then(|action| action.as_str()) == Some("unwatch") {
1502 CardActionOutcome::Failed("The app answered 500: demo failure".into())
1503 } else {
1504 CardActionOutcome::Sent
1505 };
1506 Ok((outcome, Some((bot_app(), BOT_ID.to_owned()))))
1507}
1508
1509pub async fn refresh_answer() -> CardAnswer {
1510 tokio::time::sleep(CARD_ANSWER_DELAY).await;
1511 Ok((
1512 CardActionOutcome::ReplaceCard(crate::demo_cards::refreshed_card().to_string()),
1513 Some((bot_app(), BOT_ID.to_owned())),
1514 ))
1515}
1516
1517fn settings_card() -> serde_json::Value {
1518 serde_json::json!({
1519 "type": "AdaptiveCard",
1520 "body": [
1521 {"type": "TextBlock", "weight": "bolder", "text": "Notification settings"},
1522 {"type": "TextBlock", "wrap": true, "isSubtle": true, "text": "Choose how the bot tells you about page changes."},
1523 {"type": "Input.ChoiceSet", "id": "frequency", "label": "Frequency", "style": "expanded", "value": "daily", "choices": [
1524 {"title": "Immediately", "value": "now"}, {"title": "Daily digest", "value": "daily"}
1525 ]},
1526 {"type": "Input.Toggle", "id": "mentions", "title": "Only when I am mentioned", "value": "false"}
1527 ],
1528 "actions": [
1529 {"type": "Action.Submit", "title": "Save", "data": {"save": true}}
1530 ]
1531 })
1532}
1533
1534pub const DEMO_TENANT_ID: &str = "demo-tenant";
1535const DEMO_MEETING_LINK: &str = "https://teams.microsoft.com/l/meetup-join/19%3ameeting_ZGVtbw%40thread.v2/0?context=%7b%22Tid%22%3a%22demo-tenant%22%2c%22Oid%22%3a%22demo-mara%22%7d";
1536
1537fn meeting_link_messages() -> Vec<MessageRecord> {
1538 let mara = (MARA_ID, "Mara Lindqvist");
1539 vec![message(
1540 "demo-chat-mara",
1541 "ml1",
1542 None,
1543 mara,
1544 at(0, 13, 38),
1545 &format!(
1546 "<p>Let's sync live, here is the meeting: <a href=\"{DEMO_MEETING_LINK}\">Join the Teams meeting</a></p>"
1547 ),
1548 "[]",
1549 false,
1550 )]
1551}
1552
1553fn standup_messages() -> Vec<MessageRecord> {
1554 let jonas = (JONAS_ID, "Jonas Ortega");
1555 let priya = (PRIYA_ID, "Priya Nair");
1556 vec![
1557 with_attachments(
1558 message(
1559 "demo-chat-meeting-standup",
1560 "su1",
1561 None,
1562 priya,
1563 at(0, 9, 30),
1564 "<p>Notes from today.</p>",
1565 "[]",
1566 false,
1567 ),
1568 r#"[{"content_type":"reference","name":"Standup-notes.docx","url":"https://example.com/files/standup-notes.docx","text":null,"size":38900}]"#,
1569 ),
1570 with_attachments(
1571 message(
1572 "demo-chat-meeting-standup",
1573 "su2",
1574 None,
1575 jonas,
1576 at(0, 9, 45),
1577 "<p>Recording is available</p>",
1578 "[]",
1579 false,
1580 ),
1581 r#"[{"content_type":"reference","name":"Standup-recording.mp4","url":"https://contoso-my.sharepoint.com/personal/jonas_contoso_com/Documents/Recordings/Standup-recording.mp4","text":null,"size":18400000}]"#,
1582 ),
1583 with_links(
1584 message(
1585 "demo-chat-meeting-standup",
1586 "su3",
1587 None,
1588 jonas,
1589 at(0, 9, 50),
1590 "<p><a href=\"https://example.com/checklist\">https://example.com/checklist</a></p>",
1591 "[]",
1592 false,
1593 ),
1594 link_preview("https://example.com/checklist")
1595 .map(|preview| preview.links_json())
1596 .unwrap_or_default(),
1597 ),
1598 message(
1599 "demo-chat-meeting-standup",
1600 "su4",
1601 None,
1602 priya,
1603 at(0, 9, 52),
1604 "<p>I will quickly fix the comments and then push the final version before the review starts.</p>",
1605 "[]",
1606 false,
1607 ),
1608 ]
1609}
1610
1611fn notes_messages() -> Vec<MessageRecord> {
1612 vec![message(
1613 NOTES_CHAT_ID,
1614 "n1",
1615 None,
1616 (DEMO_USER_ID, DEMO_USER_NAME),
1617 at(0, 8, 20),
1618 "<p>Release notes draft</p>",
1619 "[]",
1620 false,
1621 )]
1622}
1623
1624fn priority_messages() -> Vec<MessageRecord> {
1625 let priya = (PRIYA_ID, "Priya Nair");
1626 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1627 vec![
1628 message(
1629 PRIORITY_CHAT,
1630 "p1",
1631 None,
1632 me,
1633 at(0, 10, 40),
1634 "<p>Have you seen the error on staging yet?</p>",
1635 "[]",
1636 false,
1637 ),
1638 message(
1639 PRIORITY_CHAT,
1640 "p2",
1641 None,
1642 priya,
1643 at(0, 10, 47),
1644 &format!(
1645 "<p>Yes, here is the screenshot:</p><img src=\"{PENDING_IMAGE_KEY}\" width=\"1280\" height=\"720\">"
1646 ),
1647 "[]",
1648 false,
1649 ),
1650 ]
1651 .into_iter()
1652 .map(|record| match record.message_id.as_str() {
1653 "p2" => with_importance(record, MessageImportance::High),
1654 _ => record,
1655 })
1656 .collect()
1657}
1658
1659fn reaction(kind: &str, users: &[(&str, &str, DateTime<Utc>)]) -> Vec<serde_json::Value> {
1660 users
1661 .iter()
1662 .map(|(user_id, user_name, created_at)| {
1663 serde_json::json!({
1664 "reaction_type": kind,
1665 "user_id": user_id,
1666 "user_name": user_name,
1667 "created_at": created_at,
1668 })
1669 })
1670 .collect()
1671}
1672
1673fn reactions_json(groups: Vec<Vec<serde_json::Value>>) -> String {
1674 serde_json::Value::Array(groups.into_iter().flatten().collect()).to_string()
1675}
1676
1677fn release_messages() -> Vec<MessageRecord> {
1678 let chat = RELEASE_CHAT;
1679 let mara = (MARA_ID, "Mara Lindqvist");
1680 let jonas = (JONAS_ID, "Jonas Ortega");
1681 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1682 let jonas_name = "Jonas Ortega";
1683 let priya_name = "Priya Nair";
1684 let lea_name = "Lea Schneider";
1685 let mara_name = "Mara Lindqvist";
1686 let tobias_name = "Tobias Klein";
1687 let likes = reactions_json(vec![reaction(
1688 "like",
1689 &[
1690 (JONAS_ID, jonas_name, at(1, 16, 30)),
1691 (PRIYA_ID, priya_name, at(1, 17, 2)),
1692 (LEA_ID, lea_name, at(0, 8, 15)),
1693 ],
1694 )]);
1695 let hearts = reactions_json(vec![reaction(
1696 "heart",
1697 &[
1698 (DEMO_USER_ID, DEMO_USER_NAME, at(0, 10, 35)),
1699 (JONAS_ID, jonas_name, at(0, 10, 33)),
1700 ],
1701 )]);
1702 let single = reactions_json(vec![reaction(
1703 "laugh",
1704 &[(PRIYA_ID, priya_name, at(0, 9, 10))],
1705 )]);
1706 let many = reactions_json(vec![
1707 reaction(
1708 "like",
1709 &[
1710 (MARA_ID, mara_name, at(0, 13, 37)),
1711 (JONAS_ID, jonas_name, at(0, 13, 38)),
1712 (PRIYA_ID, priya_name, at(0, 13, 40)),
1713 (LEA_ID, lea_name, at(0, 13, 45)),
1714 (TOBIAS_ID, tobias_name, at(0, 13, 50)),
1715 ],
1716 ),
1717 reaction(
1718 "heart",
1719 &[
1720 (LEA_ID, lea_name, at(0, 13, 46)),
1721 (TOBIAS_ID, tobias_name, at(0, 13, 51)),
1722 ],
1723 ),
1724 reaction("\u{1F389}", &[(MARA_ID, mara_name, at(0, 13, 39))]),
1725 ]);
1726 vec![
1727 message(
1728 chat,
1729 "m1",
1730 None,
1731 mara,
1732 at(1, 16, 20),
1733 "<p>Release candidate is on staging. Can someone run the regression suite?</p>",
1734 "[]",
1735 false,
1736 ),
1737 message(
1738 chat,
1739 "m2",
1740 None,
1741 mara,
1742 at(1, 16, 22),
1743 "<p>Checklist lives in <a href=\"https://example.com/checklist\">release checklist</a>.</p>",
1744 &likes,
1745 false,
1746 ),
1747 with_links(
1748 message(
1749 chat,
1750 "m2a",
1751 None,
1752 mara,
1753 at(1, 16, 23),
1754 "<p><a href=\"https://example.com/checklist\">https://example.com/checklist</a></p>",
1755 "[]",
1756 false,
1757 ),
1758 link_preview("https://example.com/checklist")
1759 .map(|preview| preview.links_json())
1760 .unwrap_or_default(),
1761 ),
1762 message(
1763 chat,
1764 "m2b",
1765 None,
1766 mara,
1767 at(1, 16, 40),
1768 &format!(
1769 "<p>Staging dashboard right now:</p><img src=\"{STAGING_IMAGE_KEY}\" width=\"{}\" height=\"{}\">",
1770 STAGING_SIZE.0, STAGING_SIZE.1
1771 ),
1772 "[]",
1773 false,
1774 ),
1775 with_attachments(
1776 message(
1777 chat,
1778 "m2c",
1779 None,
1780 mara,
1781 at(1, 16, 41),
1782 "<p>Checklist and rollout plan attached.</p>",
1783 "[]",
1784 false,
1785 ),
1786 r#"[{"content_type":"reference","name":"Release-Checklist-Q4.xlsx","url":"https://example.com/files/checklist.xlsx","text":null,"size":48213},{"content_type":"reference","name":"Rollout-Plan.pdf","url":"https://example.com/files/plan.pdf","text":null,"size":2306867}]"#,
1787 ),
1788 message(
1789 chat,
1790 "m3",
1791 None,
1792 me,
1793 at(0, 9, 2),
1794 "<p>I'll take the changelog.</p>",
1795 &single,
1796 false,
1797 ),
1798 message(
1799 chat,
1800 "m4",
1801 None,
1802 jonas,
1803 at(0, 10, 14),
1804 "<p><at id=\"0\">Mara Lindqvist</at> can you take a quick look at this? It runs before <code>cargo test</code>.</p><pre><code class=\"language-rust\">// only release branches\nfn freeze(branch: &amp;str) -&gt; bool {\n branch.starts_with(\"release/\")\n}</code></pre>",
1805 "[]",
1806 false,
1807 ),
1808 message(
1809 chat,
1810 "m5",
1811 None,
1812 mara,
1813 at(0, 10, 31),
1814 "<blockquote itemscope=\"\" itemtype=\"http://schema.skype.com/Reply\" itemid=\"m4\"><strong itemprop=\"mri\">Jonas Ortega</strong><p itemprop=\"preview\">can you take a quick look at this?</p></blockquote><p>Looks good. Small thing: the name could say what it checks.</p>",
1815 &hearts,
1816 true,
1817 ),
1818 message(
1819 chat,
1820 "m5b",
1821 None,
1822 mara,
1823 at(0, 10, 40),
1824 "<p>Rollout for Friday:</p><ul><li>Freeze the release branch</li><li>Run the smoke tests on staging, then post the results in the channel</li><li>Ship<ul><li>Windows installer</li><li>Linux <code>.AppImage</code></li></ul></li></ul><p>Order:</p><ol><li>Tag</li><li>Build</li><li>Announce</li></ol>",
1825 "[]",
1826 false,
1827 ),
1828 message(
1829 chat,
1830 "m5c",
1831 None,
1832 jonas,
1833 at(0, 11, 5),
1834 "<h2>Release notes 0.2</h2><p>The <s>old sync path</s> <u>is gone</u>.</p><table><thead><tr><th>Area</th><th>Owner</th></tr></thead><tbody><tr><td>Sync</td><td>Priya</td></tr><tr><td>Render</td><td>Jonas</td></tr></tbody></table><hr><blockquote>Measure twice, cut once.</blockquote><p><span style=\"background-color: rgb(255, 255, 0)\">Important:</span> <span style=\"color: #c00000\">backup first</span>.</p><p style=\"margin-left:40px;\">Then <span style=\"color:#1E53A3;\">sync</span> <span style=\"background-color:#82CDA8;\">once</span>.</p><pre class=\"language-plaintext skipProofing\" spellcheck=\"false\"><code>backup --all<br>sync --once</code></pre>",
1835 "[]",
1836 false,
1837 ),
1838 message(
1839 chat,
1840 "m5d",
1841 None,
1842 (PRIYA_ID, priya_name),
1843 at(0, 12, 20),
1844 &format!(
1845 "<p>FYI, the customer asked for this.</p><blockquote itemscope=\"\" itemtype=\"{FORWARD_ITEMTYPE}\" itemid=\"1790000000000\"><strong>Tobias Klein</strong><p>Can we move the freeze to Thursday? The customer demo is on Friday morning.</p></blockquote>"
1846 ),
1847 "[]",
1848 false,
1849 ),
1850 message(
1851 chat,
1852 "m5e",
1853 None,
1854 jonas,
1855 at(0, 12, 40),
1856 "<p>Context from the old planning chat.</p><attachment id=\"1789000000000\"></attachment>",
1857 r#"[{"content_type":"forwardedMessageReference","name":null,"url":null,"text":null,"id":"1789000000000","content":null,"unavailable":true}]"#,
1858 false,
1859 ),
1860 message(
1861 chat,
1862 "m6",
1863 None,
1864 me,
1865 at(0, 13, 35),
1866 "<p>Thanks, renamed. Tagging now.</p>",
1867 "[]",
1868 false,
1869 ),
1870 message(
1871 chat,
1872 "m7",
1873 None,
1874 me,
1875 at(0, 13, 36),
1876 "<p>Build 42 is green, see <a href=\"https://example.com/build/42\">pipeline</a>.</p>",
1877 &many,
1878 false,
1879 ),
1880 with_links(
1881 message(
1882 chat,
1883 "m7a",
1884 None,
1885 me,
1886 at(0, 13, 37),
1887 "<p>Notes are in <a href=\"https://example.com/notes\">https://example.com/notes</a></p>",
1888 "[]",
1889 false,
1890 ),
1891 LinkPreview {
1892 url: "https://example.com/notes".to_owned(),
1893 title: Some("Release notes 0.2".to_owned()),
1894 description: Some("What changed since 0.1".to_owned()),
1895 image_url: None,
1896 image_width: None,
1897 image_height: None,
1898 }
1899 .links_json(),
1900 ),
1901 message(
1902 chat,
1903 "m8",
1904 None,
1905 jonas,
1906 at(0, 13, 40),
1907 "<p>Formula check: H<sub>2</sub>O and x<sup>2</sup> + y<sup>2</sup>. <span style=\"font-size:xx-small;\">Small print, reviewed by <at id=\"0\">Mara Lindqvist</at>.</span> <span style=\"font-size:x-large;\">Big news:</span> the <span style=\"font-size:x-large;\"><a href=\"https://example.com/notes\">release notes</a></span> are out.</p>",
1908 "[]",
1909 false,
1910 ),
1911 message(
1912 chat,
1913 "m9",
1914 None,
1915 (PRIYA_ID, priya_name),
1916 at(0, 13, 45),
1917 &format!(
1918 "<p>Ship it!</p><img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"Party\" itemtype=\"http://schema.skype.com/Giphy\">",
1919 demo_gifs::RECEIVED_GIF_KEY,
1920 demo_gifs::RECEIVED_GIF_SIZE.0,
1921 demo_gifs::RECEIVED_GIF_SIZE.1
1922 ),
1923 "[]",
1924 false,
1925 ),
1926 message(
1927 chat,
1928 FRENCH_MESSAGE,
1929 None,
1930 (LEA_ID, lea_name),
1931 at(0, 13, 47),
1932 "<p>Bonjour \u{e0} tous, la <strong>version 0.2</strong> est pr\u{ea}te. Pouvez-vous v\u{e9}rifier la liste de contr\u{f4}le avant vendredi\u{a0}?</p>",
1933 "[]",
1934 false,
1935 ),
1936 message(
1937 chat,
1938 SPANISH_MESSAGE,
1939 None,
1940 jonas,
1941 at(0, 13, 49),
1942 "<p>Gracias por el aviso. Probar\u{e9} la compilaci\u{f3}n esta tarde y os dir\u{e9} si algo falla.</p>",
1943 "[]",
1944 false,
1945 ),
1946 message(
1947 chat,
1948 "m10",
1949 None,
1950 (PRIYA_ID, priya_name),
1951 at(0, 13, 50),
1952 "<p><emoji id=\"heart\" alt=\"\u{2764}\u{fe0f}\" title=\"Heart\"></emoji></p>",
1953 &many,
1954 false,
1955 ),
1956 message(
1957 chat,
1958 "m11",
1959 None,
1960 me,
1961 at(0, 13, 51),
1962 "<p>\u{1f44d}\u{1f389}</p>",
1963 "[]",
1964 false,
1965 ),
1966 ]
1967}
1968
1969fn unread_messages() -> Vec<MessageRecord> {
1970 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1971 let lea = (LEA_ID, "Lea Schneider");
1972 let tobias = (TOBIAS_ID, "Tobias Klein");
1973 let rows = [
1974 (
1975 "u1",
1976 me,
1977 at(1, 17, 5),
1978 "<p>Can you enable access for North?</p>",
1979 ),
1980 ("u2", tobias, at(1, 17, 20), "<p>I'll check with IT.</p>"),
1981 (
1982 "u3",
1983 lea,
1984 at(0, 12, 40),
1985 "<p>Good morning, access is ready.</p>",
1986 ),
1987 (
1988 "u4",
1989 lea,
1990 at(0, 12, 41),
1991 "<p>Sign in with your company ID, no password needed.</p>",
1992 ),
1993 ("u5", lea, at(0, 12, 50), "<p>Access is enabled now</p>"),
1994 ];
1995 rows.into_iter()
1996 .map(|(id, sender, time, html)| {
1997 message(UNREAD_CHAT, id, None, sender, time, html, "[]", false)
1998 })
1999 .map(|record| match record.message_id.as_str() {
2000 "u5" => with_importance(record, MessageImportance::Urgent),
2001 _ => record,
2002 })
2003 .collect()
2004}
2005
2006const DEMO_EXTRA_TABS_CHANNEL: &str = "demo-channel-1-2";
2007const DEMO_EXTRA_TABS: [&str; 6] = [
2008 "Incident dashboard",
2009 "Postmortems",
2010 "Escalation policy",
2011 "Status page",
2012 "Vendor contacts",
2013 "On-call calendar",
2014];
2015
2016fn demo_tab(
2017 channel_id: &str,
2018 name: &str,
2019 definition_id: &str,
2020 open_url: Option<&str>,
2021) -> ChannelTabRecord {
2022 ChannelTabRecord {
2023 tab_id: format!("{channel_id}-{}", name.to_lowercase().replace(' ', "-")),
2024 name: name.to_owned(),
2025 definition_id: definition_id.to_owned(),
2026 open_url: open_url.map(str::to_owned),
2027 }
2028}
2029
2030fn demo_channel_tabs(channel_id: &str) -> Vec<ChannelTabRecord> {
2031 let mut tabs = vec![
2032 demo_tab(
2033 channel_id,
2034 "Runbook",
2035 "com.microsoft.teamspace.tab.web",
2036 Some("https://wiki.example.com/display/TEAM/Runbook"),
2037 ),
2038 demo_tab(
2039 channel_id,
2040 "Sprint board",
2041 "com.microsoft.teamspace.tab.planner",
2042 None,
2043 ),
2044 demo_tab(
2045 channel_id,
2046 "Team notes",
2047 "0d820ecd-def2-4297-adad-78056cde7c78",
2048 Some("https://onenote.example.com/notes"),
2049 ),
2050 ];
2051 if channel_id == DEMO_EXTRA_TABS_CHANNEL {
2052 tabs.extend(DEMO_EXTRA_TABS.iter().map(|name| {
2053 demo_tab(
2054 channel_id,
2055 name,
2056 "com.microsoft.teamspace.tab.web",
2057 Some("https://wiki.example.com/display/TEAM/Page"),
2058 )
2059 }));
2060 }
2061 tabs
2062}
2063
2064fn demo_team_layout(channels: &[ChannelRecord]) -> Vec<TeamLayoutRecord> {
2065 DEMO_TEAM_ORDER
2066 .iter()
2067 .map(|team_id| TeamLayoutRecord {
2068 rights: store::TeamRights {
2069 add_channel: true,
2070 add_private_channel: true,
2071 ..Default::default()
2072 },
2073 team_id: (*team_id).to_owned(),
2074 hidden: *team_id == DEMO_HIDDEN_TEAM,
2075 channels: channels
2076 .iter()
2077 .filter(|channel| channel.team_id == *team_id)
2078 .map(|channel| ChannelLayoutRecord {
2079 substrate_group_id: None,
2080 channel_id: channel.id.clone(),
2081 general: channel.name == "General",
2082 hidden: channel.id == DEMO_HIDDEN_CHANNEL,
2083 tabs: demo_channel_tabs(&channel.id),
2084 notifications: DEMO_CHANNEL_NOTIFICATIONS
2085 .iter()
2086 .find(|(id, _, _)| *id == channel.id)
2087 .map(|(_, level, include_replies)| ChannelNotifications {
2088 level: *level,
2089 include_replies: *include_replies,
2090 })
2091 .unwrap_or_default(),
2092 })
2093 .collect(),
2094 })
2095 .collect()
2096}
2097
2098const ROLLOUT_REPLIES: [(&str, &str); 12] = [
2099 (MARA_ID, "Staging looks good on my side."),
2100 (JONAS_ID, "Smoke tests passed, no regressions."),
2101 (PRIYA_ID, "Docs for the new settings page are merged."),
2102 (LEA_ID, "Support is briefed, nothing blocking."),
2103 (MARA_ID, "Can we keep the old export for one more release?"),
2104 (JONAS_ID, "Yes, behind a flag. I will add it today."),
2105 (PRIYA_ID, "Changelog draft is ready for review."),
2106 (LEA_ID, "Customer success wants a heads-up the day before."),
2107 (MARA_ID, "I will send that mail on Thursday."),
2108 (JONAS_ID, "Flag is in, rebuilding staging now."),
2109 (PRIYA_ID, "Rollback steps are in the runbook."),
2110 (LEA_ID, "All green from QA. Go for Friday."),
2111];
2112
2113fn channel_messages() -> Vec<MessageRecord> {
2114 let channel = "demo-channel-1-1";
2115 let mara = (MARA_ID, "Mara Lindqvist");
2116 let tobias = (TOBIAS_ID, "Tobias Klein");
2117 let people = [
2118 (MARA_ID, "Mara Lindqvist"),
2119 (JONAS_ID, "Jonas Ortega"),
2120 (PRIYA_ID, "Priya Nair"),
2121 (LEA_ID, "Lea Schneider"),
2122 ];
2123 let rollout_replies = ROLLOUT_REPLIES
2124 .iter()
2125 .enumerate()
2126 .map(|(index, (sender, text))| {
2127 let sender = people
2128 .iter()
2129 .copied()
2130 .find(|(id, _)| id == sender)
2131 .expect("known person");
2132 message(
2133 channel,
2134 &format!("t3r{}", index + 1),
2135 Some("t3"),
2136 sender,
2137 at(0, 9, 40) + Duration::minutes(6 * index as i64),
2138 &format!("<p>{text}</p>"),
2139 "[]",
2140 false,
2141 )
2142 });
2143 let mut records = vec![
2144 message(
2145 channel,
2146 "t1",
2147 None,
2148 mara,
2149 at(0, 8, 0),
2150 "<p>Weekly sync notes are up.</p>",
2151 "[]",
2152 false,
2153 ),
2154 message(
2155 channel,
2156 "t1r1",
2157 Some("t1"),
2158 tobias,
2159 at(0, 8, 20),
2160 "<p>Thanks, adding my items.</p>",
2161 "[]",
2162 false,
2163 ),
2164 with_subject(
2165 message(
2166 channel,
2167 "t3",
2168 None,
2169 tobias,
2170 at(0, 9, 30),
2171 "<p>Release build 42 is green, deploying to staging now.</p>",
2172 "[]",
2173 false,
2174 ),
2175 "Release 42 rollout",
2176 ),
2177 message(
2178 channel,
2179 "t2",
2180 None,
2181 tobias,
2182 at(0, 10, 0),
2183 "<p>Who owns the on-call handover?</p>",
2184 "[]",
2185 false,
2186 ),
2187 message(
2188 channel,
2189 "t4",
2190 None,
2191 mara,
2192 at(3, 8, 42),
2193 "<p>Sprint Demos.</p><p>I added you both to the sprint. <at id=\"0\">Tobias Klein</at> did you present everything about the migration tool? The spec is at <a href=\"https://wiki.example.com/display/TEAM/Settings+types+and+password+policies\">https://wiki.example.com/display/TEAM/Settings+types+and+password+policies</a>Can you please review it?</p>",
2194 "[]",
2195 false,
2196 ),
2197 message(
2198 channel,
2199 "t4r1",
2200 Some("t4"),
2201 tobias,
2202 at(0, 9, 15),
2203 "<p>Yes, all done.</p>",
2204 "[]",
2205 false,
2206 ),
2207 ];
2208 records.extend(rollout_replies);
2209 records.extend(code_post(channel, tobias));
2210 records.extend(shared_channel_messages(channel, mara, tobias));
2211 records
2212}
2213
2214fn code_post(channel: &str, tobias: (&str, &str)) -> Vec<MessageRecord> {
2215 let laughs = reactions_json(vec![reaction(
2216 "laugh",
2217 &[
2218 (PRIYA_ID, "Priya Nair", at(0, 11, 20)),
2219 (JONAS_ID, "Jonas Ortega", at(0, 11, 22)),
2220 ],
2221 )]);
2222 vec![
2223 with_subject(
2224 message(
2225 channel,
2226 "t8",
2227 None,
2228 tobias,
2229 at(0, 11, 5),
2230 "<p>I got this error message when running \"Invoke-WebRequest\" in the build script:</p><p>&nbsp;</p><p><code>Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.</code></p>",
2231 &laughs,
2232 false,
2233 ),
2234 "Build script error",
2235 ),
2236 message(
2237 channel,
2238 "t8r1",
2239 Some("t8"),
2240 (JONAS_ID, "Jonas Ortega"),
2241 at(0, 11, 30),
2242 "<p>Add <code>-UseBasicParsing</code> to the call, that fixes it.</p>",
2243 "[]",
2244 false,
2245 ),
2246 with_attachments(
2247 with_subject(
2248 message(
2249 channel,
2250 "t9",
2251 None,
2252 tobias,
2253 at(0, 12, 10),
2254 "<attachment id=\"announcement-card-demo\"></attachment><p>Please merge your last changes by Thursday 18:00. Anything later goes into release 44.</p>",
2255 "[]",
2256 false,
2257 ),
2258 "Code freeze starts Thursday",
2259 ),
2260 &format!(
2261 r#"[{{"content_type":"{ANNOUNCEMENT_BANNER_TYPE}","id":"announcement-card-demo","name":null,"url":null,"text":null,"content":{}}}]"#,
2262 serde_json::Value::String(
2263 r#"{"title":"Release 43 ships Friday","cardImageType":"colorTheme","cardImageDetails":{"colorTheme":"periwinkleBlue"}}"#.to_owned()
2264 )
2265 ),
2266 ),
2267 ]
2268}
2269
2270fn shared_channel_messages(
2271 channel: &str,
2272 mara: (&str, &str),
2273 tobias: (&str, &str),
2274) -> Vec<MessageRecord> {
2275 let priya = (PRIYA_ID, "Priya Nair");
2276 let jonas = (JONAS_ID, "Jonas Ortega");
2277 let reference = |name: &str, size: u64| {
2278 format!(
2279 r#"{{"content_type":"reference","name":"{name}","url":"https://demo.sharepoint.example/sites/demo/{name}","text":null,"size":{size}}}"#
2280 )
2281 };
2282 vec![
2283 with_attachments(
2284 with_subject(
2285 message(
2286 channel,
2287 "t5",
2288 None,
2289 priya,
2290 at(1, 14, 5),
2291 "<p>Roadmap deck and checklist for Q4 are attached.</p>",
2292 "[]",
2293 false,
2294 ),
2295 "Q4 planning files",
2296 ),
2297 &format!(
2298 "[{},{}]",
2299 reference("Roadmap-Q4.pptx", 3_412_000),
2300 reference("Release-Checklist-Q4.xlsx", 48_213)
2301 ),
2302 ),
2303 message(
2304 channel,
2305 "t5r1",
2306 Some("t5"),
2307 jonas,
2308 at(1, 14, 30),
2309 "<p>Rollback steps are here: <a href=\"https://docs.example.org/runbooks/rollback\">https://docs.example.org/runbooks/rollback</a></p>",
2310 "[]",
2311 false,
2312 ),
2313 with_attachments(
2314 message(
2315 channel,
2316 "t6",
2317 None,
2318 mara,
2319 at(12, 10, 0),
2320 "<p>Postmortem draft for the September outage. Status page: <a href=\"https://status.example.com/incidents/2026-09\">https://status.example.com/incidents/2026-09</a></p>",
2321 "[]",
2322 false,
2323 ),
2324 &format!("[{}]", reference("Postmortem-Draft.docx", 91_400)),
2325 ),
2326 with_attachments(
2327 message(
2328 channel,
2329 "t7",
2330 None,
2331 tobias,
2332 at(20, 9, 0),
2333 "<p>Rollout plan for the new export, please review.</p>",
2334 "[]",
2335 false,
2336 ),
2337 &format!("[{}]", reference("Rollout-Plan.pdf", 2_306_867)),
2338 ),
2339 ]
2340}
2341
2342fn crc32(bytes: &[u8]) -> u32 {
2343 let mut crc = 0xffff_ffffu32;
2344 for byte in bytes {
2345 crc ^= u32::from(*byte);
2346 for _ in 0..8 {
2347 crc = if crc & 1 == 1 {
2348 (crc >> 1) ^ 0xedb8_8320
2349 } else {
2350 crc >> 1
2351 };
2352 }
2353 }
2354 !crc
2355}
2356
2357fn adler32(bytes: &[u8]) -> u32 {
2358 let (mut low, mut high) = (1u32, 0u32);
2359 for byte in bytes {
2360 low = (low + u32::from(*byte)) % 65521;
2361 high = (high + low) % 65521;
2362 }
2363 (high << 16) | low
2364}
2365
2366fn png_chunk(output: &mut Vec<u8>, kind: &[u8; 4], data: &[u8]) {
2367 output.extend_from_slice(&(data.len() as u32).to_be_bytes());
2368 let mut body = kind.to_vec();
2369 body.extend_from_slice(data);
2370 output.extend_from_slice(&body);
2371 output.extend_from_slice(&crc32(&body).to_be_bytes());
2372}
2373
2374fn inside(x: f32, y: f32, center: (f32, f32), radius: (f32, f32)) -> bool {
2375 ((x - center.0) / radius.0).powi(2) + ((y - center.1) / radius.1).powi(2) <= 1.
2376}
2377
2378fn staging_pixel(column: usize, row: usize) -> [u8; 3] {
2379 let (width, height) = (STAGING_SIZE.0 as f32, STAGING_SIZE.1 as f32);
2380 let (x, y) = (column as f32, row as f32);
2381 let shade = y / height;
2382 let background = [
2383 (30. - 14. * shade) as u8,
2384 (41. - 16. * shade) as u8,
2385 (59. - 14. * shade) as u8,
2386 ];
2387 let bar_width = width / 14.;
2388 let slot = (x / bar_width) as usize;
2389 let in_bar = x - slot as f32 * bar_width > bar_width * 0.18;
2390 let bar_height = height * (0.25 + 0.5 * (((slot * 7 + 3) % 11) as f32 / 11.));
2391 let on_bars = in_bar && y > height * 0.86 - bar_height && y < height * 0.86 && slot < 14;
2392 let header = y < height * 0.1;
2393 if header {
2394 [22, 30, 45]
2395 } else if on_bars {
2396 if slot % 4 == 3 {
2397 [226, 87, 47]
2398 } else {
2399 [88, 133, 196]
2400 }
2401 } else if (y - height * 0.86).abs() < 1.5 {
2402 [71, 85, 105]
2403 } else {
2404 background
2405 }
2406}
2407
2408fn encode_png(palette: &Palette) -> Vec<u8> {
2409 let scale = PHOTO_SIZE as f32 / DEMO_PHOTO_SIDE as f32;
2410 encode_rgb(DEMO_PHOTO_SIDE, DEMO_PHOTO_SIDE, |column, row| {
2411 let (x, y) = ((column as f32 + 0.5) * scale, (row as f32 + 0.5) * scale);
2412 if inside(x, y, (24., 21.), (8.5, 9.5)) {
2413 palette.skin
2414 } else if inside(x, y, (24., 19.), (10.5, 11.)) && y < 22. {
2415 palette.hair
2416 } else if inside(x, y, (24., 50.), (22., 19.)) {
2417 palette.shirt
2418 } else {
2419 palette.background
2420 }
2421 })
2422}
2423
2424fn encode_rgb(width: usize, height: usize, pixel: impl Fn(usize, usize) -> [u8; 3]) -> Vec<u8> {
2425 let mut raw = Vec::with_capacity(height * (width * 3 + 1));
2426 for row in 0..height {
2427 raw.push(0);
2428 for column in 0..width {
2429 raw.extend_from_slice(&pixel(column, row));
2430 }
2431 }
2432 let mut zlib = vec![0x78, 0x01];
2433 let mut blocks = raw.chunks(65535).peekable();
2434 while let Some(block) = blocks.next() {
2435 zlib.push(u8::from(blocks.peek().is_none()));
2436 zlib.extend_from_slice(&(block.len() as u16).to_le_bytes());
2437 zlib.extend_from_slice(&(!(block.len() as u16)).to_le_bytes());
2438 zlib.extend_from_slice(block);
2439 }
2440 zlib.extend_from_slice(&adler32(&raw).to_be_bytes());
2441 let mut header = Vec::new();
2442 header.extend_from_slice(&(width as u32).to_be_bytes());
2443 header.extend_from_slice(&(height as u32).to_be_bytes());
2444 header.extend_from_slice(&[8, 2, 0, 0, 0]);
2445 let mut png = vec![0x89, b'P', b'N', b'G', 0x0d, 0x0a, 0x1a, 0x0a];
2446 png_chunk(&mut png, b"IHDR", &header);
2447 png_chunk(&mut png, b"IDAT", &zlib);
2448 png_chunk(&mut png, b"IEND", &[]);
2449 png
2450}
2451
2452pub fn team_members() -> Vec<crate::manage_team::TeamMember> {
2453 std::iter::once((DEMO_USER_ID, DEMO_USER_NAME, DEMO_USER_EMAIL))
2454 .chain(
2455 PEOPLE_DIRECTORY
2456 .iter()
2457 .map(|(user_id, name, _, email)| (*user_id, *name, *email)),
2458 )
2459 .enumerate()
2460 .map(
2461 |(index, (user_id, name, email))| crate::manage_team::TeamMember {
2462 user_id: Some(user_id.to_owned()),
2463 name: name.to_owned(),
2464 email: Some(email.to_owned()),
2465 owner: index == 1 || index == 3,
2466 },
2467 )
2468 .collect()
2469}
2470
2471#[cfg(test)]
2472mod tests {
2473 use super::*;
2474
2475 #[test]
2476 fn the_demo_has_one_important_and_one_urgent_message() {
2477 let store = Store::open_in_memory().unwrap();
2478 seed(&store);
2479 let importance = |chat: &str, message_id: &str| {
2480 store
2481 .messages(chat, None, 50)
2482 .unwrap()
2483 .into_iter()
2484 .find(|record| record.message_id == message_id)
2485 .map(|record| record.importance)
2486 };
2487 assert_eq!(
2488 importance(PRIORITY_CHAT, "p2"),
2489 Some(MessageImportance::High)
2490 );
2491 assert_eq!(
2492 importance(UNREAD_CHAT, "u5"),
2493 Some(MessageImportance::Urgent)
2494 );
2495 }
2496
2497 #[test]
2498 fn a_multi_forward_quotes_each_message_in_order_after_the_comment() {
2499 let store = Store::open_in_memory().unwrap();
2500 seed(&store);
2501 let chat = store
2502 .recent_chats(100)
2503 .unwrap()
2504 .into_iter()
2505 .find(|chat| chat.id == PRIORITY_CHAT)
2506 .unwrap();
2507 let item = |message_id: &str, text: &str| crate::message_actions::ForwardItem {
2508 message_id: message_id.to_owned(),
2509 author: "Synthetic Sender".to_owned(),
2510 time: "09:00".to_owned(),
2511 text: text.to_owned(),
2512 };
2513 let source = ForwardSource {
2514 conversation_id: PRIORITY_CHAT.to_owned(),
2515 messages: vec![item("m1", "first"), item("m2", "second")],
2516 };
2517 let (_, record) = forwarded_message(&chat, &source, "fyi", Utc::now());
2518 let html = &record.body_html;
2519 assert!(html.starts_with("<p>fyi</p>"));
2520 assert_eq!(html.matches(FORWARD_ITEMTYPE).count(), 2);
2521 assert!(html.find("first").unwrap() < html.find("second").unwrap());
2522 }
2523
2524 #[test]
2525 fn png_has_signature_and_ends_with_iend() {
2526 let png = encode_png(&MARA);
2527 assert_eq!(&png[..8], &[0x89, b'P', b'N', b'G', 0x0d, 0x0a, 0x1a, 0x0a]);
2528 assert_eq!(&png[png.len() - 8..png.len() - 4], b"IEND");
2529 }
2530
2531 #[test]
2532 fn crc_and_adler_match_known_values() {
2533 assert_eq!(crc32(b"IEND"), 0xae42_6082);
2534 assert_eq!(adler32(b"Wikipedia"), 0x11e6_0398);
2535 }
2536
2537 #[test]
2538 fn mention_candidates_filter_by_name_and_add_scope_in_channels() {
2539 let chat = mention_candidates("demo-chat-release", "ma");
2540 assert_eq!(chat.len(), 1);
2541 assert_eq!(chat[0].display_name(), "Mara Lindqvist");
2542 let channel = mention_candidates("demo-channel-1-1", "gen");
2543 assert!(matches!(channel[0], MentionCandidate::Channel { .. }));
2544 let all = mention_candidates("demo-chat-release", "");
2545 assert_eq!(all.len(), 6);
2546 assert!(matches!(all[0], MentionCandidate::Everyone { .. }));
2547 assert!(
2548 mention_candidates("demo-chat-mara", "")
2549 .iter()
2550 .all(|candidate| !matches!(candidate, MentionCandidate::Everyone { .. }))
2551 );
2552 assert!(matches!(
2553 mention_candidates("demo-channel-1-1", "desi")[0],
2554 MentionCandidate::Tag { .. }
2555 ));
2556 }
2557
2558 #[test]
2559 fn new_group_chat_gets_a_title_and_the_first_message() {
2560 let people = vec![
2561 (MARA_ID.to_owned(), "Mara Lindqvist".to_owned()),
2562 (JONAS_ID.to_owned(), "Jonas Ortega".to_owned()),
2563 ];
2564 let now = Utc::now();
2565 let (chat, record) = new_chat(
2566 &[],
2567 &people,
2568 Some("Crew"),
2569 "Hello all",
2570 "Hello <i>all</i>",
2571 now,
2572 );
2573 assert_eq!(chat.id, "demo-chat-new-1");
2574 assert_eq!(chat.kind, "group");
2575 assert_eq!(chat.title, "Crew");
2576 assert_eq!(chat.member_summary, "Mara Lindqvist, Jonas Ortega");
2577 assert_eq!(chat.members.len(), 3);
2578 assert_eq!(chat.members[0].user_id.as_deref(), Some(DEMO_USER_ID));
2579 assert_eq!(chat.last_message_preview.as_deref(), Some("Hello all"));
2580 assert_eq!(chat.last_message_at, Some(now));
2581 assert_eq!(record.conversation_id, chat.id);
2582 assert_eq!(record.sender_id.as_deref(), Some(DEMO_USER_ID));
2583 assert!(record.body_html.contains("Hello"));
2584 }
2585
2586 #[test]
2587 fn new_one_on_one_chat_has_no_title_and_counts_up() {
2588 let people = vec![(LEA_ID.to_owned(), "Lea Schneider".to_owned())];
2589 let (first, _) = new_chat(&[], &people, None, "Hi", "Hi", Utc::now());
2590 assert_eq!(first.kind, "oneOnOne");
2591 assert!(first.title.is_empty());
2592 let (second, _) = new_chat(&[first], &people, None, "Hi again", "Hi again", Utc::now());
2593 assert_eq!(second.id, "demo-chat-new-2");
2594 }
2595
2596 #[test]
2597 fn sending_into_a_chat_refreshes_its_preview() {
2598 let base = ChatRecord {
2599 id: "demo-chat-x".to_owned(),
2600 unread: true,
2601 ..Default::default()
2602 };
2603 let (chat, record) = send_in_chat(&base, "Ping", "Ping", Utc::now());
2604 assert!(!chat.unread);
2605 assert_eq!(chat.last_message_preview.as_deref(), Some("Ping"));
2606 assert_eq!(record.conversation_id, "demo-chat-x");
2607 }
2608
2609 #[test]
2610 fn demo_covers_the_sidebar_edge_cases() {
2611 let chats = demo_chats();
2612 assert!(chats.iter().any(|chat| chat.deleted));
2613 assert!(chats.iter().any(|chat| chat.title.len() > 40));
2614 assert!(chats.iter().filter(|chat| chat.unread).count() >= 3);
2615 }
2616}