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

This commit is contained in:
Andrew Collins 2024-08-01 13:37:21 +10:00 committed by GitHub
parent cb4455655f
commit 9a1adfb287
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 4 deletions

View file

@ -1319,6 +1319,9 @@ pub struct ChatStore {
/// Whether to ring the terminal bell on the next redraw.
pub ring_bell: bool,
/// Whether the application is currently focused
pub focused: bool,
}
impl ChatStore {
@ -1341,6 +1344,7 @@ impl ChatStore {
sync_info: Default::default(),
draw_curr: None,
ring_bell: false,
focused: true,
}
}

View file

@ -355,9 +355,13 @@ impl Application {
// Do nothing for now.
},
Event::FocusGained => {
let mut store = self.store.lock().await;
store.application.focused = true;
self.focused = true;
},
Event::FocusLost => {
let mut store = self.store.lock().await;
store.application.focused = false;
self.focused = false;
},
Event::Resize(_, _) => {

View file

@ -14,7 +14,7 @@ use matrix_sdk::{
use unicode_segmentation::UnicodeSegmentation;
use crate::{
base::{AsyncProgramStore, IambError, IambResult},
base::{AsyncProgramStore, IambError, IambResult, ProgramStore},
config::{ApplicationSettings, NotifyVia},
};
@ -44,7 +44,7 @@ pub async fn register_notifications(
return;
}
if is_open(&store, room.room_id()).await {
if is_visible_room(&store, room.room_id()).await {
return;
}
@ -127,8 +127,7 @@ fn is_missing_mention(body: &Option<String>, mode: RoomNotificationMode, client:
false
}
async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
let mut locked = store.lock().await;
fn is_open(locked: &mut ProgramStore, room_id: &RoomId) -> bool {
if let Some(draw_curr) = locked.application.draw_curr {
let info = locked.application.get_room_info(room_id.to_owned());
if let Some(draw_last) = info.draw_last {
@ -138,6 +137,16 @@ async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
false
}
fn is_focused(locked: &ProgramStore) -> bool {
locked.application.focused
}
async fn is_visible_room(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
let mut locked = store.lock().await;
is_focused(&locked) && is_open(&mut locked, room_id)
}
pub async fn parse_notification(
notification: Notification,
room: MatrixRoom,