mirror of
https://github.com/youwen5/iamb.git
synced 2025-06-20 05:39:52 -07:00
Allow notifications on open room if terminal not focused (#281)
This commit is contained in:
parent
cb4455655f
commit
9a1adfb287
3 changed files with 21 additions and 4 deletions
|
@ -1319,6 +1319,9 @@ pub struct ChatStore {
|
||||||
|
|
||||||
/// Whether to ring the terminal bell on the next redraw.
|
/// Whether to ring the terminal bell on the next redraw.
|
||||||
pub ring_bell: bool,
|
pub ring_bell: bool,
|
||||||
|
|
||||||
|
/// Whether the application is currently focused
|
||||||
|
pub focused: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatStore {
|
impl ChatStore {
|
||||||
|
@ -1341,6 +1344,7 @@ impl ChatStore {
|
||||||
sync_info: Default::default(),
|
sync_info: Default::default(),
|
||||||
draw_curr: None,
|
draw_curr: None,
|
||||||
ring_bell: false,
|
ring_bell: false,
|
||||||
|
focused: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,9 +355,13 @@ impl Application {
|
||||||
// Do nothing for now.
|
// Do nothing for now.
|
||||||
},
|
},
|
||||||
Event::FocusGained => {
|
Event::FocusGained => {
|
||||||
|
let mut store = self.store.lock().await;
|
||||||
|
store.application.focused = true;
|
||||||
self.focused = true;
|
self.focused = true;
|
||||||
},
|
},
|
||||||
Event::FocusLost => {
|
Event::FocusLost => {
|
||||||
|
let mut store = self.store.lock().await;
|
||||||
|
store.application.focused = false;
|
||||||
self.focused = false;
|
self.focused = false;
|
||||||
},
|
},
|
||||||
Event::Resize(_, _) => {
|
Event::Resize(_, _) => {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use matrix_sdk::{
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
base::{AsyncProgramStore, IambError, IambResult},
|
base::{AsyncProgramStore, IambError, IambResult, ProgramStore},
|
||||||
config::{ApplicationSettings, NotifyVia},
|
config::{ApplicationSettings, NotifyVia},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ pub async fn register_notifications(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_open(&store, room.room_id()).await {
|
if is_visible_room(&store, room.room_id()).await {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,8 +127,7 @@ fn is_missing_mention(body: &Option<String>, mode: RoomNotificationMode, client:
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
|
fn is_open(locked: &mut ProgramStore, room_id: &RoomId) -> bool {
|
||||||
let mut locked = store.lock().await;
|
|
||||||
if let Some(draw_curr) = locked.application.draw_curr {
|
if let Some(draw_curr) = locked.application.draw_curr {
|
||||||
let info = locked.application.get_room_info(room_id.to_owned());
|
let info = locked.application.get_room_info(room_id.to_owned());
|
||||||
if let Some(draw_last) = info.draw_last {
|
if let Some(draw_last) = info.draw_last {
|
||||||
|
@ -138,6 +137,16 @@ async fn is_open(store: &AsyncProgramStore, room_id: &RoomId) -> bool {
|
||||||
false
|
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(
|
pub async fn parse_notification(
|
||||||
notification: Notification,
|
notification: Notification,
|
||||||
room: MatrixRoom,
|
room: MatrixRoom,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue