BlueGit

ict rusty-teams

Files

rusty-teams / crates / core / src / folders.rs

folders.rs

folders.rs 23.5 KiB Download Raw
1use std::collections::HashMap;
2use std::future::Future;
3use std::pin::Pin;
4use std::sync::{Arc, Mutex};
5
6use chatsvc::settings::{parse_chat_sections, parse_skin_tone, parse_teams_order};
7use chatsvc::{
8 ChannelNotificationLevel, ChannelNotifications, ChannelSettings, ChatSection,
9 ChatSectionSettings, Pins, UserSettings, pins::SessionTransport,
10};
11use chrono::Utc;
12use serde_json::Value;
13use session::Session;
14use store::{ChannelLayoutRecord, ChannelTabRecord, FolderRecord, Store, TeamLayoutRecord};
15
16use crate::engine::SyncEngine;
17use crate::error::{Error, Result};
18use crate::events::CoreEvent;
19use crate::remote::Remote;
20
21pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
22
23#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24pub enum FolderKind {
25 Favorites,
26 UserCreated,
27 Recent,
28 Meeting,
29 Muted,
30}
31
32#[derive(Debug, Clone, PartialEq, Eq)]
33pub struct ChatFolder {
34 pub id: String,
35 pub name: String,
36 pub kind: FolderKind,
37 pub expanded: bool,
38 pub conversation_ids: Vec<String>,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub enum FolderChange {
43 Create {
44 name: String,
45 },
46 Rename {
47 folder_id: String,
48 name: String,
49 },
50 Delete {
51 folder_id: String,
52 },
53 Move {
54 folder_id: String,
55 target_folder_id: String,
56 },
57}
58
59pub trait FolderSource: Send + Sync {
60 fn folders(&self) -> BoxFuture<'_, Result<Vec<ChatFolder>>>;
61 fn pinned_channels(&self) -> BoxFuture<'_, Result<Vec<String>>>;
62 fn team_layout(&self) -> BoxFuture<'_, Result<Vec<TeamLayoutRecord>>>;
63 fn section_settings(&self) -> BoxFuture<'_, Result<ChatSectionSettings>>;
64 fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {
65 Box::pin(async { Ok(Vec::new()) })
66 }
67 fn preferred_skin_tone(&self) -> Option<u8> {
68 None
69 }
70 fn set_skin_tone(&self, _tone: u8) -> BoxFuture<'_, Result<()>> {
71 Box::pin(async { Ok(()) })
72 }
73 fn set_section_enabled(&self, section: ChatSection, enabled: bool)
74 -> BoxFuture<'_, Result<()>>;
75 fn set_folder_expanded<'a>(
76 &'a self,
77 folder_id: &'a str,
78 expanded: bool,
79 ) -> BoxFuture<'a, Result<()>>;
80 fn move_to_folder<'a>(
81 &'a self,
82 conversation_id: &'a str,
83 target_folder_id: &'a str,
84 ) -> BoxFuture<'a, Result<Vec<ChatFolder>>>;
85 fn remove_from_folder<'a>(
86 &'a self,
87 conversation_id: &'a str,
88 folder_id: &'a str,
89 ) -> BoxFuture<'a, Result<Vec<ChatFolder>>>;
90 fn change_folders(&self, change: FolderChange) -> BoxFuture<'_, Result<Vec<ChatFolder>>>;
91}
92
93pub struct ChatsvcFolderSource {
94 pins: Pins<SessionTransport>,
95 settings: UserSettings,
96 channel_settings: ChannelSettings,
97 properties: Mutex<Option<Value>>,
98 skin_tone: Mutex<Option<u8>>,
99 group_ids: Mutex<HashMap<String, String>>,
100}
101
102impl ChatsvcFolderSource {
103 pub fn new(session: &Session) -> Self {
104 ChatsvcFolderSource {
105 pins: Pins::new(session),
106 settings: UserSettings::new(session),
107 channel_settings: ChannelSettings::new(session),
108 properties: Mutex::new(None),
109 skin_tone: Mutex::new(None),
110 group_ids: Mutex::new(HashMap::new()),
111 }
112 }
113}
114
115impl FolderSource for ChatsvcFolderSource {
116 fn folders(&self) -> BoxFuture<'_, Result<Vec<ChatFolder>>> {
117 Box::pin(async { Ok(convert(self.pins.folders().await?)) })
118 }
119
120 fn pinned_channels(&self) -> BoxFuture<'_, Result<Vec<String>>> {
121 Box::pin(async { Ok(self.pins.pinned_channels().await?.channel_ids) })
122 }
123
124 fn team_layout(&self) -> BoxFuture<'_, Result<Vec<TeamLayoutRecord>>> {
125 Box::pin(async {
126 let layout = self.pins.team_layout().await?;
127 *self.group_ids.lock().unwrap() = group_ids_by_thread(&layout);
128 let unknown: Vec<String> = layout
129 .iter()
130 .flat_map(|team| &team.channels)
131 .filter(|channel| channel.notifications.is_none())
132 .map(|channel| channel.channel_id.clone())
133 .collect();
134 let fallback = if unknown.is_empty() {
135 HashMap::new()
136 } else {
137 self.channel_settings
138 .fetch(&unknown)
139 .await
140 .unwrap_or_default()
141 };
142 Ok(layout
143 .into_iter()
144 .map(|team| layout_record(team, &fallback))
145 .collect())
146 })
147 }
148
149 fn section_settings(&self) -> BoxFuture<'_, Result<ChatSectionSettings>> {
150 Box::pin(async {
151 let properties = self.settings.properties().await?;
152 let sections = parse_chat_sections(&properties);
153 *self.skin_tone.lock().unwrap() = parse_skin_tone(&properties);
154 *self.properties.lock().unwrap() = Some(properties);
155 Ok(sections)
156 })
157 }
158
159 fn preferred_skin_tone(&self) -> Option<u8> {
160 *self.skin_tone.lock().unwrap()
161 }
162
163 fn set_skin_tone(&self, tone: u8) -> BoxFuture<'_, Result<()>> {
164 Box::pin(async move { Ok(self.settings.set_skin_tone(tone).await?) })
165 }
166
167 fn teams_order(&self) -> BoxFuture<'_, Result<Vec<(String, i64)>>> {
168 Box::pin(async {
169 let cached = self.properties.lock().unwrap().take();
170 let properties = match cached {
171 Some(properties) => properties,
172 None => self.settings.properties().await?,
173 };
174 let known = self.group_ids.lock().unwrap().clone();
175 let group_ids = if known.is_empty() {
176 group_ids_by_thread(&self.pins.team_layout().await?)
177 } else {
178 known
179 };
180 Ok(order_by_group_id(
181 parse_teams_order(&properties),
182 &group_ids,
183 ))
184 })
185 }
186
187 fn set_section_enabled(
188 &self,
189 section: ChatSection,
190 enabled: bool,
191 ) -> BoxFuture<'_, Result<()>> {
192 Box::pin(async move { Ok(self.settings.set_chat_section(section, enabled).await?) })
193 }
194
195 fn set_folder_expanded<'a>(
196 &'a self,
197 folder_id: &'a str,
198 expanded: bool,
199 ) -> BoxFuture<'a, Result<()>> {
200 Box::pin(async move { Ok(self.pins.set_folder_expanded(folder_id, expanded).await?) })
201 }
202
203 fn move_to_folder<'a>(
204 &'a self,
205 conversation_id: &'a str,
206 target_folder_id: &'a str,
207 ) -> BoxFuture<'a, Result<Vec<ChatFolder>>> {
208 Box::pin(async move {
209 Ok(convert(
210 self.pins
211 .move_to_folder(conversation_id, target_folder_id)
212 .await?,
213 ))
214 })
215 }
216
217 fn remove_from_folder<'a>(
218 &'a self,
219 conversation_id: &'a str,
220 folder_id: &'a str,
221 ) -> BoxFuture<'a, Result<Vec<ChatFolder>>> {
222 Box::pin(async move {
223 Ok(convert(
224 self.pins
225 .remove_from_folder(conversation_id, folder_id)
226 .await?,
227 ))
228 })
229 }
230
231 fn change_folders(&self, change: FolderChange) -> BoxFuture<'_, Result<Vec<ChatFolder>>> {
232 Box::pin(async move {
233 let folders = match &change {
234 FolderChange::Create { name } => self.pins.create_folder(name).await?,
235 FolderChange::Rename { folder_id, name } => {
236 self.pins.rename_folder(folder_id, name).await?
237 }
238 FolderChange::Delete { folder_id } => self.pins.delete_folder(folder_id).await?,
239 FolderChange::Move {
240 folder_id,
241 target_folder_id,
242 } => self.pins.move_folder(folder_id, target_folder_id).await?,
243 };
244 Ok(convert(folders))
245 })
246 }
247}
248
249fn convert(folders: chatsvc::Folders) -> Vec<ChatFolder> {
250 folders
251 .folders
252 .into_iter()
253 .map(|folder| ChatFolder {
254 id: folder.id,
255 name: folder.name,
256 kind: match folder.kind {
257 chatsvc::FolderKind::Favorites => FolderKind::Favorites,
258 chatsvc::FolderKind::UserCreated => FolderKind::UserCreated,
259 chatsvc::FolderKind::Recent => FolderKind::Recent,
260 chatsvc::FolderKind::Meeting => FolderKind::Meeting,
261 chatsvc::FolderKind::Muted => FolderKind::Muted,
262 },
263 expanded: folder.expanded,
264 conversation_ids: folder.conversation_ids,
265 })
266 .collect()
267}
268
269fn stored_team_order(teams: &[store::SidebarTeam]) -> Vec<(String, i64)> {
270 teams
271 .iter()
272 .enumerate()
273 .map(|(position, team)| (team.team.id.clone(), position as i64))
274 .collect()
275}
276
277fn group_ids_by_thread(layout: &[chatsvc::TeamLayout]) -> HashMap<String, String> {
278 layout
279 .iter()
280 .filter_map(|team| Some((team.team_id.clone(), team.group_id.clone()?)))
281 .collect()
282}
283
284fn order_by_group_id(
285 order: Vec<(String, i64)>,
286 group_ids: &HashMap<String, String>,
287) -> Vec<(String, i64)> {
288 order
289 .into_iter()
290 .map(|(team_id, position)| match group_ids.get(&team_id) {
291 Some(group_id) => (group_id.clone(), position),
292 None => (team_id, position),
293 })
294 .collect()
295}
296
297fn sort_teams_by_order(teams: &mut [TeamLayoutRecord], order: &[(String, i64)]) {
298 let positions: HashMap<&str, i64> = order
299 .iter()
300 .map(|(team_id, position)| (team_id.as_str(), *position))
301 .collect();
302 teams.sort_by_key(|team| {
303 positions
304 .get(team.team_id.as_str())
305 .copied()
306 .unwrap_or(i64::MAX)
307 });
308}
309
310fn resolve_notifications(
311 channel: &chatsvc::ChannelLayout,
312 fallback: &HashMap<String, ChannelNotifications>,
313) -> ChannelNotifications {
314 channel
315 .notifications
316 .or_else(|| fallback.get(&channel.channel_id).copied())
317 .unwrap_or_else(|| ChannelNotifications::from_followed(channel.followed))
318}
319
320fn notification_record(notifications: ChannelNotifications) -> store::ChannelNotifications {
321 store::ChannelNotifications {
322 level: match notifications.level {
323 ChannelNotificationLevel::BannerAndFeed => {
324 store::ChannelNotificationLevel::BannerAndFeed
325 }
326 ChannelNotificationLevel::Feed => store::ChannelNotificationLevel::Feed,
327 ChannelNotificationLevel::Off => store::ChannelNotificationLevel::Off,
328 },
329 include_replies: notifications.include_replies,
330 }
331}
332
333pub(crate) fn chatsvc_notifications(
334 notifications: store::ChannelNotifications,
335) -> ChannelNotifications {
336 ChannelNotifications {
337 level: match notifications.level {
338 store::ChannelNotificationLevel::BannerAndFeed => {
339 ChannelNotificationLevel::BannerAndFeed
340 }
341 store::ChannelNotificationLevel::Feed => ChannelNotificationLevel::Feed,
342 store::ChannelNotificationLevel::Off => ChannelNotificationLevel::Off,
343 },
344 include_replies: notifications.include_replies,
345 }
346}
347
348fn layout_record(
349 team: chatsvc::TeamLayout,
350 fallback: &HashMap<String, ChannelNotifications>,
351) -> TeamLayoutRecord {
352 TeamLayoutRecord {
353 team_id: team.group_id.unwrap_or(team.team_id),
354 hidden: team.hidden,
355 channels: team
356 .channels
357 .into_iter()
358 .map(|channel| ChannelLayoutRecord {
359 notifications: notification_record(resolve_notifications(&channel, fallback)),
360 channel_id: channel.channel_id,
361 general: channel.general,
362 hidden: channel.hidden,
363 tabs: channel
364 .tabs
365 .into_iter()
366 .map(|tab| ChannelTabRecord {
367 tab_id: tab.id,
368 name: tab.name,
369 definition_id: tab.definition_id,
370 open_url: tab.open_url,
371 })
372 .collect(),
373 })
374 .collect(),
375 }
376}
377
378const META_TEAM_LAYOUT_AT: &str = "team_layout_refreshed_at";
379const KIND_FAVORITES: &str = "Favorites";
380const KIND_USER_CREATED: &str = "UserCreated";
381const KIND_RECENT: &str = "RecentChats";
382const KIND_MEETING: &str = "MeetingChats";
383const KIND_MUTED: &str = "MutedChats";
384const META_MUTED_SECTION: &str = "chat_section_muted";
385const META_MEETING_SECTION: &str = "chat_section_meeting";
386
387fn to_record(folder: &ChatFolder) -> FolderRecord {
388 FolderRecord {
389 id: folder.id.clone(),
390 name: folder.name.clone(),
391 kind: match folder.kind {
392 FolderKind::Favorites => KIND_FAVORITES,
393 FolderKind::UserCreated => KIND_USER_CREATED,
394 FolderKind::Recent => KIND_RECENT,
395 FolderKind::Meeting => KIND_MEETING,
396 FolderKind::Muted => KIND_MUTED,
397 }
398 .to_owned(),
399 expanded: folder.expanded,
400 conversation_ids: folder.conversation_ids.clone(),
401 }
402}
403
404fn from_record(record: FolderRecord) -> ChatFolder {
405 ChatFolder {
406 id: record.id,
407 name: record.name,
408 kind: match record.kind.as_str() {
409 KIND_FAVORITES => FolderKind::Favorites,
410 KIND_RECENT => FolderKind::Recent,
411 KIND_MEETING => FolderKind::Meeting,
412 KIND_MUTED => FolderKind::Muted,
413 _ => FolderKind::UserCreated,
414 },
415 expanded: record.expanded,
416 conversation_ids: record.conversation_ids,
417 }
418}
419
420pub fn stored_section_settings(store: &Store) -> ChatSectionSettings {
421 let read = |key: &str| {
422 store
423 .meta(key)
424 .ok()
425 .flatten()
426 .and_then(|value| value.parse().ok())
427 };
428 ChatSectionSettings {
429 muted: read(META_MUTED_SECTION),
430 meeting: read(META_MEETING_SECTION),
431 }
432}
433
434pub fn store_section_settings(store: &Store, settings: &ChatSectionSettings) -> Result<()> {
435 for (key, value) in [
436 (META_MUTED_SECTION, settings.muted),
437 (META_MEETING_SECTION, settings.meeting),
438 ] {
439 let text = value.map(|enabled| enabled.to_string()).unwrap_or_default();
440 store.set_meta(key, &text)?;
441 }
442 Ok(())
443}
444
445impl<R: Remote> SyncEngine<R> {
446 pub fn with_folder_source(mut self, source: Arc<dyn FolderSource>) -> Self {
447 self.folder_source = Some(source);
448 self
449 }
450
451 pub fn chat_folders(&self) -> Result<Vec<ChatFolder>> {
452 Ok(self.store.folders()?.into_iter().map(from_record).collect())
453 }
454
455 pub fn pinned_channels(&self) -> Result<Vec<String>> {
456 Ok(self.store.pinned_channel_ids()?)
457 }
458
459 pub async fn refresh_folders(&self) -> Result<()> {
460 let source = self.folder_source()?;
461 let folders = match tokio::try_join!(source.folders(), source.pinned_channels()) {
462 Ok((folders, channels)) => self.store_folders(&folders, &channels),
463 Err(error) => Err(error),
464 };
465 self.refresh_section_settings(source).await;
466 let layout = self.refresh_team_layout(source).await;
467 match (folders, layout) {
468 (Err(folders_error), Err(layout_error)) => {
469 Err(Error::Folders(format!("{folders_error}; {layout_error}")))
470 }
471 (Err(error), Ok(())) | (Ok(()), Err(error)) => Err(error),
472 (Ok(()), Ok(())) => Ok(()),
473 }
474 }
475
476 async fn refresh_section_settings(&self, source: &Arc<dyn FolderSource>) {
477 let outcome = match source.section_settings().await {
478 Ok(settings) => self.apply_section_settings(&settings).and_then(|()| {
479 match source.preferred_skin_tone() {
480 Some(tone) => crate::skin_tone::store_account_skin_tone(&self.store, tone),
481 None => Ok(()),
482 }
483 }),
484 Err(error) => Err(error),
485 };
486 if let Err(error) = outcome {
487 self.report(format!("cannot refresh chat list settings: {error}"));
488 }
489 }
490
491 fn apply_section_settings(&self, settings: &ChatSectionSettings) -> Result<()> {
492 if stored_section_settings(&self.store) != *settings {
493 store_section_settings(&self.store, settings)?;
494 let _ = self.events.send(CoreEvent::FoldersChanged);
495 }
496 Ok(())
497 }
498
499 pub async fn set_section_enabled(&self, section: ChatSection, enabled: bool) -> Result<()> {
500 self.folder_source()?
501 .set_section_enabled(section, enabled)
502 .await
503 }
504
505 pub async fn set_skin_tone(&self, tone: u8) -> Result<()> {
506 self.folder_source()?.set_skin_tone(tone).await?;
507 crate::skin_tone::store_account_skin_tone(&self.store, tone)
508 }
509
510 pub async fn set_folder_expanded(&self, folder_id: &str, expanded: bool) -> Result<()> {
511 self.folder_source()?
512 .set_folder_expanded(folder_id, expanded)
513 .await
514 }
515
516 async fn refresh_team_layout(&self, source: &Arc<dyn FolderSource>) -> Result<()> {
517 let last = self.store.meta_time(META_TEAM_LAYOUT_AT)?;
518 if last.is_some_and(|last| Utc::now() - last < self.config.team_layout_refresh_interval) {
519 return Ok(());
520 }
521 let mut layout = source.team_layout().await?;
522 let before = self.store.sidebar()?.teams;
523 let order = match source.teams_order().await {
524 Ok(order) => order,
525 Err(error) => {
526 self.report(format!("cannot read the team order: {error}"));
527 stored_team_order(&before)
528 }
529 };
530 sort_teams_by_order(&mut layout, &order);
531 self.store.replace_team_layout(&layout)?;
532 self.store.set_meta_time(META_TEAM_LAYOUT_AT, Utc::now())?;
533 if self.store.sidebar()?.teams != before {
534 let _ = self.events.send(CoreEvent::SidebarChanged);
535 }
536 Ok(())
537 }
538
539 pub async fn move_to_folder(
540 &self,
541 conversation_id: &str,
542 target_folder_id: &str,
543 ) -> Result<()> {
544 let folders = self
545 .folder_source()?
546 .move_to_folder(conversation_id, target_folder_id)
547 .await?;
548 self.store_folders(&folders, &self.store.pinned_channel_ids()?)
549 }
550
551 pub async fn remove_from_folder(&self, conversation_id: &str, folder_id: &str) -> Result<()> {
552 let folders = self
553 .folder_source()?
554 .remove_from_folder(conversation_id, folder_id)
555 .await?;
556 self.store_folders(&folders, &self.store.pinned_channel_ids()?)
557 }
558
559 pub async fn change_folders(&self, change: FolderChange) -> Result<()> {
560 let folders = self.folder_source()?.change_folders(change).await?;
561 self.store_folders(&folders, &self.store.pinned_channel_ids()?)
562 }
563
564 fn folder_source(&self) -> Result<&Arc<dyn FolderSource>> {
565 self.folder_source
566 .as_ref()
567 .ok_or(Error::Unsupported("chat folders without a folder source"))
568 }
569
570 fn store_folders(&self, folders: &[ChatFolder], channel_ids: &[String]) -> Result<()> {
571 let previous = (self.chat_folders()?, self.store.pinned_channel_ids()?);
572 let records: Vec<FolderRecord> = folders.iter().map(to_record).collect();
573 self.store.replace_folders(&records, channel_ids)?;
574 if previous != (folders.to_vec(), channel_ids.to_vec()) {
575 let _ = self.events.send(CoreEvent::FoldersChanged);
576 }
577 Ok(())
578 }
579}
580
581#[cfg(test)]
582mod tests {
583 use super::*;
584
585 fn channel(
586 notifications: Option<ChannelNotifications>,
587 followed: bool,
588 ) -> chatsvc::ChannelLayout {
589 chatsvc::ChannelLayout {
590 channel_id: "19:a".into(),
591 general: false,
592 hidden: false,
593 tabs: Vec::new(),
594 notifications,
595 followed,
596 }
597 }
598
599 fn level(level: ChannelNotificationLevel, include_replies: bool) -> ChannelNotifications {
600 ChannelNotifications {
601 level,
602 include_replies,
603 }
604 }
605
606 fn team(team_id: &str) -> TeamLayoutRecord {
607 TeamLayoutRecord {
608 team_id: team_id.into(),
609 hidden: false,
610 channels: Vec::new(),
611 }
612 }
613
614 fn team_ids(teams: &[TeamLayoutRecord]) -> Vec<&str> {
615 teams.iter().map(|team| team.team_id.as_str()).collect()
616 }
617
618 #[test]
619 fn listed_teams_come_first_by_order_and_unlisted_follow_in_server_order() {
620 let mut teams = vec![team("x"), team("b"), team("y"), team("a"), team("z")];
621 let order = vec![
622 ("a".to_owned(), 0),
623 ("b".to_owned(), 1),
624 ("gone".to_owned(), 2),
625 ];
626 sort_teams_by_order(&mut teams, &order);
627 assert_eq!(team_ids(&teams), ["a", "b", "x", "y", "z"]);
628 }
629
630 #[test]
631 fn real_payloads_give_the_team_order_teams_web_shows() {
632 let fixture: Value =
633 serde_json::from_str(include_str!("../tests/fixtures/team_order.json")).unwrap();
634 let layout = chatsvc::pins::parse_team_layout(&fixture["csaTeams"]).unwrap();
635 let group_ids = group_ids_by_thread(&layout);
636 let order = order_by_group_id(parse_teams_order(&fixture["userProperties"]), &group_ids);
637 let mut records: Vec<TeamLayoutRecord> = layout
638 .into_iter()
639 .map(|team| layout_record(team, &HashMap::new()))
640 .collect();
641 sort_teams_by_order(&mut records, &order);
642 let store = Store::open_in_memory().unwrap();
643 let names: HashMap<String, String> = fixture["csaTeams"]["teams"]
644 .as_array()
645 .unwrap()
646 .iter()
647 .map(|team| {
648 let group_id = team["teamSiteInformation"]["groupId"].as_str().unwrap();
649 let name = team["displayName"].as_str().unwrap();
650 (group_id.to_owned(), name.to_owned())
651 })
652 .collect();
653 let graph_teams: Vec<store::TeamRecord> = names
654 .iter()
655 .map(|(group_id, name)| store::TeamRecord {
656 id: group_id.clone(),
657 name: name.clone(),
658 })
659 .collect();
660 store.upsert_teams(&graph_teams).unwrap();
661 store.replace_team_layout(&records).unwrap();
662
663 let shown: Vec<String> = store
664 .sidebar()
665 .unwrap()
666 .teams
667 .into_iter()
668 .filter(|team| !team.hidden)
669 .map(|team| team.team.id)
670 .collect();
671 let expected: Vec<String> = fixture["teamsWebShownTeams"]
672 .as_array()
673 .unwrap()
674 .iter()
675 .map(|team| team["groupId"].as_str().unwrap().to_owned())
676 .collect();
677 assert_eq!(shown, expected);
678 }
679
680 #[test]
681 fn an_empty_order_keeps_the_server_order() {
682 let mut teams = vec![team("c"), team("a"), team("b")];
683 sort_teams_by_order(&mut teams, &[]);
684 assert_eq!(team_ids(&teams), ["c", "a", "b"]);
685 }
686
687 #[test]
688 fn channel_value_beats_the_notification_service_beats_the_followed_flag() {
689 let off = level(ChannelNotificationLevel::Off, false);
690 let banner = level(ChannelNotificationLevel::BannerAndFeed, true);
691 let fallback = HashMap::from([("19:a".to_owned(), banner)]);
692 assert_eq!(
693 resolve_notifications(&channel(Some(off), true), &fallback),
694 off
695 );
696 assert_eq!(
697 resolve_notifications(&channel(None, false), &fallback),
698 banner
699 );
700 assert_eq!(
701 resolve_notifications(&channel(None, true), &HashMap::new()),
702 banner
703 );
704 assert_eq!(
705 resolve_notifications(&channel(None, false), &HashMap::new()),
706 ChannelNotifications::default()
707 );
708 }
709}