BlueGit

ict rusty-teams

Files

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

demo.rs

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