BlueGit

ict rusty-teams

Files

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

demo.rs

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