Commit 9a1adfb287

9a1adfb287ecc5ff6b97b2760d4ab5e480835dc5

parent: cb4455655f

Unregistered key

Andrew Collins <andyc1367@gmail.com> · 2024-08-01 03:37 UTC
committer: <noreply@github.com>

Allow notifications on open room if terminal not focused (#281)

Layout: unified · split

src/base.rs +4
@@ -1319,6 +1319,9 @@ pub struct ChatStore {
13191319
13201320 /// Whether to ring the terminal bell on the next redraw.
13211321 pub ring_bell: bool,
1322
1323 /// Whether the application is currently focused
1324 pub focused: bool,
13221325}
13231326
13241327impl ChatStore {
@@ -1341,6 +1344,7 @@ impl ChatStore {
13411344 sync_info: Default::default(),
13421345 draw_curr: None,
13431346 ring_bell: false,
1347 focused: true,
13441348 }
13451349 }
13461350
src/main.rs +4
@@ -355,9 +355,13 @@ impl Application {
355355 // Do nothing for now.
356356 },
357357 Event::FocusGained => {
358 let mut store = self.store.lock().await;
359 store.application.focused = true;
358360 self.focused = true;
359361 },
360362 Event::FocusLost => {
363 let mut store = self.store.lock().await;
364 store.application.focused = false;
361365 self.focused = false;
362366 },
363367 Event::Resize(_, _) => {
src/notifications.rs +13 −4
@@ -14,7 +14,7 @@ use matrix_sdk::{
1414use unicode_segmentation::UnicodeSegmentation;
1515
1616use crate::{
17 base::{AsyncProgramStore, IambError, IambResult},
17 base::{AsyncProgramStore, IambError, IambResult, ProgramStore},
1818 config::{ApplicationSettings, NotifyVia},
1919};
2020
@@ -44,7 +44,7 @@ pub async fn register_notifications(
4444 return;
4545 }
4646
47 if is_open(&store, room.room_id()).await {
47 if is_visible_room(&store, room.room_id()).await {
4848 return;
4949 }
5050
@@ -127,8 +127,7 @@ fn is_missing_mention(body: &Option<String>, mode: RoomNotificationMode, client:
127127 false
128128}
129129
130async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
131 let mut locked = store.lock().await;
130fn is_open(locked: &mut ProgramStore, room_id: &RoomId) -> bool {
132131 if let Some(draw_curr) = locked.application.draw_curr {
133132 let info = locked.application.get_room_info(room_id.to_owned());
134133 if let Some(draw_last) = info.draw_last {
@@ -138,6 +137,16 @@ async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
138137 false
139138}
140139
140fn is_focused(locked: &ProgramStore) -> bool {
141 locked.application.focused
142}
143
144async fn is_visible_room(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
145 let mut locked = store.lock().await;
146
147 is_focused(&locked) && is_open(&mut locked, room_id)
148}
149
141150pub async fn parse_notification(
142151 notification: Notification,
143152 room: MatrixRoom,