BlueGit

ict rusty-teams

Files

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

demo.rs

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