BlueGit

ict rusty-teams

Files

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

app_state.rs

app_state.rs 25.9 KiB Download Raw
1use std::collections::{HashMap, HashSet};
2use std::sync::Arc;
3use std::time::Instant;
4
5use chatsvc::TypingEvent;
6use chrono::{DateTime, Utc};
7use gpui_kit::*;
8use store::{ChatRecord, Sidebar, Store};
9use teams_core::{ChatApp, CoreEvent, ImageRef, ScheduledDraft};
10
11use crate::backend::{BackendEvent, ConnectionState, Engine, LiveState};
12use crate::card_state::{CardState, TaskDialogState};
13use crate::data::{self, Directory};
14use crate::local_previews::{LocalPreview, load_local_previews};
15use crate::notice::Notice;
16use crate::notify;
17use crate::typing::TypingState;
18
19const COLLAPSED_META_KEY: &str = "ui.collapsed_sections";
20const RECENT_MESSAGES_FOR_TYPING: usize = 5;
21
22#[derive(Debug, Clone, PartialEq, Eq)]
23pub enum Selection {
24 Chat(String),
25 Channel(String),
26}
27
28impl Selection {
29 pub fn conversation_id(&self) -> &str {
30 match self {
31 Selection::Chat(id) | Selection::Channel(id) => id,
32 }
33 }
34}
35
36pub enum AppEvent {
37 Sidebar,
38 Selection,
39 Messages(String),
40 Images(Vec<String>),
41 Jump,
42 Status,
43 Directory,
44 Cards(String),
45 TaskDialog,
46 Typing,
47 LocalPreviews,
48 Outbox(String),
49 Scheduled,
50}
51
52#[derive(Debug, Clone, Copy, Default)]
53pub struct Mode {
54 pub demo: bool,
55 pub read_only: bool,
56 pub demo_sync: Option<std::time::Duration>,
57}
58
59pub struct AppState {
60 pub store: Arc<Store>,
61 pub engine: Option<Arc<Engine>>,
62 pub sidebar: Sidebar,
63 pub favorite_ids: Vec<String>,
64 pub selection: Option<Selection>,
65 pub new_chat: bool,
66 pub connection: ConnectionState,
67 pub live: LiveState,
68 pub last_sync: Option<DateTime<Utc>>,
69 pub mode: Mode,
70 pub directory: Directory,
71 pub collapsed: HashSet<String>,
72 pub followed_channels: HashSet<String>,
73 pub start_on_channels: bool,
74 pub pending_jump: Option<(String, String)>,
75 pub cards: CardState,
76 pub task_dialog: Option<TaskDialogState>,
77 pub bot_apps: HashMap<String, Vec<ChatApp>>,
78 pub bot_apps_pending: HashSet<String>,
79 pub notice: Option<Notice>,
80 pub notice_count: u64,
81 pub keep_unread: Option<String>,
82 pub typing: TypingState,
83 typing_timer_running: bool,
84 pub local_previews: HashMap<String, LocalPreview>,
85 pub scheduled: Vec<ScheduledDraft>,
86 pub scheduled_polling: bool,
87}
88
89pub struct AppHandle(pub Entity<AppState>);
90
91impl Global for AppHandle {}
92
93impl EventEmitter<AppEvent> for AppState {}
94
95pub fn chat_title(chat: &ChatRecord) -> String {
96 if !chat.title.trim().is_empty() {
97 chat.title.clone()
98 } else if !chat.member_summary.trim().is_empty() {
99 chat.member_summary.clone()
100 } else {
101 "Chat".to_owned()
102 }
103}
104
105pub fn selection_title(sidebar: &Sidebar, selection: &Selection) -> String {
106 match selection {
107 Selection::Chat(id) => sidebar
108 .chats
109 .iter()
110 .find(|chat| &chat.id == id)
111 .map(chat_title)
112 .unwrap_or_else(|| "Chat".to_owned()),
113 Selection::Channel(id) => sidebar
114 .teams
115 .iter()
116 .find_map(|team| {
117 team.channels
118 .iter()
119 .find(|channel| &channel.id == id)
120 .map(|channel| format!("{} / {}", team.team.name, channel.name))
121 })
122 .unwrap_or_else(|| "Channel".to_owned()),
123 }
124}
125
126impl AppState {
127 pub fn new(store: Arc<Store>, mode: Mode) -> Self {
128 let sidebar = store.sidebar().unwrap_or_default();
129 let mut state = AppState {
130 store,
131 engine: None,
132 sidebar,
133 favorite_ids: Vec::new(),
134 selection: None,
135 new_chat: false,
136 connection: if mode.demo {
137 ConnectionState::Online
138 } else {
139 ConnectionState::Connecting
140 },
141 live: LiveState::Off,
142 last_sync: None,
143 mode,
144 directory: Directory::default(),
145 collapsed: HashSet::new(),
146 followed_channels: HashSet::new(),
147 start_on_channels: false,
148 pending_jump: None,
149 cards: CardState::default(),
150 task_dialog: None,
151 bot_apps: HashMap::new(),
152 bot_apps_pending: HashSet::new(),
153 notice: None,
154 notice_count: 0,
155 keep_unread: None,
156 typing: TypingState::default(),
157 typing_timer_running: false,
158 local_previews: HashMap::new(),
159 scheduled: Vec::new(),
160 scheduled_polling: false,
161 };
162 state.local_previews = load_local_previews(&state.store);
163 state.collapsed = state.load_collapsed();
164 state.followed_channels = notify::load_followed_channels(&state.store);
165 if !mode.demo {
166 state.directory.load_cached_presence(&state.store);
167 state.reload_directory();
168 }
169 state
170 }
171
172 fn load_collapsed(&self) -> HashSet<String> {
173 self.store
174 .meta(COLLAPSED_META_KEY)
175 .ok()
176 .flatten()
177 .map(|value| {
178 value
179 .lines()
180 .map(str::to_owned)
181 .filter(|id| !id.is_empty())
182 .collect()
183 })
184 .unwrap_or_default()
185 }
186
187 pub fn toggle_followed_channel(&mut self, channel_id: &str, cx: &mut Context<Self>) {
188 if !self.followed_channels.remove(channel_id) {
189 self.followed_channels.insert(channel_id.to_owned());
190 }
191 notify::save_followed_channels(&self.store, &self.followed_channels);
192 cx.notify();
193 }
194
195 pub fn toggle_collapsed(&mut self, section_id: &str, cx: &mut Context<Self>) {
196 if !self.collapsed.remove(section_id) {
197 self.collapsed.insert(section_id.to_owned());
198 }
199 let mut ids: Vec<&str> = self.collapsed.iter().map(String::as_str).collect();
200 ids.sort_unstable();
201 let _ = self.store.set_meta(COLLAPSED_META_KEY, &ids.join("\n"));
202 cx.emit(AppEvent::Sidebar);
203 cx.notify();
204 }
205
206 pub fn reload_directory(&mut self) {
207 self.directory.me = data::me(&self.store);
208 self.directory.folders = data::folders(&self.store, &self.favorite_ids);
209 self.directory.pinned_channels = data::pinned_channels(&self.store);
210 if self.directory.pinned_channels.is_empty() {
211 let known: HashSet<&str> = self
212 .sidebar
213 .teams
214 .iter()
215 .flat_map(|team| team.channels.iter().map(|channel| channel.id.as_str()))
216 .collect();
217 self.directory.pinned_channels = self
218 .favorite_ids
219 .iter()
220 .filter(|id| known.contains(id.as_str()))
221 .cloned()
222 .collect();
223 }
224 self.resolve_pending_avatars();
225 self.sync_presence();
226 self.directory.unread_counts = match &self.engine {
227 Some(engine) => data::unread_counts(engine, &self.sidebar.chats),
228 None => Default::default(),
229 };
230 }
231
232 pub fn request_avatars(&mut self, user_ids: Vec<String>, cx: &mut Context<Self>) {
233 let wanted = self.directory.missing_avatars(user_ids);
234 if wanted.is_empty() {
235 return;
236 }
237 let mut changed = false;
238 let mut uncached = Vec::new();
239 for user_id in wanted {
240 match data::cached_avatar(&self.store, &user_id) {
241 Some(cached) => {
242 self.directory.set_avatar(&user_id, cached);
243 changed = true;
244 }
245 None => uncached.push(user_id),
246 }
247 }
248 if let Some(engine) = self.engine.clone().filter(|_| !uncached.is_empty()) {
249 self.directory.mark_avatars_pending(&uncached);
250 let done = data::fetch_avatars(&engine, uncached);
251 self.on_done(done, cx, |state, cx| {
252 state.resolve_pending_avatars();
253 cx.emit(AppEvent::Directory);
254 cx.notify();
255 });
256 changed = true;
257 }
258 if changed {
259 cx.emit(AppEvent::Directory);
260 cx.notify();
261 }
262 }
263
264 pub fn request_images(&mut self, images: Vec<ImageRef>, cx: &mut Context<Self>) {
265 let Some(engine) = self.engine.clone() else {
266 return;
267 };
268 let wanted = self
269 .directory
270 .images_to_request(images.iter().map(|image| image.url.clone()));
271 let mut changed = false;
272 for image in images
273 .into_iter()
274 .filter(|image| wanted.contains(&image.url))
275 {
276 match engine.image_path(&image) {
277 Some(path) => {
278 self.directory.set_image(&image.url, &path);
279 changed = true;
280 }
281 None => {
282 let done = data::fetch_image(&engine, image);
283 self.on_done(done, cx, |_, _| {});
284 }
285 }
286 }
287 if changed {
288 cx.emit(AppEvent::Images(wanted));
289 cx.notify();
290 }
291 }
292
293 pub fn jump_to_message(
294 &mut self,
295 selection: Selection,
296 message_id: String,
297 cx: &mut Context<Self>,
298 ) {
299 self.pending_jump = Some((selection.conversation_id().to_owned(), message_id));
300 if self.selection.as_ref() == Some(&selection) {
301 cx.emit(AppEvent::Jump);
302 } else {
303 self.select(selection, cx);
304 }
305 }
306
307 fn on_done(
308 &self,
309 done: data::Done,
310 cx: &mut Context<Self>,
311 then: impl FnOnce(&mut Self, &mut Context<Self>) + 'static,
312 ) {
313 cx.spawn(async move |this, cx| {
314 let _ = done.await;
315 this.update(cx, |state, cx| then(state, cx)).ok();
316 })
317 .detach();
318 }
319
320 fn resolve_pending_avatars(&mut self) {
321 for user_id in self.directory.pending_avatars() {
322 if let Some(cached) = data::cached_avatar(&self.store, &user_id) {
323 self.directory.set_avatar(&user_id, cached);
324 }
325 }
326 }
327
328 fn sync_presence(&mut self) -> Vec<String> {
329 let Some(engine) = self.engine.clone() else {
330 return Vec::new();
331 };
332 self.directory
333 .requested_presence_ids()
334 .into_iter()
335 .filter(|user_id| {
336 data::presence_kind(&engine, user_id)
337 .is_some_and(|kind| self.directory.set_presence(user_id, kind))
338 })
339 .collect()
340 }
341
342 pub fn request_presence(&mut self, user_ids: Vec<String>, cx: &mut Context<Self>) {
343 let now = Instant::now();
344 let pushed = self.live == LiveState::Live;
345 let wanted = self.directory.stale_presence(user_ids, now, pushed);
346 if wanted.is_empty() {
347 return;
348 }
349 self.directory.mark_presence_pending(&wanted);
350 if let Some(engine) = self.engine.clone() {
351 self.directory.mark_presence_requested(&wanted, now);
352 drop(data::watch_presence(&engine, wanted.clone()));
353 let done = data::refresh_presence(&engine, wanted.clone());
354 self.on_done(done, cx, move |state, cx| {
355 state.sync_presence();
356 state.directory.save_presence(&state.store, &wanted);
357 state.directory.settle_presence(&wanted);
358 cx.emit(AppEvent::Directory);
359 cx.notify();
360 });
361 }
362 }
363
364 pub fn move_chat(
365 &mut self,
366 conversation_id: &str,
367 folder_id: Option<&str>,
368 cx: &mut Context<Self>,
369 ) {
370 if self.mode.read_only {
371 return;
372 }
373 let previous_folder = self
374 .directory
375 .folder_of(conversation_id)
376 .map(|folder| folder.id.clone());
377 self.directory.assign(conversation_id, folder_id);
378 if let Some(engine) = self.engine.clone() {
379 let previous = previous_folder.clone();
380 let done = match (folder_id, previous.as_deref()) {
381 (Some(folder_id), _) => {
382 Some(data::move_to_folder(&engine, conversation_id, folder_id))
383 }
384 (None, Some(previous)) => {
385 Some(data::remove_from_folder(&engine, conversation_id, previous))
386 }
387 (None, None) => None,
388 };
389 if let Some(done) = done {
390 self.on_done(done, cx, |state, cx| {
391 state.reload_directory();
392 cx.emit(AppEvent::Sidebar);
393 cx.notify();
394 });
395 }
396 }
397 cx.emit(AppEvent::Sidebar);
398 cx.notify();
399 }
400
401 pub fn pin_chat(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
402 let favorites = self.directory.favorites().map(|folder| folder.id.clone());
403 self.move_chat(conversation_id, favorites.as_deref(), cx);
404 }
405
406 pub fn mark_chat_read(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
407 if self.keeps_unread(conversation_id) {
408 self.keep_unread = None;
409 }
410 if self.mode.demo {
411 if let Some(chat) = self
412 .sidebar
413 .chats
414 .iter()
415 .find(|chat| chat.id == conversation_id)
416 {
417 let mut read = chat.clone();
418 read.unread = false;
419 let _ = self.store.upsert_chats(&[read]);
420 self.reload_sidebar(cx);
421 }
422 return;
423 }
424 if self.mode.read_only {
425 return;
426 }
427 if let Some(engine) = self.engine.clone() {
428 let _ = self
429 .store
430 .mark_chat_read(conversation_id, chrono::Utc::now());
431 self.reload_sidebar(cx);
432 let conversation_id = conversation_id.to_owned();
433 drop(crate::runtime::spawn(async move {
434 engine.mark_read(&conversation_id).await
435 }));
436 }
437 }
438
439 pub fn start_new_chat(&mut self, cx: &mut Context<Self>) {
440 self.new_chat = true;
441 cx.emit(AppEvent::Selection);
442 cx.notify();
443 }
444
445 pub fn close_new_chat(&mut self, cx: &mut Context<Self>) {
446 if !self.new_chat {
447 return;
448 }
449 self.new_chat = false;
450 cx.emit(AppEvent::Selection);
451 cx.notify();
452 }
453
454 pub fn select(&mut self, selection: Selection, cx: &mut Context<Self>) {
455 let was_drafting = std::mem::take(&mut self.new_chat);
456 if !was_drafting && self.selection.as_ref() == Some(&selection) {
457 return;
458 }
459 self.selection = Some(selection);
460 self.keep_unread = None;
461 cx.emit(AppEvent::Selection);
462 cx.notify();
463 }
464
465 fn apply_typing(&mut self, event: TypingEvent, cx: &mut Context<Self>) {
466 let is_me = self
467 .directory
468 .me
469 .as_ref()
470 .is_some_and(|me| me.user_id == event.user_id);
471 if is_me {
472 return;
473 }
474 if event.active {
475 let display_name = match event.display_name.trim() {
476 "" => crate::people::resolve_names(self, std::slice::from_ref(&event.user_id))
477 .remove(&event.user_id)
478 .unwrap_or_default(),
479 _ => event.display_name.clone(),
480 };
481 self.typing.start(
482 &event.conversation_id,
483 &event.user_id,
484 &display_name,
485 Instant::now(),
486 event.received_at,
487 );
488 self.request_avatars(vec![event.user_id.clone()], cx);
489 self.schedule_typing_expiry(cx);
490 } else {
491 self.typing.clear(&event.conversation_id, &event.user_id);
492 }
493 cx.emit(AppEvent::Typing);
494 cx.notify();
495 }
496
497 fn clear_typists_who_sent(&mut self, conversation_id: &str, cx: &mut Context<Self>) {
498 if !self.typing.is_active(conversation_id) {
499 return;
500 }
501 let Ok(recent) = self
502 .store
503 .messages(conversation_id, None, RECENT_MESSAGES_FOR_TYPING)
504 else {
505 return;
506 };
507 let mut changed = false;
508 for message in recent {
509 if let Some(sender_id) = message.sender_id.as_deref() {
510 changed |= self
511 .typing
512 .message_from(conversation_id, sender_id, message.created_at);
513 }
514 }
515 if changed {
516 cx.emit(AppEvent::Typing);
517 cx.notify();
518 }
519 }
520
521 fn schedule_typing_expiry(&mut self, cx: &mut Context<Self>) {
522 if self.typing_timer_running {
523 return;
524 }
525 self.typing_timer_running = true;
526 cx.spawn(async move |this, cx| {
527 loop {
528 let next = this.update(cx, |state, _| {
529 let next = state.typing.next_expiry();
530 state.typing_timer_running = next.is_some();
531 next
532 });
533 let Ok(Some(next)) = next else { return };
534 cx.background_executor()
535 .timer(next.saturating_duration_since(Instant::now()))
536 .await;
537 let alive = this.update(cx, |state, cx| {
538 if state.typing.expire(Instant::now()) {
539 cx.emit(AppEvent::Typing);
540 cx.notify();
541 }
542 });
543 if alive.is_err() {
544 return;
545 }
546 }
547 })
548 .detach();
549 }
550
551 pub fn reload_sidebar(&mut self, cx: &mut Context<Self>) {
552 if let Ok(sidebar) = self.store.sidebar() {
553 self.sidebar = sidebar;
554 self.apply_bot_titles();
555 }
556 if !self.mode.demo {
557 self.reload_directory();
558 }
559 cx.emit(AppEvent::Sidebar);
560 cx.notify();
561 }
562
563 pub fn apply(&mut self, event: BackendEvent, cx: &mut Context<Self>) {
564 match event {
565 BackendEvent::Connection(connection) => {
566 self.connection = connection;
567 cx.emit(AppEvent::Status);
568 }
569 BackendEvent::Engine(engine) => {
570 self.engine = Some(engine);
571 self.resend_outbox(cx);
572 self.refresh_scheduled(cx);
573 let waiting = self.directory.waiting_presence_ids();
574 self.request_presence(waiting, cx);
575 cx.emit(AppEvent::Status);
576 }
577 BackendEvent::Core(CoreEvent::SidebarChanged) => self.reload_sidebar(cx),
578 BackendEvent::Core(
579 CoreEvent::MessagesChanged { conversation_id }
580 | CoreEvent::ReceiptsChanged { conversation_id },
581 ) => {
582 self.clear_typists_who_sent(&conversation_id, cx);
583 cx.emit(AppEvent::Messages(conversation_id));
584 }
585 BackendEvent::Core(CoreEvent::ImagesChanged { keys }) => {
586 if let Some(engine) = &self.engine {
587 for key in &keys {
588 let image = ImageRef {
589 id: String::new(),
590 url: key.clone(),
591 width: None,
592 height: None,
593 };
594 if let Some(path) = engine.image_path(&image) {
595 self.directory.set_image(key, &path);
596 }
597 }
598 }
599 cx.emit(AppEvent::Images(keys));
600 }
601 BackendEvent::Core(CoreEvent::PresenceChanged) => {
602 let changed = self.sync_presence();
603 self.directory.save_presence(&self.store, &changed);
604 cx.emit(AppEvent::Directory);
605 cx.notify();
606 }
607 BackendEvent::Core(_) => {
608 if !self.mode.demo {
609 self.reload_directory();
610 }
611 cx.emit(AppEvent::Directory);
612 }
613 BackendEvent::Typing(event) => self.apply_typing(event, cx),
614 BackendEvent::Live(live) => {
615 self.live = live;
616 cx.emit(AppEvent::Status);
617 }
618 BackendEvent::Favorites(ids) => {
619 self.favorite_ids = ids;
620 if !self.mode.demo {
621 self.reload_directory();
622 }
623 cx.emit(AppEvent::Sidebar);
624 }
625 BackendEvent::Synced(time) => {
626 self.last_sync = Some(time);
627 cx.emit(AppEvent::Status);
628 }
629 }
630 cx.notify();
631 }
632}
633
634#[cfg(test)]
635mod tests {
636 use std::sync::Arc;
637
638 use chatsvc::TypingEvent;
639 use chrono::{Duration, Utc};
640 use gpui_kit::{AppContext as _, TestAppContext};
641 use store::{
642 ChannelRecord, ChatRecord, MemberRecord, MessageRecord, SidebarTeam, Store, TeamRecord,
643 };
644 use teams_core::CoreEvent;
645
646 use super::{AppState, Mode, Selection, chat_title, selection_title};
647 use crate::backend::BackendEvent;
648 use crate::data::Person;
649 use store::Sidebar;
650
651 fn chat(id: &str, title: &str, unread: bool) -> ChatRecord {
652 ChatRecord {
653 id: id.into(),
654 kind: "group".into(),
655 title: title.into(),
656 member_summary: "Member".into(),
657 last_message_at: None,
658 last_read_at: None,
659 unread,
660 ..Default::default()
661 }
662 }
663
664 fn sidebar() -> Sidebar {
665 Sidebar {
666 chats: vec![chat("c1", "First", true), chat("c2", "", false)],
667 teams: vec![SidebarTeam {
668 team: TeamRecord {
669 id: "t".into(),
670 name: "Team".into(),
671 },
672 channels: vec![ChannelRecord {
673 id: "ch".into(),
674 team_id: "t".into(),
675 name: "General".into(),
676 membership_type: None,
677 last_message_at: None,
678 unread: false,
679 }],
680 hidden: false,
681 hidden_channel_ids: Vec::new(),
682 }],
683 }
684 }
685
686 #[test]
687 fn empty_chat_title_falls_back_to_members() {
688 assert_eq!(chat_title(&sidebar().chats[1]), "Member");
689 }
690
691 #[test]
692 fn selection_titles() {
693 assert_eq!(
694 selection_title(&sidebar(), &Selection::Channel("ch".into())),
695 "Team / General"
696 );
697 assert_eq!(
698 selection_title(&sidebar(), &Selection::Chat("c1".into())),
699 "First"
700 );
701 }
702
703 fn typing_event(user_id: &str, active: bool) -> BackendEvent {
704 BackendEvent::Typing(TypingEvent {
705 conversation_id: "c1".into(),
706 user_id: user_id.into(),
707 display_name: format!("Name {user_id}"),
708 active,
709 received_at: Utc::now(),
710 })
711 }
712
713 #[gpui_kit::test]
714 fn typing_events_track_other_users_and_ignore_me(cx: &mut TestAppContext) {
715 cx.update(gpui_kit::init);
716 let store = Arc::new(Store::open_in_memory().unwrap());
717 let app = cx.update(|cx| {
718 cx.new(|_| {
719 let mut state = AppState::new(store.clone(), Mode::default());
720 state.directory.me = Some(Person {
721 user_id: "me".into(),
722 display_name: "Me".into(),
723 });
724 state
725 })
726 });
727 let names = |cx: &mut TestAppContext| cx.update(|cx| app.read(cx).typing.names("c1"));
728 cx.update(|cx| {
729 app.update(cx, |state, cx| {
730 state.apply(typing_event("me", true), cx);
731 state.apply(typing_event("ada", true), cx);
732 })
733 });
734 assert_eq!(names(cx), vec!["Name ada".to_owned()]);
735
736 let message = MessageRecord {
737 conversation_id: "c1".into(),
738 message_id: "m1".into(),
739 sender_id: Some("ada".into()),
740 created_at: Utc::now() + Duration::seconds(1),
741 ..Default::default()
742 };
743 store.upsert_messages(&[message]).unwrap();
744 cx.update(|cx| {
745 app.update(cx, |state, cx| {
746 state.apply(
747 BackendEvent::Core(CoreEvent::MessagesChanged {
748 conversation_id: "c1".into(),
749 }),
750 cx,
751 )
752 })
753 });
754 assert!(names(cx).is_empty());
755
756 cx.update(|cx| {
757 app.update(cx, |state, cx| {
758 state.apply(typing_event("ada", true), cx);
759 state.apply(typing_event("ada", false), cx);
760 })
761 });
762 assert!(names(cx).is_empty());
763 }
764
765 #[gpui_kit::test]
766 fn typing_without_a_display_name_uses_the_chat_member_name(cx: &mut TestAppContext) {
767 cx.update(gpui_kit::init);
768 let store = Arc::new(Store::open_in_memory().unwrap());
769 let app = cx.update(|cx| {
770 cx.new(|_| {
771 let mut state = AppState::new(store.clone(), Mode::default());
772 let mut member_chat = chat("c1", "First", false);
773 member_chat.members = vec![MemberRecord {
774 user_id: Some("ada".into()),
775 display_name: "Ada Lovelace".into(),
776 }];
777 state.sidebar.chats = vec![member_chat];
778 state
779 })
780 });
781 cx.update(|cx| {
782 app.update(cx, |state, cx| {
783 state.apply(
784 BackendEvent::Typing(TypingEvent {
785 conversation_id: "c1".into(),
786 user_id: "ada".into(),
787 display_name: String::new(),
788 active: true,
789 received_at: Utc::now(),
790 }),
791 cx,
792 )
793 })
794 });
795 assert_eq!(
796 cx.update(|cx| app.read(cx).typing.names("c1")),
797 vec!["Ada Lovelace".to_owned()]
798 );
799 }
800}