From 08125e8c448b43201319242d1f5f4e96ab7c3911 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Fri, 13 Mar 2020 19:30:50 -0400 Subject: Sort room list by room priority --- src/RoomList.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/RoomList.cpp') diff --git a/src/RoomList.cpp b/src/RoomList.cpp index 6feb4f76..977cac99 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -16,6 +16,7 @@ */ #include +#include #include #include @@ -328,30 +329,47 @@ RoomList::updateRoomDescription(const QString &roomid, const DescInfo &info) emit sortRoomsByLastMessage(); } +struct room_sort { + bool operator() (const RoomInfoListItem * a, const RoomInfoListItem * b) const { + // Sort by "importance" (i.e. invites before mentions before + // notifs before new events before old events), then secondly + // by recency. + + // Checking importance first + const auto a_importance = a->calculateImportance(); + const auto b_importance = b->calculateImportance(); + if(a_importance != b_importance) { + return a_importance > b_importance; + } + + // Now sort by recency + // Zero if empty, otherwise the time that the event occured + const uint64_t a_recency = a->lastMessageInfo().userid.isEmpty() ? 0 : + a->lastMessageInfo().datetime.toMSecsSinceEpoch(); + const uint64_t b_recency = b->lastMessageInfo().userid.isEmpty() ? 0 : + b->lastMessageInfo().datetime.toMSecsSinceEpoch(); + return a_recency > b_recency; + } +}; + void RoomList::sortRoomsByLastMessage() { isSortPending_ = false; - std::multimap> times; + std::multiset times; for (int ii = 0; ii < contentsLayout_->count(); ++ii) { auto room = qobject_cast(contentsLayout_->itemAt(ii)->widget()); if (!room) continue; - - // Not a room message. - if (room->isInvite()) - times.emplace(std::numeric_limits::max(), room); - else if (room->lastMessageInfo().userid.isEmpty()) - times.emplace(0, room); else - times.emplace(room->lastMessageInfo().datetime.toMSecsSinceEpoch(), room); + times.insert(room); } for (auto it = times.cbegin(); it != times.cend(); ++it) { - const auto roomWidget = it->second; + const auto roomWidget = *it; const auto currentIndex = contentsLayout_->indexOf(roomWidget); const auto newIndex = std::distance(times.cbegin(), it); -- cgit 1.5.1 From 0153dc7a390aa8c7f5dc33973e80ef6676b45f1e Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Fri, 13 Mar 2020 20:52:42 -0400 Subject: Automatically move rooms down in the list once they've been read --- src/RoomList.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/RoomList.cpp') diff --git a/src/RoomList.cpp b/src/RoomList.cpp index 977cac99..fba910a7 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -123,6 +123,8 @@ RoomList::updateUnreadMessageCount(const QString &roomid, int count, int highlig rooms_[roomid]->updateUnreadMessageCount(count, highlightedCount); calculateUnreadMessageCount(); + + sortRoomsByLastMessage(); } void -- cgit 1.5.1 From a5b388db15ae6fbe22497c458ce2af888e6f27df Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sat, 14 Mar 2020 09:16:08 -0400 Subject: Appease the linter --- src/RoomInfoListItem.cpp | 6 ++---- src/RoomList.cpp | 18 +++++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/RoomList.cpp') diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index 1860881a..5b6840bf 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -332,10 +332,8 @@ RoomInfoListItem::calculateImportance() const // 2: Contains unread messages // 3: Contains mentions // 4: Is a room invite - return (hasUnreadMessages_) + - (unreadHighlightedMsgCount_ + unreadMsgCount_ != 0) + - (unreadHighlightedMsgCount_ != 0) + - (isInvite()) * 4; + return (hasUnreadMessages_) + (unreadHighlightedMsgCount_ + unreadMsgCount_ != 0) + + (unreadHighlightedMsgCount_ != 0) + (isInvite()) * 4; } void diff --git a/src/RoomList.cpp b/src/RoomList.cpp index fba910a7..74a7ff6f 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -331,8 +331,10 @@ RoomList::updateRoomDescription(const QString &roomid, const DescInfo &info) emit sortRoomsByLastMessage(); } -struct room_sort { - bool operator() (const RoomInfoListItem * a, const RoomInfoListItem * b) const { +struct room_sort +{ + bool operator()(const RoomInfoListItem *a, const RoomInfoListItem *b) const + { // Sort by "importance" (i.e. invites before mentions before // notifs before new events before old events), then secondly // by recency. @@ -340,16 +342,18 @@ struct room_sort { // Checking importance first const auto a_importance = a->calculateImportance(); const auto b_importance = b->calculateImportance(); - if(a_importance != b_importance) { + if (a_importance != b_importance) { return a_importance > b_importance; } // Now sort by recency // Zero if empty, otherwise the time that the event occured - const uint64_t a_recency = a->lastMessageInfo().userid.isEmpty() ? 0 : - a->lastMessageInfo().datetime.toMSecsSinceEpoch(); - const uint64_t b_recency = b->lastMessageInfo().userid.isEmpty() ? 0 : - b->lastMessageInfo().datetime.toMSecsSinceEpoch(); + const uint64_t a_recency = a->lastMessageInfo().userid.isEmpty() + ? 0 + : a->lastMessageInfo().datetime.toMSecsSinceEpoch(); + const uint64_t b_recency = b->lastMessageInfo().userid.isEmpty() + ? 0 + : b->lastMessageInfo().datetime.toMSecsSinceEpoch(); return a_recency > b_recency; } }; -- cgit 1.5.1 From b6bd36ac16f3fbc3717385a3c2fe365535206159 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sun, 15 Mar 2020 11:19:22 -0400 Subject: Added toggle in the settings to ignore minor events --- src/ChatPage.cpp | 2 +- src/RoomInfoListItem.cpp | 17 ++++++++++------- src/RoomInfoListItem.h | 8 +++++++- src/RoomList.cpp | 8 +++++--- src/RoomList.h | 6 +++++- src/UserSettingsPage.cpp | 9 +++++++++ src/UserSettingsPage.h | 9 +++++++++ 7 files changed, 46 insertions(+), 13 deletions(-) (limited to 'src/RoomList.cpp') diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp index 698a4ae2..7674f11c 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp @@ -100,7 +100,7 @@ ChatPage::ChatPage(QSharedPointer userSettings, QWidget *parent) user_info_widget_ = new UserInfoWidget(sideBar_); user_mentions_popup_ = new popups::UserMentions(); - room_list_ = new RoomList(sideBar_); + room_list_ = new RoomList(userSettings, sideBar_); connect(room_list_, &RoomList::joinRoom, this, &ChatPage::joinRoom); sideBarLayout_->addWidget(user_info_widget_); diff --git a/src/RoomInfoListItem.cpp b/src/RoomInfoListItem.cpp index 26c4e8cf..d7537d64 100644 --- a/src/RoomInfoListItem.cpp +++ b/src/RoomInfoListItem.cpp @@ -26,6 +26,7 @@ #include "Config.h" #include "RoomInfoListItem.h" #include "Splitter.h" +#include "UserSettingsPage.h" #include "Utils.h" #include "ui/Menu.h" #include "ui/Ripple.h" @@ -99,7 +100,10 @@ RoomInfoListItem::init(QWidget *parent) menu_->addAction(leaveRoom_); } -RoomInfoListItem::RoomInfoListItem(QString room_id, const RoomInfo &info, QWidget *parent) +RoomInfoListItem::RoomInfoListItem(QString room_id, + const RoomInfo &info, + QSharedPointer userSettings, + QWidget *parent) : QWidget(parent) , roomType_{info.is_invite ? RoomType::Invited : RoomType::Joined} , roomId_(std::move(room_id)) @@ -107,6 +111,7 @@ RoomInfoListItem::RoomInfoListItem(QString room_id, const RoomInfo &info, QWidge , isPressed_(false) , unreadMsgCount_(0) , unreadHighlightedMsgCount_(0) + , settings(userSettings) { init(parent); } @@ -336,18 +341,16 @@ enum NotificationImportance : unsigned short unsigned short int RoomInfoListItem::calculateImportance() const { - // 0: All messages and minor events read - // 1: Contains unread minor events (joins/notices/muted messages) - // 2: Contains unread messages - // 3: Contains mentions - // 4: Is a room invite + // Returns the degree of importance of the unread messages in the room. + // If ignoreMinorEvents is set to true in the settings, then + // NewMinorEvents will always be rounded down to AllEventsRead if (isInvite()) { return Invite; } else if (unreadHighlightedMsgCount_) { return NewMentions; } else if (unreadMsgCount_) { return NewMessage; - } else if (hasUnreadMessages_) { + } else if (hasUnreadMessages_ && !settings->isIgnoreMinorEventsEnabled()) { return NewMinorEvents; } else { return AllEventsRead; diff --git a/src/RoomInfoListItem.h b/src/RoomInfoListItem.h index a246e487..9361a20b 100644 --- a/src/RoomInfoListItem.h +++ b/src/RoomInfoListItem.h @@ -25,6 +25,7 @@ #include #include "CacheStructs.h" +#include "UserSettingsPage.h" #include "ui/Avatar.h" class Menu; @@ -63,7 +64,10 @@ class RoomInfoListItem : public QWidget Q_PROPERTY(QColor btnTextColor READ btnTextColor WRITE setBtnTextColor) public: - RoomInfoListItem(QString room_id, const RoomInfo &info, QWidget *parent = nullptr); + RoomInfoListItem(QString room_id, + const RoomInfo &info, + QSharedPointer userSettings, + QWidget *parent = nullptr); void updateUnreadMessageCount(int count, int highlightedCount); void clearUnreadMessageCount() { updateUnreadMessageCount(0, 0); }; @@ -216,4 +220,6 @@ private: QColor bubbleBgColor_; QColor bubbleFgColor_; + + QSharedPointer settings; }; diff --git a/src/RoomList.cpp b/src/RoomList.cpp index 74a7ff6f..a9ce957a 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -27,11 +27,13 @@ #include "MainWindow.h" #include "RoomInfoListItem.h" #include "RoomList.h" +#include "UserSettingsPage.h" #include "Utils.h" #include "ui/OverlayModal.h" -RoomList::RoomList(QWidget *parent) +RoomList::RoomList(QSharedPointer userSettings, QWidget *parent) : QWidget(parent) + , settings(userSettings) { topLayout_ = new QVBoxLayout(this); topLayout_->setSpacing(0); @@ -68,7 +70,7 @@ RoomList::RoomList(QWidget *parent) void RoomList::addRoom(const QString &room_id, const RoomInfo &info) { - auto room_item = new RoomInfoListItem(room_id, info, scrollArea_); + auto room_item = new RoomInfoListItem(room_id, info, settings, scrollArea_); room_item->setRoomName(QString::fromStdString(std::move(info.name))); connect(room_item, &RoomInfoListItem::clicked, this, &RoomList::highlightSelectedRoom); @@ -492,7 +494,7 @@ RoomList::updateRoom(const QString &room_id, const RoomInfo &info) void RoomList::addInvitedRoom(const QString &room_id, const RoomInfo &info) { - auto room_item = new RoomInfoListItem(room_id, info, scrollArea_); + auto room_item = new RoomInfoListItem(room_id, info, settings, scrollArea_); connect(room_item, &RoomInfoListItem::acceptInvite, this, &RoomList::acceptInvite); connect(room_item, &RoomInfoListItem::declineInvite, this, &RoomList::declineInvite); diff --git a/src/RoomList.h b/src/RoomList.h index fef552c6..a0151f92 100644 --- a/src/RoomList.h +++ b/src/RoomList.h @@ -23,6 +23,9 @@ #include #include +#include "CacheStructs.h" +#include "UserSettingsPage.h" + class LeaveRoomDialog; class OverlayModal; class RoomInfoListItem; @@ -35,7 +38,7 @@ class RoomList : public QWidget Q_OBJECT public: - explicit RoomList(QWidget *parent = nullptr); + explicit RoomList(QSharedPointer userSettings, QWidget *parent = nullptr); void initialize(const QMap &info); void sync(const std::map &info); @@ -100,4 +103,5 @@ private: QString selectedRoom_; bool isSortPending_ = false; + QSharedPointer settings; }; diff --git a/src/UserSettingsPage.cpp b/src/UserSettingsPage.cpp index 2cac783c..7bae01a0 100644 --- a/src/UserSettingsPage.cpp +++ b/src/UserSettingsPage.cpp @@ -57,6 +57,7 @@ UserSettings::load() isGroupViewEnabled_ = settings.value("user/group_view", true).toBool(); isMarkdownEnabled_ = settings.value("user/markdown_enabled", true).toBool(); isTypingNotificationsEnabled_ = settings.value("user/typing_notifications", true).toBool(); + ignoreMinorEvents_ = settings.value("user/minor_events", false).toBool(); isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool(); theme_ = settings.value("user/theme", defaultTheme_).toString(); font_ = settings.value("user/font_family", "default").toString(); @@ -130,6 +131,7 @@ UserSettings::save() settings.setValue("font_size", baseFontSize_); settings.setValue("typing_notifications", isTypingNotificationsEnabled_); + settings.setValue("minor_events", ignoreMinorEvents_); settings.setValue("read_receipts", isReadReceiptsEnabled_); settings.setValue("group_view", isGroupViewEnabled_); settings.setValue("markdown_enabled", isMarkdownEnabled_); @@ -191,6 +193,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge avatarCircles_ = new Toggle{this}; groupViewToggle_ = new Toggle{this}; typingNotifications_ = new Toggle{this}; + ignoreMinorEvents_ = new Toggle{this}; readReceipts_ = new Toggle{this}; markdownEnabled_ = new Toggle{this}; desktopNotifications_ = new Toggle{this}; @@ -293,6 +296,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge boxWrap(tr("Circular Avatars"), avatarCircles_); boxWrap(tr("Group's sidebar"), groupViewToggle_); boxWrap(tr("Typing notifications"), typingNotifications_); + boxWrap(tr("Ignore minor events in room list"), ignoreMinorEvents_); formLayout_->addRow(new HorizontalLine{this}); boxWrap(tr("Read receipts"), readReceipts_); boxWrap(tr("Send messages as Markdown"), markdownEnabled_); @@ -394,6 +398,10 @@ UserSettingsPage::UserSettingsPage(QSharedPointer settings, QWidge settings_->setTypingNotifications(!isDisabled); }); + connect(ignoreMinorEvents_, &Toggle::toggled, this, [this](bool isDisabled) { + settings_->setIgnoreMinorEvents(!isDisabled); + }); + connect(readReceipts_, &Toggle::toggled, this, [this](bool isDisabled) { settings_->setReadReceipts(!isDisabled); }); @@ -428,6 +436,7 @@ UserSettingsPage::showEvent(QShowEvent *) groupViewToggle_->setState(!settings_->isGroupViewEnabled()); avatarCircles_->setState(!settings_->isAvatarCirclesEnabled()); typingNotifications_->setState(!settings_->isTypingNotificationsEnabled()); + ignoreMinorEvents_->setState(!settings_->isIgnoreMinorEventsEnabled()); readReceipts_->setState(!settings_->isReadReceiptsEnabled()); markdownEnabled_->setState(!settings_->isMarkdownEnabled()); desktopNotifications_->setState(!settings_->hasDesktopNotifications()); diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index a1b7b084..e1c52277 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -87,6 +87,12 @@ public: save(); } + void setIgnoreMinorEvents(bool state) + { + ignoreMinorEvents_ = state; + save(); + } + void setDesktopNotifications(bool state) { hasDesktopNotifications_ = state; @@ -106,6 +112,7 @@ public: bool isAvatarCirclesEnabled() const { return avatarCircles_; } bool isMarkdownEnabled() const { return isMarkdownEnabled_; } bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; } + bool isIgnoreMinorEventsEnabled() const { return ignoreMinorEvents_; } bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; } bool hasDesktopNotifications() const { return hasDesktopNotifications_; } double fontSize() const { return baseFontSize_; } @@ -127,6 +134,7 @@ private: bool isGroupViewEnabled_; bool isMarkdownEnabled_; bool isTypingNotificationsEnabled_; + bool ignoreMinorEvents_; bool isReadReceiptsEnabled_; bool hasDesktopNotifications_; bool avatarCircles_; @@ -176,6 +184,7 @@ private: Toggle *startInTrayToggle_; Toggle *groupViewToggle_; Toggle *typingNotifications_; + Toggle *ignoreMinorEvents_; Toggle *readReceipts_; Toggle *markdownEnabled_; Toggle *desktopNotifications_; -- cgit 1.5.1 From abac4c8d34db971382c4716dea735f1fd0755fa3 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sun, 15 Mar 2020 14:30:21 -0400 Subject: Sort room list on setting change --- src/RoomList.cpp | 4 ++++ src/UserSettingsPage.h | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/RoomList.cpp') diff --git a/src/RoomList.cpp b/src/RoomList.cpp index a9ce957a..13a4fa67 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -65,6 +65,10 @@ RoomList::RoomList(QSharedPointer userSettings, QWidget *parent) topLayout_->addWidget(scrollArea_); connect(this, &RoomList::updateRoomAvatarCb, this, &RoomList::updateRoomAvatar); + connect(userSettings.get(), + &UserSettings::roomSortingChanged, + this, + &RoomList::sortRoomsByLastMessage); } void diff --git a/src/UserSettingsPage.h b/src/UserSettingsPage.h index a1bc4ffc..d47ceb83 100644 --- a/src/UserSettingsPage.h +++ b/src/UserSettingsPage.h @@ -87,7 +87,11 @@ public: save(); } - void setIgnoreMinorEvents(bool state) { ignoreMinorEvents_ = state; } + void setIgnoreMinorEvents(bool state) + { + ignoreMinorEvents_ = state; + emit roomSortingChanged(); + } void setButtonsInTimeline(bool state) { @@ -124,6 +128,7 @@ public: signals: void groupViewStateChanged(bool state); + void roomSortingChanged(); private: // Default to system theme if QT_QPA_PLATFORMTHEME var is set. -- cgit 1.5.1 From 12aa94ad9afdeedbf05c785b234c2605c282f0d1 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Sun, 15 Mar 2020 15:27:30 -0400 Subject: Fixed compatibility with Qt < 5.11 --- src/RoomList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/RoomList.cpp') diff --git a/src/RoomList.cpp b/src/RoomList.cpp index 13a4fa67..1c7c340d 100644 --- a/src/RoomList.cpp +++ b/src/RoomList.cpp @@ -65,7 +65,7 @@ RoomList::RoomList(QSharedPointer userSettings, QWidget *parent) topLayout_->addWidget(scrollArea_); connect(this, &RoomList::updateRoomAvatarCb, this, &RoomList::updateRoomAvatar); - connect(userSettings.get(), + connect(userSettings.data(), &UserSettings::roomSortingChanged, this, &RoomList::sortRoomsByLastMessage); -- cgit 1.5.1