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,29 +329,32 @@ RoomInfoListItem::updateUnreadMessageCount(int count, int highlightedCount)
update(); update();
} }
enum NotificationImportance : unsigned short enum NotificationImportance : short
{ {
AllEventsRead = 0, ImportanceDisabled = -1,
NewMinorEvents = 1, AllEventsRead = 0,
NewMessage = 2, NewMinorEvents = 1, // This is currently unused
NewMentions = 3, NewMessage = 2,
Invite = 4 NewMentions = 3,
Invite = 4
}; };
unsigned short int unsigned short int
RoomInfoListItem::calculateImportance() const RoomInfoListItem::calculateImportance() const
{ {
// Returns the degree of importance of the unread messages in the room. // Returns the degree of importance of the unread messages in the room.
// If ignoreMinorEvents is set to true in the settings, then // If sorting by importance is disabled in settings, this only ever
// NewMinorEvents will always be rounded down to AllEventsRead // returns ImportanceDisabled
if (isInvite()) { if (!settings->isSortByImportanceEnabled()) {
return ImportanceDisabled;
} else if (isInvite()) {
return Invite; return Invite;
} else if (unreadHighlightedMsgCount_) { } else if (unreadHighlightedMsgCount_) {
return NewMentions; return NewMentions;
} else if (unreadMsgCount_) { } else if (unreadMsgCount_) {
return NewMessage; return NewMessage;
} else if (hasUnreadMessages_ && !settings->isIgnoreMinorEventsEnabled()) { // } else if (hasUnreadMessages_ && !settings->isIgnoreMinorEventsEnabled()) {
return NewMinorEvents; // return NewMinorEvents;
} else { } else {
return AllEventsRead; return AllEventsRead;
} }

View File

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

View File

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