BlueGit

ict rusty-teams

Files

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

demo.rs

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