BlueGit

ict rusty-teams

Files

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

demo.rs

demo.rs 81.3 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 Activity, CallEvent, CallPhase, CallType, CardActionOutcome, ChatApp, Gif, Language,
15 LanguageSettings, LinkPreview, MentionCandidate, NOTES_CHAT_ID, PersonCandidate, PersonSource,
16 PinnedMessage, SavedMessage, TaskDialog, TaskDialogKind, Translation, TranslationBehavior,
17 TranslationStatus,
18};
19
20use crate::activity::{Actor, Entry, Kind};
21use crate::app_state::{AppState, Selection};
22use crate::card_actions::{CardAnswer, CardTask};
23use crate::data::{AvatarState, FolderInfo, FolderKind, Person, PresenceKind};
24use crate::demo_gifs;
25use crate::message_actions::ForwardSource;
26
27static SEARCHABLE_GIFS: OnceLock<Vec<Gif>> = OnceLock::new();
28
29pub const DEMO_USER_ID: &str = "demo-me";
30const DEMO_USER_NAME: &str = "Dana Demo";
31const DEMO_USER_EMAIL: &str = "dana.demo@example.com";
32const DEMO_TIME_ZONE: &str = "W. Europe Standard Time";
33const PHOTO_SIZE: usize = 48;
34const DEMO_PHOTO_SIDE: usize = 240;
35const STAGING_IMAGE_KEY: &str = "demo://staging-dashboard";
36const PENDING_IMAGE_KEY: &str = "demo://pending-screenshot";
37const STAGING_SIZE: (usize, usize) = (960, 540);
38const LINK_IMAGE_KEY: &str =
39 "https://de-prod.asyncgw.teams.microsoft.com/urlp/v1/url/image/Thumbnail?url=demo";
40const LINK_IMAGE_SIZE: (u32, u32) = (320, 180);
41const PRIORITY_CHAT: &str = "demo-chat-priya";
42const BOT_CHAT: &str = "demo-chat-wiki-bot";
43const BOT_NAME: &str = "Wiki Bot";
44const ECHO_CHAT: &str = "demo-chat-echo";
45const ECHO_BOT_ID: &str = "28:demo-echo";
46const BOT_APP_NAME: &str = "Wiki Cloud";
47const BOT_ID: &str = "00000000-0000-0000-0000-00000000b07a";
48const CARD_ANSWER_DELAY: std::time::Duration = std::time::Duration::from_millis(700);
49const CARD_PERSON_URL: &str = "https://avatars.githubusercontent.com/u/9919?s=64";
50const CARD_PAGE_URL: &str = "https://avatars.githubusercontent.com/u/9919?s=64";
51const NEW_CHAT_PREFIX: &str = "demo-chat-new-";
52const PEOPLE_DIRECTORY: [(&str, &str, &str, &str); 5] = [
53 (
54 MARA_ID,
55 "Mara Lindqvist",
56 "Product Owner",
57 "mara.lindqvist@example.com",
58 ),
59 (
60 JONAS_ID,
61 "Jonas Ortega",
62 "Backend Engineer",
63 "jonas.ortega@example.com",
64 ),
65 (
66 PRIYA_ID,
67 "Priya Nair",
68 "Engineering Manager",
69 "priya.nair@example.com",
70 ),
71 (
72 LEA_ID,
73 "Lea Schneider",
74 "Customer Success",
75 "lea.schneider@example.com",
76 ),
77 (
78 TOBIAS_ID,
79 "Tobias Klein",
80 "Support Engineer",
81 "tobias.klein@example.com",
82 ),
83];
84
85struct Palette {
86 background: [u8; 3],
87 skin: [u8; 3],
88 hair: [u8; 3],
89 shirt: [u8; 3],
90}
91
92const MARA: Palette = Palette {
93 background: [0x3f, 0x5f, 0x7a],
94 skin: [0xe0, 0xb2, 0x93],
95 hair: [0xd9, 0xa4, 0x41],
96 shirt: [0x1e, 0x29, 0x3b],
97};
98const PRIYA: Palette = Palette {
99 background: [0x4b, 0x3b, 0x5c],
100 skin: [0x9a, 0x6a, 0x4a],
101 hair: [0x1c, 0x19, 0x17],
102 shirt: [0xbe, 0x12, 0x3c],
103};
104const TOBIAS: Palette = Palette {
105 background: [0x3b, 0x4a, 0x3f],
106 skin: [0xf1, 0xc7, 0xa5],
107 hair: [0x57, 0x53, 0x4e],
108 shirt: [0x0f, 0x76, 0x6e],
109};
110
111pub const MARA_ID: &str = "demo-mara";
112pub const JONAS_ID: &str = "demo-jonas";
113pub const PRIYA_ID: &str = "demo-priya";
114pub const LEA_ID: &str = "demo-lea";
115pub const TOBIAS_ID: &str = "demo-tobias";
116
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 scope: Vec<MentionCandidate> = if conversation_id.starts_with("demo-channel") {
497 [
498 MentionCandidate::Channel {
499 channel_id: conversation_id.to_owned(),
500 name: "General".to_owned(),
501 },
502 MentionCandidate::Team {
503 team_id: "demo-team-1".to_owned(),
504 name: "Platform".to_owned(),
505 },
506 ]
507 .into_iter()
508 .filter(|candidate| matches(candidate.display_name()))
509 .collect()
510 } else {
511 Vec::new()
512 };
513 people.chain(scope).collect()
514}
515
516pub fn send_in_chat(
517 chat: &ChatRecord,
518 preview: &str,
519 html: &str,
520 now: DateTime<Utc>,
521) -> (ChatRecord, MessageRecord) {
522 let mut chat = chat.clone();
523 chat.last_message_at = Some(now);
524 chat.last_message_preview = Some(preview.to_owned());
525 chat.last_message_sender_id = Some(DEMO_USER_ID.to_owned());
526 chat.last_message_sender_name = Some(DEMO_USER_NAME.to_owned());
527 chat.last_message_deleted = false;
528 chat.unread = false;
529 let record = message(
530 &chat.id,
531 &format!("demo-sent-{}", now.timestamp_millis()),
532 None,
533 (DEMO_USER_ID, DEMO_USER_NAME),
534 now,
535 html,
536 "[]",
537 false,
538 );
539 (chat, record)
540}
541
542pub fn new_chat(
543 existing: &[ChatRecord],
544 people: &[(String, String)],
545 topic: Option<&str>,
546 preview: &str,
547 html: &str,
548 now: DateTime<Utc>,
549) -> (ChatRecord, MessageRecord) {
550 let number = existing
551 .iter()
552 .filter(|chat| chat.id.starts_with(NEW_CHAT_PREFIX))
553 .count()
554 + 1;
555 let one_on_one = people.len() == 1;
556 let members = std::iter::once(member(DEMO_USER_ID, DEMO_USER_NAME))
557 .chain(people.iter().map(|(user_id, name)| member(user_id, name)))
558 .collect();
559 let chat = ChatRecord {
560 id: format!("{NEW_CHAT_PREFIX}{number}"),
561 kind: if one_on_one { "oneOnOne" } else { "group" }.to_owned(),
562 title: if one_on_one {
563 String::new()
564 } else {
565 topic.unwrap_or_default().to_owned()
566 },
567 member_summary: people
568 .iter()
569 .map(|(_, name)| name.as_str())
570 .collect::<Vec<_>>()
571 .join(", "),
572 members,
573 ..Default::default()
574 };
575 send_in_chat(&chat, preview, html, now)
576}
577
578fn image_directory() -> PathBuf {
579 std::env::temp_dir().join("rusty-teams-demo")
580}
581
582pub fn search_gifs(query: &str) -> Vec<Gif> {
583 let query = query.trim().to_lowercase();
584 SEARCHABLE_GIFS
585 .get()
586 .into_iter()
587 .flatten()
588 .filter(|gif| gif.title.to_lowercase().contains(&query))
589 .cloned()
590 .collect()
591}
592
593pub fn language_settings() -> LanguageSettings {
594 LanguageSettings {
595 display_locale: Some("en-US".to_owned()),
596 target_locale: Some("en".to_owned()),
597 behavior: TranslationBehavior::Ask,
598 authoring_locales: vec!["de-DE".to_owned(), "en-US".to_owned()],
599 preferences: serde_json::Map::new(),
600 }
601}
602
603pub fn language_list() -> Vec<Language> {
604 [
605 ("de", "German"),
606 ("en", "English"),
607 ("es", "Spanish"),
608 ("fr", "French"),
609 ("it", "Italian"),
610 ("ja", "Japanese"),
611 ("nl", "Dutch"),
612 ("pt", "Portuguese"),
613 ]
614 .into_iter()
615 .map(|(code, name)| Language {
616 code: code.to_owned(),
617 name: name.to_owned(),
618 })
619 .collect()
620}
621
622pub fn language_stamps(conversation_id: &str) -> HashMap<String, String> {
623 if conversation_id != RELEASE_CHAT {
624 return HashMap::new();
625 }
626 HashMap::from([
627 (
628 FRENCH_MESSAGE.to_owned(),
629 "languages=fr:100;en:12;length:104;&detector=Bling".to_owned(),
630 ),
631 (
632 SPANISH_MESSAGE.to_owned(),
633 "languages=es:100;pt:31;length:94;&detector=Bling".to_owned(),
634 ),
635 ])
636}
637
638pub fn translations(message_ids: &[String]) -> Vec<Translation> {
639 let translated = |message_id: &str| match message_id {
640 FRENCH_MESSAGE => Some(
641 "<p>Hello everyone, <strong>version 0.2</strong> is ready. Can you check the checklist before Friday?</p>",
642 ),
643 SPANISH_MESSAGE => Some(
644 "<p>Thanks for the heads-up. I will test the build this afternoon and let you know if anything breaks.</p>",
645 ),
646 _ => None,
647 };
648 message_ids
649 .iter()
650 .map(|message_id| Translation {
651 message_id: message_id.clone(),
652 version: None,
653 status: if translated(message_id).is_some() {
654 TranslationStatus::Done
655 } else {
656 TranslationStatus::Failed
657 },
658 content_html: translated(message_id).map(str::to_owned),
659 subject: None,
660 title: None,
661 })
662 .collect()
663}
664
665pub fn first_unread(conversation_id: &str) -> Option<String> {
666 (conversation_id == UNREAD_CHAT).then(|| "u3".to_owned())
667}
668
669pub fn read_message_ids(records: &[MessageRecord]) -> std::collections::HashSet<String> {
670 let newest = records.iter().max_by_key(|record| record.created_at);
671 records
672 .iter()
673 .filter(|record| {
674 Some(record.message_id.as_str()) != newest.map(|newest| newest.message_id.as_str())
675 })
676 .map(|record| record.message_id.clone())
677 .collect()
678}
679
680pub fn start_session(state: &Entity<AppState>, cx: &mut App) {
681 state.update(cx, |state, cx| {
682 seed_directory(state);
683 state.demo_live_meetings();
684 state.select(first_selection(), cx);
685 });
686}
687
688pub fn first_selection() -> Selection {
689 Selection::Chat(RELEASE_CHAT.to_owned())
690}
691
692pub fn activity_entries() -> Vec<Entry> {
693 let actor = |user_id: &str, name: &str| Actor {
694 user_id: Some(user_id.to_owned()),
695 name: name.to_owned(),
696 };
697 let entry = |conversation_id: &str,
698 kind: Kind,
699 message_id: &str,
700 actors: Vec<Actor>,
701 preview: &str,
702 count: u32,
703 updated_at: DateTime<Utc>,
704 read: bool| Entry {
705 id: 0,
706 conversation_id: conversation_id.to_owned(),
707 kind,
708 message_id: message_id.to_owned(),
709 actors,
710 preview: preview.to_owned(),
711 glyphs: Vec::new(),
712 count,
713 updated_at,
714 read,
715 };
716 let reaction = Entry {
717 glyphs: vec!["\u{1F602}".to_owned(), "\u{1F44D}".to_owned()],
718 ..entry(
719 RELEASE_CHAT,
720 Kind::Reaction,
721 "m3",
722 vec![
723 actor(PRIYA_ID, "Priya Nair"),
724 actor(LEA_ID, "Lea Schneider"),
725 ],
726 "I'll take the changelog.",
727 2,
728 at(0, 13, 20),
729 false,
730 )
731 };
732 vec![
733 entry(
734 UNREAD_CHAT,
735 Kind::Messages,
736 "u3",
737 vec![
738 actor(LEA_ID, "Lea Schneider"),
739 actor(PRIYA_ID, "Priya Nair"),
740 ],
741 "Who is taking the review?",
742 3,
743 at(0, 13, 12),
744 false,
745 ),
746 entry(
747 "demo-channel-1-1",
748 Kind::Mention,
749 "t1",
750 vec![actor(MARA_ID, "Mara Lindqvist")],
751 "@Dana can you approve the merge? The pipeline is waiting.",
752 1,
753 at(0, 11, 40),
754 false,
755 ),
756 reaction,
757 entry(
758 "demo-chat-allhands",
759 Kind::Mention,
760 "demo-allhands-policy",
761 vec![actor(LEA_ID, "Lea Schneider")],
762 "@Dana please read the new vacation policy before Friday.",
763 1,
764 at(0, 9, 0),
765 false,
766 ),
767 entry(
768 "demo-chat-customer-3",
769 Kind::Messages,
770 "demo-customer-3-closed",
771 vec![actor(TOBIAS_ID, "Tobias Klein")],
772 "Ticket is closed",
773 1,
774 at(1, 16, 0),
775 true,
776 ),
777 ]
778}
779
780pub fn seed(store: &Store) {
781 let chats: Vec<ChatRecord> = demo_chats()
782 .into_iter()
783 .map(|demo| ChatRecord {
784 id: demo.id.to_owned(),
785 kind: demo.kind.to_owned(),
786 title: if demo.kind == "oneOnOne" {
787 String::new()
788 } else {
789 demo.title.to_owned()
790 },
791 member_summary: demo.title.to_owned(),
792 last_message_at: Some(demo.time),
793 unread: demo.unread,
794 members: demo.members,
795 last_message_preview: demo.preview.map(|(_, _, text)| text.to_owned()),
796 last_message_sender_id: demo.preview.map(|(id, _, _)| id.to_owned()),
797 last_message_sender_name: demo.preview.map(|(_, name, _)| name.to_owned()),
798 last_message_deleted: demo.deleted,
799 ..Default::default()
800 })
801 .collect();
802 let _ = store.upsert_chats(&chats);
803 for chat_id in MUTED_CHATS {
804 let _ = store.set_chat_muted(chat_id, true);
805 }
806 let teams: Vec<TeamRecord> = DEMO_TEAMS
807 .iter()
808 .map(|(id, name, _)| TeamRecord {
809 id: (*id).to_owned(),
810 name: (*name).to_owned(),
811 })
812 .collect();
813 let _ = store.upsert_teams(&teams);
814 let mut channels = Vec::new();
815 for (team_index, (team_id, _, names)) in DEMO_TEAMS.iter().enumerate() {
816 for (channel_index, name) in names.iter().enumerate() {
817 channels.push(ChannelRecord {
818 id: format!("demo-channel-{}-{}", team_index + 1, channel_index + 1),
819 team_id: (*team_id).to_owned(),
820 name: (*name).to_owned(),
821 membership_type: None,
822 last_message_at: Some(at(channel_index as i64, 12, 10)),
823 unread: (team_index == 0 && channel_index == 1)
824 || (team_index == 1 && channel_index == 0),
825 });
826 }
827 }
828 for channel in channels.iter_mut().filter(|channel| {
829 DEMO_CHANNEL_MENTIONS
830 .iter()
831 .any(|(id, _)| *id == channel.id)
832 }) {
833 channel.unread = true;
834 }
835 let _ = store.upsert_channels(&channels);
836 let _ = store.replace_team_layout(&demo_team_layout(&channels));
837 let _ = store.replace_channel_mentions(
838 &DEMO_CHANNEL_MENTIONS
839 .iter()
840 .map(|(id, mentions)| ((*id).to_owned(), *mentions))
841 .collect::<Vec<_>>(),
842 );
843 let _ = store.set_meta("me_user_id", DEMO_USER_ID);
844 let _ = store.set_meta("me_display_name", DEMO_USER_NAME);
845 let _ = store.upsert_messages(&release_messages());
846 let _ = store.upsert_messages(&unread_messages());
847 let _ = store.upsert_messages(&channel_messages());
848 let _ = store.upsert_messages(&priority_messages());
849 let _ = store.upsert_messages(&notes_messages());
850 let _ = store.upsert_messages(&meeting_link_messages());
851 let _ = store.upsert_messages(&standup_messages());
852 let _ = store.upsert_messages(&call_messages());
853 let _ = store.upsert_messages(&crate::demo_meetings::meeting_messages());
854 let _ = store.upsert_messages(&bot_messages());
855 seed_agent_access(store);
856}
857
858const AGENT_DEMO_PROPOSAL: &str = "I ran the regression suite on staging: 412 passed, 0 failed. The release candidate is good to ship, @Mara Lindqvist.";
859
860fn seed_agent_access(store: &Store) {
861 let selected =
862 |ids: &[&str]| mcp::Access::Selected(ids.iter().map(|id| (*id).to_owned()).collect());
863 mcp::save_policy(
864 store,
865 &mcp::AgentPolicy {
866 enabled: true,
867 chats: selected(&[RELEASE_CHAT, "demo-chat-mara", "demo-chat-meeting-standup"]),
868 channels: selected(&["demo-channel-1-1"]),
869 propose: true,
870 calendar: true,
871 transcripts: false,
872 ..mcp::AgentPolicy::default()
873 },
874 );
875 let _ = store.insert_agent_proposal(&store::AgentProposalRecord {
876 id: "demo-proposal".to_owned(),
877 conversation_id: RELEASE_CHAT.to_owned(),
878 reply_to_message_id: Some("m1".to_owned()),
879 text: AGENT_DEMO_PROPOSAL.to_owned(),
880 mentions: vec![store::AgentProposalMention {
881 user_id: MARA_ID.to_owned(),
882 name: "Mara Lindqvist".to_owned(),
883 }],
884 images: vec![store::AttachmentImage {
885 name: "image-1.png".to_owned(),
886 format: "image/png".to_owned(),
887 bytes: encode_png(&MARA),
888 width: Some(PHOTO_SIZE as u32),
889 height: Some(PHOTO_SIZE as u32),
890 }],
891 agent: Some("claude".to_owned()),
892 session_id: None,
893 created_at: Utc::now() - Duration::minutes(1),
894 state: "pending".to_owned(),
895 resolved_at: None,
896 });
897 let _ = store.insert_agent_reaction(&store::AgentReactionRecord {
898 id: "demo-reaction".to_owned(),
899 conversation_id: "demo-chat-mara".to_owned(),
900 message_id: "ml1".to_owned(),
901 emoji: "\u{1F44D}".to_owned(),
902 agent: Some("claude".to_owned()),
903 session_id: None,
904 created_at: Utc::now() - Duration::minutes(1),
905 state: "pending".to_owned(),
906 resolved_at: None,
907 });
908}
909
910fn photo(palette: &Palette) -> AvatarState {
911 crate::data::avatar_state_from("image/png", encode_png(palette), false)
912}
913
914pub fn seed_directory(state: &mut AppState) {
915 state.own_status = crate::own_status::demo_status();
916 state.own_email = DEMO_USER_EMAIL.to_owned();
917 state.own_time_zone = Some(DEMO_TIME_ZONE.to_owned());
918 state.translation.settings = Some(language_settings());
919 state.apply_date_locale();
920 state.translation.languages = language_list();
921 let directory = &mut state.directory;
922 directory.me = Some(Person {
923 user_id: DEMO_USER_ID.to_owned(),
924 display_name: DEMO_USER_NAME.to_owned(),
925 });
926 let ids = |list: &[&str]| list.iter().map(|id| (*id).to_owned()).collect::<Vec<_>>();
927 directory.folders = vec![
928 FolderInfo {
929 id: FAVORITES_ID.to_owned(),
930 name: String::new(),
931 kind: FolderKind::Favorites,
932 expanded: None,
933 conversation_ids: ids(&["demo-chat-mara", RELEASE_CHAT]),
934 },
935 FolderInfo {
936 id: CUSTOMERS_FOLDER.to_owned(),
937 name: "Customers".to_owned(),
938 kind: FolderKind::UserCreated,
939 expanded: None,
940 conversation_ids: ids(&[
941 "demo-chat-customer-1",
942 "demo-chat-customer-2",
943 "demo-chat-customer-3",
944 "demo-chat-customer-4",
945 ]),
946 },
947 FolderInfo {
948 id: ATLAS_FOLDER.to_owned(),
949 name: "Project Atlas".to_owned(),
950 kind: FolderKind::UserCreated,
951 expanded: None,
952 conversation_ids: ids(&["demo-chat-atlas", "demo-chat-jonas"]),
953 },
954 FolderInfo {
955 id: TODO_FOLDER.to_owned(),
956 name: "To do".to_owned(),
957 kind: FolderKind::UserCreated,
958 expanded: None,
959 conversation_ids: Vec::new(),
960 },
961 ];
962 state.bot_apps.insert(BOT_CHAT.to_owned(), vec![bot_app()]);
963 let directory = &mut state.directory;
964 directory.pinned_channels = ids(&["demo-channel-1-1", "demo-channel-3-2"]);
965 directory
966 .unread_counts
967 .insert("demo-chat-atlas".to_owned(), 5);
968 directory
969 .unread_counts
970 .insert("demo-chat-customer-1".to_owned(), 2);
971 directory
972 .unread_counts
973 .insert("demo-chat-customer-2".to_owned(), 1);
974 directory
975 .unread_counts
976 .insert("demo-chat-allhands".to_owned(), 120);
977 directory
978 .unread_importance
979 .insert(UNREAD_CHAT.to_owned(), MessageImportance::Urgent);
980 directory
981 .unread_importance
982 .insert("demo-chat-customer-1".to_owned(), MessageImportance::High);
983 directory.set_avatar(MARA_ID, photo(&MARA));
984 directory.set_avatar(PRIYA_ID, photo(&PRIYA));
985 directory.set_avatar(TOBIAS_ID, photo(&TOBIAS));
986 for (user_id, kind) in [
987 (MARA_ID, PresenceKind::Available),
988 (JONAS_ID, PresenceKind::Busy),
989 (PRIYA_ID, PresenceKind::Away),
990 (TOBIAS_ID, PresenceKind::Offline),
991 (LEA_ID, PresenceKind::Busy),
992 (DEMO_USER_ID, PresenceKind::Available),
993 ] {
994 directory.set_presence(user_id, kind);
995 }
996 directory.set_activity(JONAS_ID, Some(Activity::InACall));
997 directory.set_activity(LEA_ID, Some(Activity::InAConferenceCall));
998 let directory_path = image_directory();
999 if std::fs::create_dir_all(&directory_path).is_ok() {
1000 let path = directory_path.join("staging-dashboard.png");
1001 let png = encode_rgb(STAGING_SIZE.0, STAGING_SIZE.1, staging_pixel);
1002 if std::fs::write(&path, png).is_ok() {
1003 state.directory.set_image(STAGING_IMAGE_KEY, &path);
1004 state.directory.set_image(LINK_IMAGE_KEY, &path);
1005 }
1006 let _ = SEARCHABLE_GIFS.set(demo_gifs::generate(&directory_path));
1007 state.directory.set_image(
1008 demo_gifs::RECEIVED_GIF_KEY,
1009 &directory_path.join(demo_gifs::file_name(demo_gifs::RECEIVED_GIF_NAME)),
1010 );
1011 }
1012 state.typing.start(
1013 "demo-chat-mara",
1014 MARA_ID,
1015 "Mara Lindqvist",
1016 Instant::now(),
1017 Utc::now(),
1018 );
1019 state.collapsed.insert(CUSTOMERS_FOLDER.to_owned());
1020 state.last_sync = Some(Utc::now());
1021 state.apply_bot_titles();
1022 seed_message_actions(state);
1023}
1024
1025fn seed_message_actions(state: &mut AppState) {
1026 state.pins.insert(
1027 PINNED_CHANNEL.to_owned(),
1028 vec![PinnedMessage {
1029 message_id: PINNED_POST.to_owned(),
1030 pinned_at: Some(at(0, 9, 45)),
1031 parent_id: None,
1032 }],
1033 );
1034 state.pins.insert(
1035 RELEASE_CHAT.to_owned(),
1036 vec![PinnedMessage {
1037 message_id: PINNED_MESSAGE.to_owned(),
1038 pinned_at: Some(at(0, 11, 30)),
1039 parent_id: None,
1040 }],
1041 );
1042 let ids: Vec<String> = SAVED_MESSAGES.iter().map(|id| (*id).to_owned()).collect();
1043 let records = state
1044 .store
1045 .messages_by_id(RELEASE_CHAT, &ids)
1046 .unwrap_or_default();
1047 let saved = SAVED_MESSAGES
1048 .iter()
1049 .enumerate()
1050 .filter_map(|(position, id)| {
1051 let record = records.get(*id)?;
1052 Some(SavedMessage {
1053 conversation_id: record.conversation_id.clone(),
1054 message_id: record.message_id.clone(),
1055 root_id: record.message_id.clone(),
1056 author_id: record.sender_id.clone(),
1057 author_name: record.sender_name.clone(),
1058 preview: crate::rows::reply_excerpt(record),
1059 saved_at: at(position as i64, 15, 20),
1060 topic: None,
1061 })
1062 })
1063 .collect();
1064 state.saved.replace(saved);
1065}
1066
1067pub fn forwarded_message(
1068 chat: &ChatRecord,
1069 source: &ForwardSource,
1070 comment: &str,
1071 now: DateTime<Utc>,
1072) -> (ChatRecord, MessageRecord) {
1073 let comment_html = if comment.is_empty() {
1074 String::new()
1075 } else {
1076 format!("<p>{}</p>", teams_core::escape_html(comment))
1077 };
1078 let html = format!(
1079 "{comment_html}<blockquote itemscope=\"\" itemtype=\"{FORWARD_ITEMTYPE}\" itemid=\"{}\"><strong>{}</strong><p>{}</p></blockquote>",
1080 teams_core::escape_html(&source.message_id),
1081 teams_core::escape_html(&source.author),
1082 teams_core::escape_html(&source.text),
1083 );
1084 send_in_chat(chat, &source.text, &html, now)
1085}
1086
1087#[allow(clippy::too_many_arguments)]
1088fn message(
1089 conversation: &str,
1090 id: &str,
1091 reply_to: Option<&str>,
1092 sender: (&str, &str),
1093 time: DateTime<Utc>,
1094 html: &str,
1095 reactions_json: &str,
1096 edited: bool,
1097) -> MessageRecord {
1098 MessageRecord {
1099 conversation_id: conversation.to_owned(),
1100 message_id: id.to_owned(),
1101 reply_to_id: reply_to.map(str::to_owned),
1102 sender_id: Some(sender.0.to_owned()),
1103 sender_name: Some(sender.1.to_owned()),
1104 sender_application_id: None,
1105 links_json: "[]".to_owned(),
1106 created_at: time,
1107 edited_at: edited.then_some(time + Duration::minutes(2)),
1108 deleted: false,
1109 body_html: html.to_owned(),
1110 attachments_json: "[]".to_owned(),
1111 reactions_json: reactions_json.to_owned(),
1112 mentions_json: "[]".to_owned(),
1113 subject: None,
1114 call_event_json: None,
1115 importance: Default::default(),
1116 }
1117}
1118
1119pub fn roster_record(
1120 conversation: &str,
1121 id: &str,
1122 time: DateTime<Utc>,
1123 event: &teams_core::roster_event::RosterEvent,
1124) -> MessageRecord {
1125 MessageRecord {
1126 conversation_id: conversation.to_owned(),
1127 message_id: id.to_owned(),
1128 created_at: time,
1129 links_json: "[]".to_owned(),
1130 attachments_json: "[]".to_owned(),
1131 reactions_json: "[]".to_owned(),
1132 mentions_json: "[]".to_owned(),
1133 call_event_json: Some(event.to_json()),
1134 ..MessageRecord::default()
1135 }
1136}
1137
1138fn call_record(
1139 conversation: &str,
1140 id: &str,
1141 time: DateTime<Utc>,
1142 event: CallEvent,
1143) -> MessageRecord {
1144 MessageRecord {
1145 conversation_id: conversation.to_owned(),
1146 message_id: id.to_owned(),
1147 created_at: time,
1148 links_json: "[]".to_owned(),
1149 attachments_json: "[]".to_owned(),
1150 reactions_json: "[]".to_owned(),
1151 mentions_json: "[]".to_owned(),
1152 call_event_json: Some(event.to_json()),
1153 ..MessageRecord::default()
1154 }
1155}
1156
1157fn call_event(
1158 phase: CallPhase,
1159 call_id: &str,
1160 initiator: (&str, &str),
1161 duration_seconds: Option<u64>,
1162 participant_ids: &[&str],
1163) -> CallEvent {
1164 CallEvent {
1165 phase,
1166 call_type: CallType::Call,
1167 call_id: call_id.to_owned(),
1168 duration_seconds,
1169 initiator_id: Some(initiator.0.to_owned()),
1170 initiator_name: Some(initiator.1.to_owned()),
1171 participant_ids: participant_ids.iter().map(|id| (*id).to_owned()).collect(),
1172 participant_names: Vec::new(),
1173 recording: None,
1174 }
1175}
1176
1177fn call_messages() -> Vec<MessageRecord> {
1178 let mara = (MARA_ID, "Mara Lindqvist");
1179 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1180 let jonas = (JONAS_ID, "Jonas Ortega");
1181 let both = [DEMO_USER_ID, MARA_ID];
1182 vec![
1183 call_record(
1184 "demo-chat-mara",
1185 "call-1-started",
1186 at(0, 12, 4),
1187 call_event(CallPhase::Started, "demo-call-1", me, None, &[]),
1188 ),
1189 call_record(
1190 "demo-chat-mara",
1191 "call-1-ended",
1192 at(0, 12, 16),
1193 call_event(CallPhase::Ended, "demo-call-1", me, Some(723), &both),
1194 ),
1195 call_record(
1196 "demo-chat-mara",
1197 "call-2-started",
1198 at(0, 13, 9),
1199 call_event(CallPhase::Started, "demo-call-2", mara, None, &[]),
1200 ),
1201 call_record(
1202 "demo-chat-mara",
1203 "call-2-ended",
1204 at(0, 13, 10),
1205 call_event(CallPhase::Ended, "demo-call-2", mara, Some(60), &[MARA_ID]),
1206 ),
1207 call_record(
1208 "demo-chat-meeting-standup",
1209 "call-3-started",
1210 at(0, 9, 50),
1211 CallEvent {
1212 call_type: CallType::Meeting,
1213 ..call_event(CallPhase::Started, "demo-call-3", jonas, None, &[])
1214 },
1215 ),
1216 ]
1217}
1218
1219fn with_importance(mut record: MessageRecord, importance: MessageImportance) -> MessageRecord {
1220 record.importance = importance;
1221 record
1222}
1223
1224fn with_subject(mut record: MessageRecord, subject: &str) -> MessageRecord {
1225 record.subject = Some(subject.to_owned());
1226 record
1227}
1228
1229fn with_attachments(mut record: MessageRecord, attachments_json: &str) -> MessageRecord {
1230 record.attachments_json = attachments_json.to_owned();
1231 record
1232}
1233
1234fn with_links(mut record: MessageRecord, links_json: String) -> MessageRecord {
1235 record.links_json = links_json;
1236 record
1237}
1238
1239pub fn link_preview(url: &str) -> Option<LinkPreview> {
1240 Some(LinkPreview {
1241 url: url.to_owned(),
1242 title: Some("Release checklist Q4".to_owned()),
1243 description: Some(
1244 "Everything that has to be green before the release candidate goes out on Friday."
1245 .to_owned(),
1246 ),
1247 image_url: Some(LINK_IMAGE_KEY.to_owned()),
1248 image_width: Some(LINK_IMAGE_SIZE.0),
1249 image_height: Some(LINK_IMAGE_SIZE.1),
1250 })
1251}
1252
1253fn bot_messages() -> Vec<MessageRecord> {
1254 let card = serde_json::json!({
1255 "type": "AdaptiveCard",
1256 "body": [
1257 {"type": "ColumnSet", "columns": [
1258 {"type": "Column", "width": "auto", "verticalContentAlignment": "center", "items": [
1259 {"type": "Image", "url": CARD_PERSON_URL, "size": "small", "style": "person", "height": "32px"}
1260 ]},
1261 {"type": "Column", "width": "stretch", "verticalContentAlignment": "center", "items": [
1262 {"type": "TextBlock", "size": "medium", "weight": "bolder", "wrap": true, "text": "Mara Lindqvist edited your page"}
1263 ]}
1264 ]},
1265 {"type": "ColumnSet", "separator": true, "columns": [
1266 {"type": "Column", "width": "auto", "items": [
1267 {"type": "Image", "url": CARD_PAGE_URL, "width": "24px", "height": "24px"}
1268 ]},
1269 {"type": "Column", "width": "stretch", "items": [
1270 {"type": "TextBlock", "weight": "bolder", "wrap": true, "text": "[**Release Checklist Q4**](https://example.com/wiki/release-checklist) in [**Platform**](https://example.com/wiki/platform)"},
1271 {"type": "TextBlock", "spacing": "small", "isSubtle": true, "wrap": true, "text": "Owned by: Dana Demo"}
1272 ]}
1273 ]},
1274 {"type": "TextBlock", "id": "owner-note", "isVisible": false, "isSubtle": true, "wrap": true, "text": "Owner notes are only shown on request."},
1275 {"type": "ActionSet", "actions": [
1276 {"type": "Action.OpenUrl", "title": "View page", "url": "https://example.com/wiki/release-checklist"},
1277 {"type": "Action.OpenUrl", "title": "View changes", "url": "https://example.com/wiki/release-checklist/changes"},
1278 {"type": "Action.Submit", "title": "Watch page", "data": {"action": "watch"}},
1279 {"type": "Action.Submit", "title": "Stop watching", "data": {"action": "unwatch"}},
1280 {"type": "Action.Submit", "title": "Settings", "data": {"msteams": {"type": "task/fetch"}}},
1281 {"type": "Action.ToggleVisibility", "title": "Owner notes", "targetElements": ["owner-note"]},
1282 {"type": "Action.ShowCard", "title": "Details", "card": {"body": [
1283 {"type": "TextBlock", "wrap": true, "text": "Last edited by **Mara Lindqvist** on Tuesday."}
1284 ]}}
1285 ]}
1286 ]
1287 });
1288 let mut messages = vec![
1289 bot_card_message("b1", at(0, 13, 45), &card),
1290 bot_card_message("b2", at(0, 13, 52), &input_card()),
1291 bot_card_message(
1292 "b3",
1293 at(0, 13, 58),
1294 &crate::demo_input_cards::all_inputs_card(),
1295 ),
1296 ];
1297 messages.extend(
1298 crate::demo_cards::behaviour_cards()
1299 .iter()
1300 .zip(0u32..)
1301 .map(|(card, index)| bot_card_message(&format!("g{index}"), at(0, 14, index), card)),
1302 );
1303 messages.extend(crate::demo_chart_cards::cards().iter().zip(0..).map(
1304 |(chart_card, minute)| {
1305 bot_card_message(&format!("c{minute}"), at(0, 15, minute), chart_card)
1306 },
1307 ));
1308 messages
1309}
1310
1311fn bot_card_message(id: &str, time: DateTime<Utc>, card: &serde_json::Value) -> MessageRecord {
1312 let attachments = serde_json::json!([{
1313 "content_type": "application/vnd.microsoft.card.adaptive",
1314 "name": null,
1315 "url": null,
1316 "text": null,
1317 "content": card.to_string()
1318 }]);
1319 let mut record = with_attachments(
1320 message(
1321 BOT_CHAT,
1322 id,
1323 None,
1324 ("", BOT_NAME),
1325 time,
1326 &format!("<attachment id=\"{id}\"></attachment>"),
1327 "[]",
1328 false,
1329 ),
1330 &attachments.to_string(),
1331 );
1332 record.sender_id = None;
1333 record.sender_application_id = Some(BOT_ID.to_owned());
1334 record
1335}
1336
1337fn input_card() -> serde_json::Value {
1338 serde_json::json!({
1339 "type": "AdaptiveCard",
1340 "body": [
1341 {"type": "TextBlock", "size": "medium", "weight": "bolder", "text": "Release request"},
1342 {"type": "Input.Text", "id": "title", "label": "Title", "placeholder": "Short summary", "isRequired": true, "errorMessage": "Give the release a title"},
1343 {"type": "Input.Text", "id": "notes", "label": "Notes", "placeholder": "Anything the reviewers should know", "isMultiline": true},
1344 {"type": "Input.Text", "id": "token", "label": "Access code", "style": "Password", "regex": "^\\d{4}$", "errorMessage": "Enter four digits"},
1345 {"type": "ColumnSet", "columns": [
1346 {"type": "Column", "width": "stretch", "items": [
1347 {"type": "Input.Number", "id": "count", "label": "Servers", "placeholder": "1-20", "min": 1, "max": 20, "value": 4}
1348 ]},
1349 {"type": "Column", "width": "stretch", "items": [
1350 {"type": "Input.Date", "id": "day", "label": "Release day", "value": "2026-11-02"}
1351 ]},
1352 {"type": "Column", "width": "stretch", "items": [
1353 {"type": "Input.Time", "id": "hour", "label": "Start time", "value": "09:30"}
1354 ]}
1355 ]},
1356 {"type": "Input.ChoiceSet", "id": "channel", "label": "Channel", "placeholder": "Pick a channel", "isRequired": true, "choices": [
1357 {"title": "Stable", "value": "stable"}, {"title": "Beta", "value": "beta"}, {"title": "Nightly", "value": "nightly"}
1358 ]},
1359 {"type": "Input.ChoiceSet", "id": "region", "label": "Region", "style": "expanded", "value": "eu", "choices": [
1360 {"title": "Europe", "value": "eu"}, {"title": "North America", "value": "na"}
1361 ]},
1362 {"type": "Input.ChoiceSet", "id": "checks", "label": "Checks", "style": "expanded", "isMultiSelect": true, "value": "lint", "choices": [
1363 {"title": "Lint", "value": "lint"}, {"title": "Unit tests", "value": "unit"}, {"title": "Smoke tests", "value": "smoke"}
1364 ]},
1365 {"type": "Input.Toggle", "id": "notify", "title": "Notify the team", "value": "yes", "valueOn": "yes", "valueOff": "no"}
1366 ],
1367 "actions": [
1368 {"type": "Action.Submit", "title": "Request release", "data": {"action": "release"}},
1369 {"type": "Action.Submit", "title": "Cancel", "associatedInputs": "none", "data": {"action": "cancel"}}
1370 ]
1371 })
1372}
1373
1374fn bot_app() -> ChatApp {
1375 ChatApp {
1376 app_id: "demo-app-wiki".to_owned(),
1377 name: BOT_APP_NAME.to_owned(),
1378 bot_ids: vec![BOT_ID.to_owned()],
1379 small_image_url: None,
1380 accent_color: None,
1381 web_application_resource: None,
1382 }
1383}
1384
1385pub async fn card_answer(task: CardTask) -> CardAnswer {
1386 tokio::time::sleep(CARD_ANSWER_DELAY).await;
1387 let data = match task {
1388 CardTask::Submit(_) => {
1389 return Ok((
1390 CardActionOutcome::Message("Settings saved".into()),
1391 Some((bot_app(), BOT_ID.to_owned())),
1392 ));
1393 }
1394 CardTask::Action(action) => match action.invoke_payload() {
1395 Some(payload) => payload.value,
1396 None => return Err("Not supported".to_owned()),
1397 },
1398 };
1399 let outcome = if data.pointer("/data/type").and_then(|kind| kind.as_str()) == Some("task/fetch")
1400 {
1401 CardActionOutcome::Dialog(TaskDialog {
1402 title: None,
1403 width: 520,
1404 height: 300,
1405 kind: TaskDialogKind::Card(settings_card().to_string()),
1406 })
1407 } else if data.get("action").and_then(|action| action.as_str()) == Some("unwatch") {
1408 CardActionOutcome::Failed("The app answered 500: demo failure".into())
1409 } else {
1410 CardActionOutcome::Sent
1411 };
1412 Ok((outcome, Some((bot_app(), BOT_ID.to_owned()))))
1413}
1414
1415pub async fn refresh_answer() -> CardAnswer {
1416 tokio::time::sleep(CARD_ANSWER_DELAY).await;
1417 Ok((
1418 CardActionOutcome::ReplaceCard(crate::demo_cards::refreshed_card().to_string()),
1419 Some((bot_app(), BOT_ID.to_owned())),
1420 ))
1421}
1422
1423fn settings_card() -> serde_json::Value {
1424 serde_json::json!({
1425 "type": "AdaptiveCard",
1426 "body": [
1427 {"type": "TextBlock", "weight": "bolder", "text": "Notification settings"},
1428 {"type": "TextBlock", "wrap": true, "isSubtle": true, "text": "Choose how the bot tells you about page changes."},
1429 {"type": "Input.ChoiceSet", "id": "frequency", "label": "Frequency", "style": "expanded", "value": "daily", "choices": [
1430 {"title": "Immediately", "value": "now"}, {"title": "Daily digest", "value": "daily"}
1431 ]},
1432 {"type": "Input.Toggle", "id": "mentions", "title": "Only when I am mentioned", "value": "false"}
1433 ],
1434 "actions": [
1435 {"type": "Action.Submit", "title": "Save", "data": {"save": true}}
1436 ]
1437 })
1438}
1439
1440pub const DEMO_TENANT_ID: &str = "demo-tenant";
1441const 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";
1442
1443fn meeting_link_messages() -> Vec<MessageRecord> {
1444 let mara = (MARA_ID, "Mara Lindqvist");
1445 vec![message(
1446 "demo-chat-mara",
1447 "ml1",
1448 None,
1449 mara,
1450 at(0, 13, 38),
1451 &format!(
1452 "<p>Let's sync live, here is the meeting: <a href=\"{DEMO_MEETING_LINK}\">Join the Teams meeting</a></p>"
1453 ),
1454 "[]",
1455 false,
1456 )]
1457}
1458
1459fn standup_messages() -> Vec<MessageRecord> {
1460 let jonas = (JONAS_ID, "Jonas Ortega");
1461 let priya = (PRIYA_ID, "Priya Nair");
1462 vec![
1463 with_attachments(
1464 message(
1465 "demo-chat-meeting-standup",
1466 "su1",
1467 None,
1468 priya,
1469 at(0, 9, 30),
1470 "<p>Notes from today.</p>",
1471 "[]",
1472 false,
1473 ),
1474 r#"[{"content_type":"reference","name":"Standup-notes.docx","url":"https://example.com/files/standup-notes.docx","text":null,"size":38900}]"#,
1475 ),
1476 message(
1477 "demo-chat-meeting-standup",
1478 "su2",
1479 None,
1480 jonas,
1481 at(0, 9, 45),
1482 "<p>Recording is available</p>",
1483 "[]",
1484 false,
1485 ),
1486 with_links(
1487 message(
1488 "demo-chat-meeting-standup",
1489 "su3",
1490 None,
1491 jonas,
1492 at(0, 9, 50),
1493 "<p><a href=\"https://example.com/checklist\">https://example.com/checklist</a></p>",
1494 "[]",
1495 false,
1496 ),
1497 link_preview("https://example.com/checklist")
1498 .map(|preview| preview.links_json())
1499 .unwrap_or_default(),
1500 ),
1501 message(
1502 "demo-chat-meeting-standup",
1503 "su4",
1504 None,
1505 priya,
1506 at(0, 9, 52),
1507 "<p>I will quickly fix the comments and then push the final version before the review starts.</p>",
1508 "[]",
1509 false,
1510 ),
1511 ]
1512}
1513
1514fn notes_messages() -> Vec<MessageRecord> {
1515 vec![message(
1516 NOTES_CHAT_ID,
1517 "n1",
1518 None,
1519 (DEMO_USER_ID, DEMO_USER_NAME),
1520 at(0, 8, 20),
1521 "<p>Release notes draft</p>",
1522 "[]",
1523 false,
1524 )]
1525}
1526
1527fn priority_messages() -> Vec<MessageRecord> {
1528 let priya = (PRIYA_ID, "Priya Nair");
1529 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1530 vec![
1531 message(
1532 PRIORITY_CHAT,
1533 "p1",
1534 None,
1535 me,
1536 at(0, 10, 40),
1537 "<p>Have you seen the error on staging yet?</p>",
1538 "[]",
1539 false,
1540 ),
1541 message(
1542 PRIORITY_CHAT,
1543 "p2",
1544 None,
1545 priya,
1546 at(0, 10, 47),
1547 &format!(
1548 "<p>Yes, here is the screenshot:</p><img src=\"{PENDING_IMAGE_KEY}\" width=\"1280\" height=\"720\">"
1549 ),
1550 "[]",
1551 false,
1552 ),
1553 ]
1554 .into_iter()
1555 .map(|record| match record.message_id.as_str() {
1556 "p2" => with_importance(record, MessageImportance::High),
1557 _ => record,
1558 })
1559 .collect()
1560}
1561
1562fn reaction(kind: &str, users: &[(&str, &str, DateTime<Utc>)]) -> Vec<serde_json::Value> {
1563 users
1564 .iter()
1565 .map(|(user_id, user_name, created_at)| {
1566 serde_json::json!({
1567 "reaction_type": kind,
1568 "user_id": user_id,
1569 "user_name": user_name,
1570 "created_at": created_at,
1571 })
1572 })
1573 .collect()
1574}
1575
1576fn reactions_json(groups: Vec<Vec<serde_json::Value>>) -> String {
1577 serde_json::Value::Array(groups.into_iter().flatten().collect()).to_string()
1578}
1579
1580fn release_messages() -> Vec<MessageRecord> {
1581 let chat = RELEASE_CHAT;
1582 let mara = (MARA_ID, "Mara Lindqvist");
1583 let jonas = (JONAS_ID, "Jonas Ortega");
1584 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1585 let jonas_name = "Jonas Ortega";
1586 let priya_name = "Priya Nair";
1587 let lea_name = "Lea Schneider";
1588 let mara_name = "Mara Lindqvist";
1589 let tobias_name = "Tobias Klein";
1590 let likes = reactions_json(vec![reaction(
1591 "like",
1592 &[
1593 (JONAS_ID, jonas_name, at(1, 16, 30)),
1594 (PRIYA_ID, priya_name, at(1, 17, 2)),
1595 (LEA_ID, lea_name, at(0, 8, 15)),
1596 ],
1597 )]);
1598 let hearts = reactions_json(vec![reaction(
1599 "heart",
1600 &[
1601 (DEMO_USER_ID, DEMO_USER_NAME, at(0, 10, 35)),
1602 (JONAS_ID, jonas_name, at(0, 10, 33)),
1603 ],
1604 )]);
1605 let single = reactions_json(vec![reaction(
1606 "laugh",
1607 &[(PRIYA_ID, priya_name, at(0, 9, 10))],
1608 )]);
1609 let many = reactions_json(vec![
1610 reaction(
1611 "like",
1612 &[
1613 (MARA_ID, mara_name, at(0, 13, 37)),
1614 (JONAS_ID, jonas_name, at(0, 13, 38)),
1615 (PRIYA_ID, priya_name, at(0, 13, 40)),
1616 (LEA_ID, lea_name, at(0, 13, 45)),
1617 (TOBIAS_ID, tobias_name, at(0, 13, 50)),
1618 ],
1619 ),
1620 reaction(
1621 "heart",
1622 &[
1623 (LEA_ID, lea_name, at(0, 13, 46)),
1624 (TOBIAS_ID, tobias_name, at(0, 13, 51)),
1625 ],
1626 ),
1627 reaction("\u{1F389}", &[(MARA_ID, mara_name, at(0, 13, 39))]),
1628 ]);
1629 vec![
1630 message(
1631 chat,
1632 "m1",
1633 None,
1634 mara,
1635 at(1, 16, 20),
1636 "<p>Release candidate is on staging. Can someone run the regression suite?</p>",
1637 "[]",
1638 false,
1639 ),
1640 message(
1641 chat,
1642 "m2",
1643 None,
1644 mara,
1645 at(1, 16, 22),
1646 "<p>Checklist lives in <a href=\"https://example.com/checklist\">release checklist</a>.</p>",
1647 &likes,
1648 false,
1649 ),
1650 with_links(
1651 message(
1652 chat,
1653 "m2a",
1654 None,
1655 mara,
1656 at(1, 16, 23),
1657 "<p><a href=\"https://example.com/checklist\">https://example.com/checklist</a></p>",
1658 "[]",
1659 false,
1660 ),
1661 link_preview("https://example.com/checklist")
1662 .map(|preview| preview.links_json())
1663 .unwrap_or_default(),
1664 ),
1665 message(
1666 chat,
1667 "m2b",
1668 None,
1669 mara,
1670 at(1, 16, 40),
1671 &format!(
1672 "<p>Staging dashboard right now:</p><img src=\"{STAGING_IMAGE_KEY}\" width=\"{}\" height=\"{}\">",
1673 STAGING_SIZE.0, STAGING_SIZE.1
1674 ),
1675 "[]",
1676 false,
1677 ),
1678 with_attachments(
1679 message(
1680 chat,
1681 "m2c",
1682 None,
1683 mara,
1684 at(1, 16, 41),
1685 "<p>Checklist and rollout plan attached.</p>",
1686 "[]",
1687 false,
1688 ),
1689 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}]"#,
1690 ),
1691 message(
1692 chat,
1693 "m3",
1694 None,
1695 me,
1696 at(0, 9, 2),
1697 "<p>I'll take the changelog.</p>",
1698 &single,
1699 false,
1700 ),
1701 message(
1702 chat,
1703 "m4",
1704 None,
1705 jonas,
1706 at(0, 10, 14),
1707 "<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>",
1708 "[]",
1709 false,
1710 ),
1711 message(
1712 chat,
1713 "m5",
1714 None,
1715 mara,
1716 at(0, 10, 31),
1717 "<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>",
1718 &hearts,
1719 true,
1720 ),
1721 message(
1722 chat,
1723 "m5b",
1724 None,
1725 mara,
1726 at(0, 10, 40),
1727 "<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>",
1728 "[]",
1729 false,
1730 ),
1731 message(
1732 chat,
1733 "m5c",
1734 None,
1735 jonas,
1736 at(0, 11, 5),
1737 "<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>",
1738 "[]",
1739 false,
1740 ),
1741 message(
1742 chat,
1743 "m5d",
1744 None,
1745 (PRIYA_ID, priya_name),
1746 at(0, 12, 20),
1747 &format!(
1748 "<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>"
1749 ),
1750 "[]",
1751 false,
1752 ),
1753 message(
1754 chat,
1755 "m5e",
1756 None,
1757 jonas,
1758 at(0, 12, 40),
1759 "<p>Context from the old planning chat.</p><attachment id=\"1789000000000\"></attachment>",
1760 r#"[{"content_type":"forwardedMessageReference","name":null,"url":null,"text":null,"id":"1789000000000","content":null,"unavailable":true}]"#,
1761 false,
1762 ),
1763 message(
1764 chat,
1765 "m6",
1766 None,
1767 me,
1768 at(0, 13, 35),
1769 "<p>Thanks, renamed. Tagging now.</p>",
1770 "[]",
1771 false,
1772 ),
1773 message(
1774 chat,
1775 "m7",
1776 None,
1777 me,
1778 at(0, 13, 36),
1779 "<p>Build 42 is green, see <a href=\"https://example.com/build/42\">pipeline</a>.</p>",
1780 &many,
1781 false,
1782 ),
1783 with_links(
1784 message(
1785 chat,
1786 "m7a",
1787 None,
1788 me,
1789 at(0, 13, 37),
1790 "<p>Notes are in <a href=\"https://example.com/notes\">https://example.com/notes</a></p>",
1791 "[]",
1792 false,
1793 ),
1794 LinkPreview {
1795 url: "https://example.com/notes".to_owned(),
1796 title: Some("Release notes 0.2".to_owned()),
1797 description: Some("What changed since 0.1".to_owned()),
1798 image_url: None,
1799 image_width: None,
1800 image_height: None,
1801 }
1802 .links_json(),
1803 ),
1804 message(
1805 chat,
1806 "m8",
1807 None,
1808 jonas,
1809 at(0, 13, 40),
1810 "<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>",
1811 "[]",
1812 false,
1813 ),
1814 message(
1815 chat,
1816 "m9",
1817 None,
1818 (PRIYA_ID, priya_name),
1819 at(0, 13, 45),
1820 &format!(
1821 "<p>Ship it!</p><img src=\"{}\" width=\"{}\" height=\"{}\" alt=\"Party\" itemtype=\"http://schema.skype.com/Giphy\">",
1822 demo_gifs::RECEIVED_GIF_KEY,
1823 demo_gifs::RECEIVED_GIF_SIZE.0,
1824 demo_gifs::RECEIVED_GIF_SIZE.1
1825 ),
1826 "[]",
1827 false,
1828 ),
1829 message(
1830 chat,
1831 FRENCH_MESSAGE,
1832 None,
1833 (LEA_ID, lea_name),
1834 at(0, 13, 47),
1835 "<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>",
1836 "[]",
1837 false,
1838 ),
1839 message(
1840 chat,
1841 SPANISH_MESSAGE,
1842 None,
1843 jonas,
1844 at(0, 13, 49),
1845 "<p>Gracias por el aviso. Probar\u{e9} la compilaci\u{f3}n esta tarde y os dir\u{e9} si algo falla.</p>",
1846 "[]",
1847 false,
1848 ),
1849 message(
1850 chat,
1851 "m10",
1852 None,
1853 (PRIYA_ID, priya_name),
1854 at(0, 13, 50),
1855 "<p><emoji id=\"heart\" alt=\"\u{2764}\u{fe0f}\" title=\"Heart\"></emoji></p>",
1856 &many,
1857 false,
1858 ),
1859 message(
1860 chat,
1861 "m11",
1862 None,
1863 me,
1864 at(0, 13, 51),
1865 "<p>\u{1f44d}\u{1f389}</p>",
1866 "[]",
1867 false,
1868 ),
1869 ]
1870}
1871
1872fn unread_messages() -> Vec<MessageRecord> {
1873 let me = (DEMO_USER_ID, DEMO_USER_NAME);
1874 let lea = (LEA_ID, "Lea Schneider");
1875 let tobias = (TOBIAS_ID, "Tobias Klein");
1876 let rows = [
1877 (
1878 "u1",
1879 me,
1880 at(1, 17, 5),
1881 "<p>Can you enable access for North?</p>",
1882 ),
1883 ("u2", tobias, at(1, 17, 20), "<p>I'll check with IT.</p>"),
1884 (
1885 "u3",
1886 lea,
1887 at(0, 12, 40),
1888 "<p>Good morning, access is ready.</p>",
1889 ),
1890 (
1891 "u4",
1892 lea,
1893 at(0, 12, 41),
1894 "<p>Sign in with your company ID, no password needed.</p>",
1895 ),
1896 ("u5", lea, at(0, 12, 50), "<p>Access is enabled now</p>"),
1897 ];
1898 rows.into_iter()
1899 .map(|(id, sender, time, html)| {
1900 message(UNREAD_CHAT, id, None, sender, time, html, "[]", false)
1901 })
1902 .map(|record| match record.message_id.as_str() {
1903 "u5" => with_importance(record, MessageImportance::Urgent),
1904 _ => record,
1905 })
1906 .collect()
1907}
1908
1909const DEMO_EXTRA_TABS_CHANNEL: &str = "demo-channel-1-2";
1910const DEMO_EXTRA_TABS: [&str; 6] = [
1911 "Incident dashboard",
1912 "Postmortems",
1913 "Escalation policy",
1914 "Status page",
1915 "Vendor contacts",
1916 "On-call calendar",
1917];
1918
1919fn demo_tab(
1920 channel_id: &str,
1921 name: &str,
1922 definition_id: &str,
1923 open_url: Option<&str>,
1924) -> ChannelTabRecord {
1925 ChannelTabRecord {
1926 tab_id: format!("{channel_id}-{}", name.to_lowercase().replace(' ', "-")),
1927 name: name.to_owned(),
1928 definition_id: definition_id.to_owned(),
1929 open_url: open_url.map(str::to_owned),
1930 }
1931}
1932
1933fn demo_channel_tabs(channel_id: &str) -> Vec<ChannelTabRecord> {
1934 let mut tabs = vec![
1935 demo_tab(
1936 channel_id,
1937 "Runbook",
1938 "com.microsoft.teamspace.tab.web",
1939 Some("https://wiki.example.com/display/TEAM/Runbook"),
1940 ),
1941 demo_tab(
1942 channel_id,
1943 "Sprint board",
1944 "com.microsoft.teamspace.tab.planner",
1945 None,
1946 ),
1947 demo_tab(
1948 channel_id,
1949 "Team notes",
1950 "0d820ecd-def2-4297-adad-78056cde7c78",
1951 Some("https://onenote.example.com/notes"),
1952 ),
1953 ];
1954 if channel_id == DEMO_EXTRA_TABS_CHANNEL {
1955 tabs.extend(DEMO_EXTRA_TABS.iter().map(|name| {
1956 demo_tab(
1957 channel_id,
1958 name,
1959 "com.microsoft.teamspace.tab.web",
1960 Some("https://wiki.example.com/display/TEAM/Page"),
1961 )
1962 }));
1963 }
1964 tabs
1965}
1966
1967fn demo_team_layout(channels: &[ChannelRecord]) -> Vec<TeamLayoutRecord> {
1968 DEMO_TEAM_ORDER
1969 .iter()
1970 .map(|team_id| TeamLayoutRecord {
1971 team_id: (*team_id).to_owned(),
1972 hidden: *team_id == DEMO_HIDDEN_TEAM,
1973 channels: channels
1974 .iter()
1975 .filter(|channel| channel.team_id == *team_id)
1976 .map(|channel| ChannelLayoutRecord {
1977 channel_id: channel.id.clone(),
1978 general: channel.name == "General",
1979 hidden: channel.id == DEMO_HIDDEN_CHANNEL,
1980 tabs: demo_channel_tabs(&channel.id),
1981 notifications: DEMO_CHANNEL_NOTIFICATIONS
1982 .iter()
1983 .find(|(id, _, _)| *id == channel.id)
1984 .map(|(_, level, include_replies)| ChannelNotifications {
1985 level: *level,
1986 include_replies: *include_replies,
1987 })
1988 .unwrap_or_default(),
1989 })
1990 .collect(),
1991 })
1992 .collect()
1993}
1994
1995const ROLLOUT_REPLIES: [(&str, &str); 12] = [
1996 (MARA_ID, "Staging looks good on my side."),
1997 (JONAS_ID, "Smoke tests passed, no regressions."),
1998 (PRIYA_ID, "Docs for the new settings page are merged."),
1999 (LEA_ID, "Support is briefed, nothing blocking."),
2000 (MARA_ID, "Can we keep the old export for one more release?"),
2001 (JONAS_ID, "Yes, behind a flag. I will add it today."),
2002 (PRIYA_ID, "Changelog draft is ready for review."),
2003 (LEA_ID, "Customer success wants a heads-up the day before."),
2004 (MARA_ID, "I will send that mail on Thursday."),
2005 (JONAS_ID, "Flag is in, rebuilding staging now."),
2006 (PRIYA_ID, "Rollback steps are in the runbook."),
2007 (LEA_ID, "All green from QA. Go for Friday."),
2008];
2009
2010fn channel_messages() -> Vec<MessageRecord> {
2011 let channel = "demo-channel-1-1";
2012 let mara = (MARA_ID, "Mara Lindqvist");
2013 let tobias = (TOBIAS_ID, "Tobias Klein");
2014 let people = [
2015 (MARA_ID, "Mara Lindqvist"),
2016 (JONAS_ID, "Jonas Ortega"),
2017 (PRIYA_ID, "Priya Nair"),
2018 (LEA_ID, "Lea Schneider"),
2019 ];
2020 let rollout_replies = ROLLOUT_REPLIES
2021 .iter()
2022 .enumerate()
2023 .map(|(index, (sender, text))| {
2024 let sender = people
2025 .iter()
2026 .copied()
2027 .find(|(id, _)| id == sender)
2028 .expect("known person");
2029 message(
2030 channel,
2031 &format!("t3r{}", index + 1),
2032 Some("t3"),
2033 sender,
2034 at(0, 9, 40) + Duration::minutes(6 * index as i64),
2035 &format!("<p>{text}</p>"),
2036 "[]",
2037 false,
2038 )
2039 });
2040 let mut records = vec![
2041 message(
2042 channel,
2043 "t1",
2044 None,
2045 mara,
2046 at(0, 8, 0),
2047 "<p>Weekly sync notes are up.</p>",
2048 "[]",
2049 false,
2050 ),
2051 message(
2052 channel,
2053 "t1r1",
2054 Some("t1"),
2055 tobias,
2056 at(0, 8, 20),
2057 "<p>Thanks, adding my items.</p>",
2058 "[]",
2059 false,
2060 ),
2061 with_subject(
2062 message(
2063 channel,
2064 "t3",
2065 None,
2066 tobias,
2067 at(0, 9, 30),
2068 "<p>Release build 42 is green, deploying to staging now.</p>",
2069 "[]",
2070 false,
2071 ),
2072 "Release 42 rollout",
2073 ),
2074 message(
2075 channel,
2076 "t2",
2077 None,
2078 tobias,
2079 at(0, 10, 0),
2080 "<p>Who owns the on-call handover?</p>",
2081 "[]",
2082 false,
2083 ),
2084 message(
2085 channel,
2086 "t4",
2087 None,
2088 mara,
2089 at(3, 8, 42),
2090 "<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>",
2091 "[]",
2092 false,
2093 ),
2094 message(
2095 channel,
2096 "t4r1",
2097 Some("t4"),
2098 tobias,
2099 at(0, 9, 15),
2100 "<p>Yes, all done.</p>",
2101 "[]",
2102 false,
2103 ),
2104 ];
2105 records.extend(rollout_replies);
2106 records.extend(code_post(channel, tobias));
2107 records.extend(shared_channel_messages(channel, mara, tobias));
2108 records
2109}
2110
2111fn code_post(channel: &str, tobias: (&str, &str)) -> Vec<MessageRecord> {
2112 let laughs = reactions_json(vec![reaction(
2113 "laugh",
2114 &[
2115 (PRIYA_ID, "Priya Nair", at(0, 11, 20)),
2116 (JONAS_ID, "Jonas Ortega", at(0, 11, 22)),
2117 ],
2118 )]);
2119 vec![
2120 with_subject(
2121 message(
2122 channel,
2123 "t8",
2124 None,
2125 tobias,
2126 at(0, 11, 5),
2127 "<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>",
2128 &laughs,
2129 false,
2130 ),
2131 "Build script error",
2132 ),
2133 message(
2134 channel,
2135 "t8r1",
2136 Some("t8"),
2137 (JONAS_ID, "Jonas Ortega"),
2138 at(0, 11, 30),
2139 "<p>Add <code>-UseBasicParsing</code> to the call, that fixes it.</p>",
2140 "[]",
2141 false,
2142 ),
2143 ]
2144}
2145
2146fn shared_channel_messages(
2147 channel: &str,
2148 mara: (&str, &str),
2149 tobias: (&str, &str),
2150) -> Vec<MessageRecord> {
2151 let priya = (PRIYA_ID, "Priya Nair");
2152 let jonas = (JONAS_ID, "Jonas Ortega");
2153 let reference = |name: &str, size: u64| {
2154 format!(
2155 r#"{{"content_type":"reference","name":"{name}","url":"https://demo.sharepoint.example/sites/demo/{name}","text":null,"size":{size}}}"#
2156 )
2157 };
2158 vec![
2159 with_attachments(
2160 with_subject(
2161 message(
2162 channel,
2163 "t5",
2164 None,
2165 priya,
2166 at(1, 14, 5),
2167 "<p>Roadmap deck and checklist for Q4 are attached.</p>",
2168 "[]",
2169 false,
2170 ),
2171 "Q4 planning files",
2172 ),
2173 &format!(
2174 "[{},{}]",
2175 reference("Roadmap-Q4.pptx", 3_412_000),
2176 reference("Release-Checklist-Q4.xlsx", 48_213)
2177 ),
2178 ),
2179 message(
2180 channel,
2181 "t5r1",
2182 Some("t5"),
2183 jonas,
2184 at(1, 14, 30),
2185 "<p>Rollback steps are here: <a href=\"https://docs.example.org/runbooks/rollback\">https://docs.example.org/runbooks/rollback</a></p>",
2186 "[]",
2187 false,
2188 ),
2189 with_attachments(
2190 message(
2191 channel,
2192 "t6",
2193 None,
2194 mara,
2195 at(12, 10, 0),
2196 "<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>",
2197 "[]",
2198 false,
2199 ),
2200 &format!("[{}]", reference("Postmortem-Draft.docx", 91_400)),
2201 ),
2202 with_attachments(
2203 message(
2204 channel,
2205 "t7",
2206 None,
2207 tobias,
2208 at(20, 9, 0),
2209 "<p>Rollout plan for the new export, please review.</p>",
2210 "[]",
2211 false,
2212 ),
2213 &format!("[{}]", reference("Rollout-Plan.pdf", 2_306_867)),
2214 ),
2215 ]
2216}
2217
2218fn crc32(bytes: &[u8]) -> u32 {
2219 let mut crc = 0xffff_ffffu32;
2220 for byte in bytes {
2221 crc ^= u32::from(*byte);
2222 for _ in 0..8 {
2223 crc = if crc & 1 == 1 {
2224 (crc >> 1) ^ 0xedb8_8320
2225 } else {
2226 crc >> 1
2227 };
2228 }
2229 }
2230 !crc
2231}
2232
2233fn adler32(bytes: &[u8]) -> u32 {
2234 let (mut low, mut high) = (1u32, 0u32);
2235 for byte in bytes {
2236 low = (low + u32::from(*byte)) % 65521;
2237 high = (high + low) % 65521;
2238 }
2239 (high << 16) | low
2240}
2241
2242fn png_chunk(output: &mut Vec<u8>, kind: &[u8; 4], data: &[u8]) {
2243 output.extend_from_slice(&(data.len() as u32).to_be_bytes());
2244 let mut body = kind.to_vec();
2245 body.extend_from_slice(data);
2246 output.extend_from_slice(&body);
2247 output.extend_from_slice(&crc32(&body).to_be_bytes());
2248}
2249
2250fn inside(x: f32, y: f32, center: (f32, f32), radius: (f32, f32)) -> bool {
2251 ((x - center.0) / radius.0).powi(2) + ((y - center.1) / radius.1).powi(2) <= 1.
2252}
2253
2254fn staging_pixel(column: usize, row: usize) -> [u8; 3] {
2255 let (width, height) = (STAGING_SIZE.0 as f32, STAGING_SIZE.1 as f32);
2256 let (x, y) = (column as f32, row as f32);
2257 let shade = y / height;
2258 let background = [
2259 (30. - 14. * shade) as u8,
2260 (41. - 16. * shade) as u8,
2261 (59. - 14. * shade) as u8,
2262 ];
2263 let bar_width = width / 14.;
2264 let slot = (x / bar_width) as usize;
2265 let in_bar = x - slot as f32 * bar_width > bar_width * 0.18;
2266 let bar_height = height * (0.25 + 0.5 * (((slot * 7 + 3) % 11) as f32 / 11.));
2267 let on_bars = in_bar && y > height * 0.86 - bar_height && y < height * 0.86 && slot < 14;
2268 let header = y < height * 0.1;
2269 if header {
2270 [22, 30, 45]
2271 } else if on_bars {
2272 if slot % 4 == 3 {
2273 [226, 87, 47]
2274 } else {
2275 [88, 133, 196]
2276 }
2277 } else if (y - height * 0.86).abs() < 1.5 {
2278 [71, 85, 105]
2279 } else {
2280 background
2281 }
2282}
2283
2284fn encode_png(palette: &Palette) -> Vec<u8> {
2285 let scale = PHOTO_SIZE as f32 / DEMO_PHOTO_SIDE as f32;
2286 encode_rgb(DEMO_PHOTO_SIDE, DEMO_PHOTO_SIDE, |column, row| {
2287 let (x, y) = ((column as f32 + 0.5) * scale, (row as f32 + 0.5) * scale);
2288 if inside(x, y, (24., 21.), (8.5, 9.5)) {
2289 palette.skin
2290 } else if inside(x, y, (24., 19.), (10.5, 11.)) && y < 22. {
2291 palette.hair
2292 } else if inside(x, y, (24., 50.), (22., 19.)) {
2293 palette.shirt
2294 } else {
2295 palette.background
2296 }
2297 })
2298}
2299
2300fn encode_rgb(width: usize, height: usize, pixel: impl Fn(usize, usize) -> [u8; 3]) -> Vec<u8> {
2301 let mut raw = Vec::with_capacity(height * (width * 3 + 1));
2302 for row in 0..height {
2303 raw.push(0);
2304 for column in 0..width {
2305 raw.extend_from_slice(&pixel(column, row));
2306 }
2307 }
2308 let mut zlib = vec![0x78, 0x01];
2309 let mut blocks = raw.chunks(65535).peekable();
2310 while let Some(block) = blocks.next() {
2311 zlib.push(u8::from(blocks.peek().is_none()));
2312 zlib.extend_from_slice(&(block.len() as u16).to_le_bytes());
2313 zlib.extend_from_slice(&(!(block.len() as u16)).to_le_bytes());
2314 zlib.extend_from_slice(block);
2315 }
2316 zlib.extend_from_slice(&adler32(&raw).to_be_bytes());
2317 let mut header = Vec::new();
2318 header.extend_from_slice(&(width as u32).to_be_bytes());
2319 header.extend_from_slice(&(height as u32).to_be_bytes());
2320 header.extend_from_slice(&[8, 2, 0, 0, 0]);
2321 let mut png = vec![0x89, b'P', b'N', b'G', 0x0d, 0x0a, 0x1a, 0x0a];
2322 png_chunk(&mut png, b"IHDR", &header);
2323 png_chunk(&mut png, b"IDAT", &zlib);
2324 png_chunk(&mut png, b"IEND", &[]);
2325 png
2326}
2327
2328#[cfg(test)]
2329mod tests {
2330 use super::*;
2331
2332 #[test]
2333 fn the_demo_has_one_important_and_one_urgent_message() {
2334 let store = Store::open_in_memory().unwrap();
2335 seed(&store);
2336 let importance = |chat: &str, message_id: &str| {
2337 store
2338 .messages(chat, None, 50)
2339 .unwrap()
2340 .into_iter()
2341 .find(|record| record.message_id == message_id)
2342 .map(|record| record.importance)
2343 };
2344 assert_eq!(
2345 importance(PRIORITY_CHAT, "p2"),
2346 Some(MessageImportance::High)
2347 );
2348 assert_eq!(
2349 importance(UNREAD_CHAT, "u5"),
2350 Some(MessageImportance::Urgent)
2351 );
2352 }
2353
2354 #[test]
2355 fn png_has_signature_and_ends_with_iend() {
2356 let png = encode_png(&MARA);
2357 assert_eq!(&png[..8], &[0x89, b'P', b'N', b'G', 0x0d, 0x0a, 0x1a, 0x0a]);
2358 assert_eq!(&png[png.len() - 8..png.len() - 4], b"IEND");
2359 }
2360
2361 #[test]
2362 fn crc_and_adler_match_known_values() {
2363 assert_eq!(crc32(b"IEND"), 0xae42_6082);
2364 assert_eq!(adler32(b"Wikipedia"), 0x11e6_0398);
2365 }
2366
2367 #[test]
2368 fn mention_candidates_filter_by_name_and_add_scope_in_channels() {
2369 let chat = mention_candidates("demo-chat-release", "ma");
2370 assert_eq!(chat.len(), 1);
2371 assert_eq!(chat[0].display_name(), "Mara Lindqvist");
2372 let channel = mention_candidates("demo-channel-1-1", "gen");
2373 assert!(matches!(channel[0], MentionCandidate::Channel { .. }));
2374 assert_eq!(mention_candidates("demo-chat-release", "").len(), 5);
2375 }
2376
2377 #[test]
2378 fn new_group_chat_gets_a_title_and_the_first_message() {
2379 let people = vec![
2380 (MARA_ID.to_owned(), "Mara Lindqvist".to_owned()),
2381 (JONAS_ID.to_owned(), "Jonas Ortega".to_owned()),
2382 ];
2383 let now = Utc::now();
2384 let (chat, record) = new_chat(
2385 &[],
2386 &people,
2387 Some("Crew"),
2388 "Hello all",
2389 "Hello <i>all</i>",
2390 now,
2391 );
2392 assert_eq!(chat.id, "demo-chat-new-1");
2393 assert_eq!(chat.kind, "group");
2394 assert_eq!(chat.title, "Crew");
2395 assert_eq!(chat.member_summary, "Mara Lindqvist, Jonas Ortega");
2396 assert_eq!(chat.members.len(), 3);
2397 assert_eq!(chat.members[0].user_id.as_deref(), Some(DEMO_USER_ID));
2398 assert_eq!(chat.last_message_preview.as_deref(), Some("Hello all"));
2399 assert_eq!(chat.last_message_at, Some(now));
2400 assert_eq!(record.conversation_id, chat.id);
2401 assert_eq!(record.sender_id.as_deref(), Some(DEMO_USER_ID));
2402 assert!(record.body_html.contains("Hello"));
2403 }
2404
2405 #[test]
2406 fn new_one_on_one_chat_has_no_title_and_counts_up() {
2407 let people = vec![(LEA_ID.to_owned(), "Lea Schneider".to_owned())];
2408 let (first, _) = new_chat(&[], &people, None, "Hi", "Hi", Utc::now());
2409 assert_eq!(first.kind, "oneOnOne");
2410 assert!(first.title.is_empty());
2411 let (second, _) = new_chat(&[first], &people, None, "Hi again", "Hi again", Utc::now());
2412 assert_eq!(second.id, "demo-chat-new-2");
2413 }
2414
2415 #[test]
2416 fn sending_into_a_chat_refreshes_its_preview() {
2417 let base = ChatRecord {
2418 id: "demo-chat-x".to_owned(),
2419 unread: true,
2420 ..Default::default()
2421 };
2422 let (chat, record) = send_in_chat(&base, "Ping", "Ping", Utc::now());
2423 assert!(!chat.unread);
2424 assert_eq!(chat.last_message_preview.as_deref(), Some("Ping"));
2425 assert_eq!(record.conversation_id, "demo-chat-x");
2426 }
2427
2428 #[test]
2429 fn demo_covers_the_sidebar_edge_cases() {
2430 let chats = demo_chats();
2431 assert!(chats.iter().any(|chat| chat.deleted));
2432 assert!(chats.iter().any(|chat| chat.title.len() > 40));
2433 assert!(chats.iter().filter(|chat| chat.unread).count() >= 3);
2434 }
2435}