BlueGit

ict rusty-teams

Files

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

demo.rs

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