diff --git a/src/apps/qml/RoomsComponent.qml b/src/apps/qml/RoomsComponent.qml --- a/src/apps/qml/RoomsComponent.qml +++ b/src/apps/qml/RoomsComponent.qml @@ -47,6 +47,14 @@ searchChannelDialog.initializeAndOpen(); } }, + Kirigami.Action { + iconName: "edit-symbolic" + text: i18n("Unread on Top"); + checkable: true + onToggled: { + appid.rocketChatAccount.setSortUnreadOnTop(checked); + } + }, Kirigami.Action { iconName: "edit-symbolic" text: i18n("Show Close Icons"); diff --git a/src/ruqolacore/model/roommodel.cpp b/src/ruqolacore/model/roommodel.cpp --- a/src/ruqolacore/model/roommodel.cpp +++ b/src/ruqolacore/model/roommodel.cpp @@ -469,25 +469,44 @@ str = i18n("Favorites"); } else { const QString channelTypeStr = r->channelType(); - if (channelTypeStr == QLatin1String("p")) { - if (r->parentRid().isEmpty()) { + if (mRocketChatAccount && mRocketChatAccount->sortUnreadOnTop() && (r->unread() > 0 || r->alert())) { + if (channelTypeStr == QLatin1String("p")) { + if (r->parentRid().isEmpty()) { + str = i18n("Unread Rooms"); + } else { + str = i18n("Unread Discussions"); + } + } else if (channelTypeStr == QLatin1String("c")) { + str = i18n("Unread Rooms"); + } else if (channelTypeStr == QLatin1String("d")) { + str = i18n("Unread Private Messages"); + } + } else { + if (channelTypeStr == QLatin1String("p")) { + if (r->parentRid().isEmpty()) { + str = i18n("Rooms"); + } else { + str = i18n("Discussions"); + } + } else if (channelTypeStr == QLatin1String("c")) { str = i18n("Rooms"); - } else { - str = i18n("Discussions"); + } else if (channelTypeStr == QLatin1String("d")) { + str = i18n("Private Messages"); } - } else if (channelTypeStr == QLatin1String("c")) { - str = i18n("Rooms"); - } else if (channelTypeStr == QLatin1String("d")) { - str = i18n("Private Message"); } } return str; } int RoomModel::order(Room *r) const { int order = 0; - //First item are favorites channels + // Unread on top: push down everything that isn't unread + if (mRocketChatAccount && mRocketChatAccount->sortUnreadOnTop() && r->unread() == 0 && !r->alert()) { + order += 20; + } + + // Then we have favorites channels, push down everything else if (!r->favorite()) { order += 10; } diff --git a/src/ruqolacore/rocketchataccount.h b/src/ruqolacore/rocketchataccount.h --- a/src/ruqolacore/rocketchataccount.h +++ b/src/ruqolacore/rocketchataccount.h @@ -220,6 +220,7 @@ Q_INVOKABLE void channelGetAllUserMentions(const QString &roomId); Q_INVOKABLE void switchEditingMode(bool b); + Q_INVOKABLE void setSortUnreadOnTop(bool b); Q_INVOKABLE void kickUser(const QString &rid, const QString &userId, const QString &channelType); Q_INVOKABLE void changeRoles(const QString &rid, const QString &userId, const QString &channelType, RocketChatAccount::RoleType roleType); Q_INVOKABLE void rolesInRoom(const QString &roomId, const QString &channelType); @@ -243,6 +244,7 @@ DDPClient *ddp(); Q_REQUIRED_RESULT bool editingMode() const; + Q_REQUIRED_RESULT bool sortUnreadOnTop() const; Q_REQUIRED_RESULT DDPClient::LoginStatus loginStatus(); RocketChatRestApi::RestApiRequest *restApi(); @@ -407,6 +409,7 @@ MentionsFilterProxyModel *mMentionsFilterProxyModel = nullptr; EmoticonModel *mEmoticonModel = nullptr; bool mEditingMode = false; + bool mUnreadOnTop = false; }; #endif // ROCKETCHATACCOUNT_H diff --git a/src/ruqolacore/rocketchataccount.cpp b/src/ruqolacore/rocketchataccount.cpp --- a/src/ruqolacore/rocketchataccount.cpp +++ b/src/ruqolacore/rocketchataccount.cpp @@ -439,6 +439,11 @@ return mEditingMode; } +bool RocketChatAccount::sortUnreadOnTop() const +{ + return mUnreadOnTop; +} + DDPClient::LoginStatus RocketChatAccount::loginStatus() { if (mDdp) { @@ -1309,6 +1314,14 @@ } } +void RocketChatAccount::setSortUnreadOnTop(bool b) +{ + if (mUnreadOnTop != b) { + mUnreadOnTop = b; + mRoomFilterProxyModel->invalidate(); + } +} + void RocketChatAccount::kickUser(const QString &roomId, const QString &userId, const QString &channelType) { if (channelType == QStringLiteral("c")) {