diff --git a/include/ChatPage.h b/include/ChatPage.h index fd0b63dc1c2d31ec751d747675ab68efd1a3c093..182dca3a4c1f8784905077edf6c26751dd818a62 100644 --- a/include/ChatPage.h +++ b/include/ChatPage.h @@ -48,8 +48,10 @@ public: signals: void close(); + void changeWindowTitle(const QString &msg); private slots: + void showUnreadMessageNotification(int count); void updateTopBarAvatar(const QString &roomid, const QPixmap &img); void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name); void setOwnAvatar(const QPixmap &img); diff --git a/include/RoomInfoListItem.h b/include/RoomInfoListItem.h index 24e84bd36aa2aefe07037d3980d6cc8f5e5e8530..5c403dc37c1ab9b87de6a6e4dc6da3666c757834 100644 --- a/include/RoomInfoListItem.h +++ b/include/RoomInfoListItem.h @@ -42,6 +42,7 @@ public: inline bool isPressed(); inline RoomInfo info(); inline void setAvatar(const QImage &avatar_image); + inline int unreadMessageCount(); signals: void clicked(const RoomInfo &info_); @@ -82,6 +83,11 @@ private: int unread_msg_count_; }; +inline int RoomInfoListItem::unreadMessageCount() +{ + return unread_msg_count_; +} + inline bool RoomInfoListItem::isPressed() { return is_pressed_; diff --git a/include/RoomList.h b/include/RoomList.h index d60661660489b77e6d865fdb3f79e7de7e84d2f1..e22f0954fdb636b5198beecda2f603ab480f2a5b 100644 --- a/include/RoomList.h +++ b/include/RoomList.h @@ -48,6 +48,7 @@ public: signals: void roomChanged(const RoomInfo &info); + void totalUnreadMessageCountUpdated(int count); public slots: void updateRoomAvatar(const QString &roomid, const QPixmap &img); @@ -55,6 +56,8 @@ public slots: void updateUnreadMessageCount(const QString &roomid, int count); private: + void calculateUnreadMessageCount(); + Ui::RoomList *ui; QMap<QString, RoomInfoListItem *> rooms_; diff --git a/src/ChatPage.cc b/src/ChatPage.cc index 33cacb3eb205d50b84821eaea666515896005afc..3bae177bd9da4d88aca9a5da98b4b05cc0d0b8b9 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 d0d01bcbbedb47b0baac668fc23abb89e1ad131a..3d591755f5aae0a0721ca69c3a1222556e7e9f56 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 b1186d39176ef872d72178f5dbf0c040b1708872..9955384235d183c139ad76a3b46eddcaed8c08ce 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);