BlueGit

ict rusty-teams

Files

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

demo.rs

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