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