BlueGit

ict rusty-teams

Files

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

demo.rs

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