BlueGit

ict rusty-teams

Files

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

demo.rs

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