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 {
1319 1319
1320 /// Whether to ring the terminal bell on the next redraw. 1320 /// Whether to ring the terminal bell on the next redraw.
1321 pub ring_bell: bool, 1321 pub ring_bell: bool,
1322
1323 /// Whether the application is currently focused
1324 pub focused: bool,
1322} 1325}
1323 1326
1324impl ChatStore { 1327impl ChatStore {
@@ -1341,6 +1344,7 @@ impl ChatStore {
1341 sync_info: Default::default(), 1344 sync_info: Default::default(),
1342 draw_curr: None, 1345 draw_curr: None,
1343 ring_bell: false, 1346 ring_bell: false,
1347 focused: true,
1344 } 1348 }
1345 } 1349 }
1346 1350
src/main.rs +4
@@ -355,9 +355,13 @@ impl Application {
355 // Do nothing for now. 355 // Do nothing for now.
356 }, 356 },
357 Event::FocusGained => { 357 Event::FocusGained => {
358 let mut store = self.store.lock().await;
359 store.application.focused = true;
358 self.focused = true; 360 self.focused = true;
359 }, 361 },
360 Event::FocusLost => { 362 Event::FocusLost => {
363 let mut store = self.store.lock().await;
364 store.application.focused = false;
361 self.focused = false; 365 self.focused = false;
362 }, 366 },
363 Event::Resize(_, _) => { 367 Event::Resize(_, _) => {
src/notifications.rs +13 −4
@@ -14,7 +14,7 @@ use matrix_sdk::{
14use unicode_segmentation::UnicodeSegmentation; 14use unicode_segmentation::UnicodeSegmentation;
15 15
16use crate::{ 16use crate::{
17 base::{AsyncProgramStore, IambError, IambResult}, 17 base::{AsyncProgramStore, IambError, IambResult, ProgramStore},
18 config::{ApplicationSettings, NotifyVia}, 18 config::{ApplicationSettings, NotifyVia},
19}; 19};
20 20
@@ -44,7 +44,7 @@ pub async fn register_notifications(
44 return; 44 return;
45 } 45 }
46 46
47 if is_open(&store, room.room_id()).await { 47 if is_visible_room(&store, room.room_id()).await {
48 return; 48 return;
49 } 49 }
50 50
@@ -127,8 +127,7 @@ fn is_missing_mention(body: &Option<String>, mode: RoomNotificationMode, client:
127 false 127 false
128} 128}
129 129
130async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool { 130fn is_open(locked: &mut ProgramStore, room_id: &RoomId) -> bool {
131 let mut locked = store.lock().await;
132 if let Some(draw_curr) = locked.application.draw_curr { 131 if let Some(draw_curr) = locked.application.draw_curr {
133 let info = locked.application.get_room_info(room_id.to_owned()); 132 let info = locked.application.get_room_info(room_id.to_owned());
134 if let Some(draw_last) = info.draw_last { 133 if let Some(draw_last) = info.draw_last {
@@ -138,6 +137,16 @@ async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
138 false 137 false
139} 138}
140 139
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
141pub async fn parse_notification( 150pub async fn parse_notification(
142 notification: Notification, 151 notification: Notification,
143 room: MatrixRoom, 152 room: MatrixRoom,