BlueGit

ict rusty-teams

Files

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

demo.rs

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