BlueGit

ict rusty-teams

Files

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

demo.rs

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