Make toggle in settings revert between old behavior and new behavior for sorting by unreads

This commit is contained in:
Emi Simpson 2020-03-15 14:56:39 -04:00
parent abac4c8d34
commit bf5ae884de
No known key found for this signature in database
GPG key ID: 68FAB2E2E6DFC98B
3 changed files with 26 additions and 23 deletions

View file

@ -329,10 +329,11 @@ RoomInfoListItem::updateUnreadMessageCount(int count, int highlightedCount)
update();
}
enum NotificationImportance : unsigned short
enum NotificationImportance : short
{
ImportanceDisabled = -1,
AllEventsRead = 0,
NewMinorEvents = 1,
NewMinorEvents = 1, // This is currently unused
NewMessage = 2,
NewMentions = 3,
Invite = 4
@ -342,16 +343,18 @@ unsigned short int
RoomInfoListItem::calculateImportance() const
{
// 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()) {
// If sorting by importance is disabled in settings, this only ever
// returns ImportanceDisabled
if (!settings->isSortByImportanceEnabled()) {
return ImportanceDisabled;
} else if (isInvite()) {
return Invite;
} else if (unreadHighlightedMsgCount_) {
return NewMentions;
} else if (unreadMsgCount_) {
return NewMessage;
} else if (hasUnreadMessages_ && !settings->isIgnoreMinorEventsEnabled()) {
return NewMinorEvents;
// } else if (hasUnreadMessages_ && !settings->isIgnoreMinorEventsEnabled()) {
// return NewMinorEvents;
} else {
return AllEventsRead;
}

View file

@ -58,7 +58,7 @@ UserSettings::load()
isButtonsInTimelineEnabled_ = settings.value("user/timeline/buttons", 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();
sortByImportance_ = settings.value("user/sort_by_unread", true).toBool();
isReadReceiptsEnabled_ = settings.value("user/read_receipts", true).toBool();
theme_ = settings.value("user/theme", defaultTheme_).toString();
font_ = settings.value("user/font_family", "default").toString();
@ -136,7 +136,7 @@ UserSettings::save()
settings.setValue("font_size", baseFontSize_);
settings.setValue("typing_notifications", isTypingNotificationsEnabled_);
settings.setValue("minor_events", ignoreMinorEvents_);
settings.setValue("minor_events", sortByImportance_);
settings.setValue("read_receipts", isReadReceiptsEnabled_);
settings.setValue("group_view", isGroupViewEnabled_);
settings.setValue("markdown_enabled", isMarkdownEnabled_);
@ -199,7 +199,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
groupViewToggle_ = new Toggle{this};
timelineButtonsToggle_ = new Toggle{this};
typingNotifications_ = new Toggle{this};
ignoreMinorEvents_ = new Toggle{this};
sortByImportance_ = new Toggle{this};
readReceipts_ = new Toggle{this};
markdownEnabled_ = new Toggle{this};
desktopNotifications_ = new Toggle{this};
@ -303,7 +303,7 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
boxWrap(tr("Group's sidebar"), groupViewToggle_);
boxWrap(tr("Show buttons in timeline"), timelineButtonsToggle_);
boxWrap(tr("Typing notifications"), typingNotifications_);
boxWrap(tr("Ignore minor events in room list"), ignoreMinorEvents_);
boxWrap(tr("Sort rooms by unreads"), sortByImportance_);
formLayout_->addRow(new HorizontalLine{this});
boxWrap(tr("Read receipts"), readReceipts_);
boxWrap(tr("Send messages as Markdown"), markdownEnabled_);
@ -405,8 +405,8 @@ UserSettingsPage::UserSettingsPage(QSharedPointer<UserSettings> settings, QWidge
settings_->setTypingNotifications(!isDisabled);
});
connect(ignoreMinorEvents_, &Toggle::toggled, this, [this](bool isDisabled) {
settings_->setIgnoreMinorEvents(!isDisabled);
connect(sortByImportance_, &Toggle::toggled, this, [this](bool isDisabled) {
settings_->setSortByImportance(!isDisabled);
});
connect(timelineButtonsToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
@ -447,7 +447,7 @@ UserSettingsPage::showEvent(QShowEvent *)
groupViewToggle_->setState(!settings_->isGroupViewEnabled());
avatarCircles_->setState(!settings_->isAvatarCirclesEnabled());
typingNotifications_->setState(!settings_->isTypingNotificationsEnabled());
ignoreMinorEvents_->setState(!settings_->isIgnoreMinorEventsEnabled());
sortByImportance_->setState(!settings_->isSortByImportanceEnabled());
timelineButtonsToggle_->setState(!settings_->isButtonsInTimelineEnabled());
readReceipts_->setState(!settings_->isReadReceiptsEnabled());
markdownEnabled_->setState(!settings_->isMarkdownEnabled());

View file

@ -87,9 +87,9 @@ public:
save();
}
void setIgnoreMinorEvents(bool state)
void setSortByImportance(bool state)
{
ignoreMinorEvents_ = state;
sortByImportance_ = state;
emit roomSortingChanged();
}
@ -118,7 +118,7 @@ public:
bool isAvatarCirclesEnabled() const { return avatarCircles_; }
bool isMarkdownEnabled() const { return isMarkdownEnabled_; }
bool isTypingNotificationsEnabled() const { return isTypingNotificationsEnabled_; }
bool isIgnoreMinorEventsEnabled() const { return ignoreMinorEvents_; }
bool isSortByImportanceEnabled() const { return sortByImportance_; }
bool isButtonsInTimelineEnabled() const { return isButtonsInTimelineEnabled_; }
bool isReadReceiptsEnabled() const { return isReadReceiptsEnabled_; }
bool hasDesktopNotifications() const { return hasDesktopNotifications_; }
@ -142,7 +142,7 @@ private:
bool isGroupViewEnabled_;
bool isMarkdownEnabled_;
bool isTypingNotificationsEnabled_;
bool ignoreMinorEvents_;
bool sortByImportance_;
bool isButtonsInTimelineEnabled_;
bool isReadReceiptsEnabled_;
bool hasDesktopNotifications_;
@ -194,7 +194,7 @@ private:
Toggle *groupViewToggle_;
Toggle *timelineButtonsToggle_;
Toggle *typingNotifications_;
Toggle *ignoreMinorEvents_;
Toggle *sortByImportance_;
Toggle *readReceipts_;
Toggle *markdownEnabled_;
Toggle *desktopNotifications_;