diff --git a/src/ChatPage.cc b/src/ChatPage.cc
index 33cacb3e..3bae177b 100644
--- a/src/ChatPage.cc
+++ b/src/ChatPage.cc
@@ -64,11 +64,17 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
view_manager_,
SLOT(setHistoryView(const RoomInfo &)));
+ // TODO: Better pass the whole RoomInfo struct instead of the roomid.
connect(view_manager_,
SIGNAL(unreadMessages(const QString &, int)),
room_list_,
SLOT(updateUnreadMessageCount(const QString &, int)));
+ connect(room_list_,
+ SIGNAL(totalUnreadMessageCountUpdated(int)),
+ this,
+ SLOT(showUnreadMessageNotification(int)));
+
connect(text_input_,
SIGNAL(sendTextMessage(const QString &)),
view_manager_,
@@ -206,6 +212,15 @@ void ChatPage::changeTopRoomInfo(const RoomInfo &info)
current_room_ = info;
}
+void ChatPage::showUnreadMessageNotification(int count)
+{
+ // TODO: Make the default title a const.
+ if (count == 0)
+ emit changeWindowTitle("nheko");
+ else
+ emit changeWindowTitle(QString("nheko (%1)").arg(count));
+}
+
ChatPage::~ChatPage()
{
sync_timer_->stop();
diff --git a/src/MainWindow.cc b/src/MainWindow.cc
index d0d01bcb..3d591755 100644
--- a/src/MainWindow.cc
+++ b/src/MainWindow.cc
@@ -51,6 +51,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(register_page_, SIGNAL(backButtonClicked()), this, SLOT(showWelcomePage()));
connect(chat_page_, SIGNAL(close()), this, SLOT(showWelcomePage()));
+ connect(chat_page_, SIGNAL(changeWindowTitle(QString)), this, SLOT(setWindowTitle(QString)));
connect(client_.data(),
SIGNAL(loginSuccess(QString, QString, QString)),
diff --git a/src/RoomList.cc b/src/RoomList.cc
index b1186d39..99553842 100644
--- a/src/RoomList.cc
+++ b/src/RoomList.cc
@@ -89,6 +89,18 @@ void RoomList::updateUnreadMessageCount(const QString &roomid, int count)
}
rooms_[roomid]->updateUnreadMessageCount(count);
+
+ calculateUnreadMessageCount();
+}
+
+void RoomList::calculateUnreadMessageCount()
+{
+ int total_unread_msgs = 0;
+
+ for (const auto &room : rooms_)
+ total_unread_msgs += room->unreadMessageCount();
+
+ emit totalUnreadMessageCountUpdated(total_unread_msgs);
}
void RoomList::setInitialRooms(const Rooms &rooms)
@@ -132,11 +144,12 @@ void RoomList::highlightSelectedRoom(const RoomInfo &info)
return;
}
-
// TODO: Send a read receipt for the last event.
auto room = rooms_[info.id()];
room->clearUnreadMessageCount();
+ calculateUnreadMessageCount();
+
for (auto it = rooms_.constBegin(); it != rooms_.constEnd(); it++) {
if (it.key() != info.id())
it.value()->setPressedState(false);
|