mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 11:00:48 +03:00
Show the unread message count on the window title
This commit is contained in:
parent
e02dd2b8c5
commit
e1d48367f8
6 changed files with 41 additions and 1 deletions
|
@ -48,8 +48,10 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void close();
|
void close();
|
||||||
|
void changeWindowTitle(const QString &msg);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void showUnreadMessageNotification(int count);
|
||||||
void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
|
void updateTopBarAvatar(const QString &roomid, const QPixmap &img);
|
||||||
void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name);
|
void updateOwnProfileInfo(const QUrl &avatar_url, const QString &display_name);
|
||||||
void setOwnAvatar(const QPixmap &img);
|
void setOwnAvatar(const QPixmap &img);
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
inline bool isPressed();
|
inline bool isPressed();
|
||||||
inline RoomInfo info();
|
inline RoomInfo info();
|
||||||
inline void setAvatar(const QImage &avatar_image);
|
inline void setAvatar(const QImage &avatar_image);
|
||||||
|
inline int unreadMessageCount();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void clicked(const RoomInfo &info_);
|
void clicked(const RoomInfo &info_);
|
||||||
|
@ -82,6 +83,11 @@ private:
|
||||||
int unread_msg_count_;
|
int unread_msg_count_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline int RoomInfoListItem::unreadMessageCount()
|
||||||
|
{
|
||||||
|
return unread_msg_count_;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool RoomInfoListItem::isPressed()
|
inline bool RoomInfoListItem::isPressed()
|
||||||
{
|
{
|
||||||
return is_pressed_;
|
return is_pressed_;
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void roomChanged(const RoomInfo &info);
|
void roomChanged(const RoomInfo &info);
|
||||||
|
void totalUnreadMessageCountUpdated(int count);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateRoomAvatar(const QString &roomid, const QPixmap &img);
|
void updateRoomAvatar(const QString &roomid, const QPixmap &img);
|
||||||
|
@ -55,6 +56,8 @@ public slots:
|
||||||
void updateUnreadMessageCount(const QString &roomid, int count);
|
void updateUnreadMessageCount(const QString &roomid, int count);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void calculateUnreadMessageCount();
|
||||||
|
|
||||||
Ui::RoomList *ui;
|
Ui::RoomList *ui;
|
||||||
|
|
||||||
QMap<QString, RoomInfoListItem *> rooms_;
|
QMap<QString, RoomInfoListItem *> rooms_;
|
||||||
|
|
|
@ -64,11 +64,17 @@ ChatPage::ChatPage(QSharedPointer<MatrixClient> client, QWidget *parent)
|
||||||
view_manager_,
|
view_manager_,
|
||||||
SLOT(setHistoryView(const RoomInfo &)));
|
SLOT(setHistoryView(const RoomInfo &)));
|
||||||
|
|
||||||
|
// TODO: Better pass the whole RoomInfo struct instead of the roomid.
|
||||||
connect(view_manager_,
|
connect(view_manager_,
|
||||||
SIGNAL(unreadMessages(const QString &, int)),
|
SIGNAL(unreadMessages(const QString &, int)),
|
||||||
room_list_,
|
room_list_,
|
||||||
SLOT(updateUnreadMessageCount(const QString &, int)));
|
SLOT(updateUnreadMessageCount(const QString &, int)));
|
||||||
|
|
||||||
|
connect(room_list_,
|
||||||
|
SIGNAL(totalUnreadMessageCountUpdated(int)),
|
||||||
|
this,
|
||||||
|
SLOT(showUnreadMessageNotification(int)));
|
||||||
|
|
||||||
connect(text_input_,
|
connect(text_input_,
|
||||||
SIGNAL(sendTextMessage(const QString &)),
|
SIGNAL(sendTextMessage(const QString &)),
|
||||||
view_manager_,
|
view_manager_,
|
||||||
|
@ -206,6 +212,15 @@ void ChatPage::changeTopRoomInfo(const RoomInfo &info)
|
||||||
current_room_ = 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()
|
ChatPage::~ChatPage()
|
||||||
{
|
{
|
||||||
sync_timer_->stop();
|
sync_timer_->stop();
|
||||||
|
|
|
@ -51,6 +51,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(register_page_, SIGNAL(backButtonClicked()), this, SLOT(showWelcomePage()));
|
connect(register_page_, SIGNAL(backButtonClicked()), this, SLOT(showWelcomePage()));
|
||||||
|
|
||||||
connect(chat_page_, SIGNAL(close()), this, SLOT(showWelcomePage()));
|
connect(chat_page_, SIGNAL(close()), this, SLOT(showWelcomePage()));
|
||||||
|
connect(chat_page_, SIGNAL(changeWindowTitle(QString)), this, SLOT(setWindowTitle(QString)));
|
||||||
|
|
||||||
connect(client_.data(),
|
connect(client_.data(),
|
||||||
SIGNAL(loginSuccess(QString, QString, QString)),
|
SIGNAL(loginSuccess(QString, QString, QString)),
|
||||||
|
|
|
@ -89,6 +89,18 @@ void RoomList::updateUnreadMessageCount(const QString &roomid, int count)
|
||||||
}
|
}
|
||||||
|
|
||||||
rooms_[roomid]->updateUnreadMessageCount(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)
|
void RoomList::setInitialRooms(const Rooms &rooms)
|
||||||
|
@ -132,11 +144,12 @@ void RoomList::highlightSelectedRoom(const RoomInfo &info)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: Send a read receipt for the last event.
|
// TODO: Send a read receipt for the last event.
|
||||||
auto room = rooms_[info.id()];
|
auto room = rooms_[info.id()];
|
||||||
room->clearUnreadMessageCount();
|
room->clearUnreadMessageCount();
|
||||||
|
|
||||||
|
calculateUnreadMessageCount();
|
||||||
|
|
||||||
for (auto it = rooms_.constBegin(); it != rooms_.constEnd(); it++) {
|
for (auto it = rooms_.constBegin(); it != rooms_.constEnd(); it++) {
|
||||||
if (it.key() != info.id())
|
if (it.key() != info.id())
|
||||||
it.value()->setPressedState(false);
|
it.value()->setPressedState(false);
|
||||||
|
|
Loading…
Reference in a new issue