mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Don't send notification for the room that is currently open
This commit is contained in:
parent
506cf68072
commit
5aff3e4309
2 changed files with 11 additions and 2 deletions
|
@ -117,6 +117,12 @@ private slots:
|
|||
private:
|
||||
static ChatPage *instance_;
|
||||
|
||||
//! Check if the given room is currently open.
|
||||
bool isRoomActive(const QString &room_id)
|
||||
{
|
||||
return isActiveWindow() && currentRoom() == room_id;
|
||||
}
|
||||
|
||||
using UserID = QString;
|
||||
using Membership = mtx::events::StateEvent<mtx::events::state::Member>;
|
||||
using Memberships = std::map<std::string, Membership>;
|
||||
|
|
|
@ -868,15 +868,18 @@ ChatPage::sendDesktopNotifications(const mtx::responses::Notifications &res)
|
|||
if (!cache_->isNotificationSent(event_id)) {
|
||||
const auto room_id = QString::fromStdString(item.room_id);
|
||||
const auto user_id = utils::event_sender(item.event);
|
||||
const auto body = utils::event_body(item.event);
|
||||
|
||||
// We should only sent one notification per event.
|
||||
cache_->markSentNotification(event_id);
|
||||
|
||||
// Don't send a notification when the current room is opened.
|
||||
if (isRoomActive(room_id))
|
||||
continue;
|
||||
|
||||
NotificationsManager::postNotification(
|
||||
QString::fromStdString(cache_->singleRoomInfo(item.room_id).name),
|
||||
Cache::displayName(room_id, user_id),
|
||||
body);
|
||||
utils::event_body(item.event));
|
||||
}
|
||||
} catch (const lmdb::error &e) {
|
||||
qWarning() << e.what();
|
||||
|
|
Loading…
Reference in a new issue