Only show server notices at the top if they have unread messages
This commit is contained in:
@@ -23,11 +23,11 @@ public:
|
|||||||
* @brief Defines the room list categories a room can be assigned.
|
* @brief Defines the room list categories a room can be assigned.
|
||||||
*/
|
*/
|
||||||
enum Types {
|
enum Types {
|
||||||
ServerNotice, /**< Official messages from the server. */
|
|
||||||
Invited, /**< The user has been invited to the room. */
|
Invited, /**< The user has been invited to the room. */
|
||||||
Favorite, /**< The room is set as a favourite. */
|
Favorite, /**< The room is set as a favourite. */
|
||||||
Direct, /**< The room is a direct chat. */
|
Direct, /**< The room is a direct chat. */
|
||||||
Normal, /**< The default category for a joined room. */
|
Normal, /**< The default category for a joined room. */
|
||||||
|
ServerNotice, /**< Official messages from the server. */
|
||||||
Deprioritized, /**< The room is set as low priority. */
|
Deprioritized, /**< The room is set as low priority. */
|
||||||
Space, /**< The room is a space. */
|
Space, /**< The room is a space. */
|
||||||
AddDirect, /**< So we can show the add friend delegate. */
|
AddDirect, /**< So we can show the add friend delegate. */
|
||||||
@@ -37,7 +37,7 @@ public:
|
|||||||
|
|
||||||
static NeoChatRoomType::Types typeForRoom(const NeoChatRoom *room)
|
static NeoChatRoomType::Types typeForRoom(const NeoChatRoom *room)
|
||||||
{
|
{
|
||||||
if (room->hasAccountData(u"m.tag"_s) && room->accountData(u"m.tag"_s)->contentPart<QJsonObject>(u"tags"_s).contains(u"m.server_notice"_s)) {
|
if (room->isServerNoticeRoom()) {
|
||||||
return NeoChatRoomType::ServerNotice;
|
return NeoChatRoomType::ServerNotice;
|
||||||
}
|
}
|
||||||
if (room->isSpace()) {
|
if (room->isSpace()) {
|
||||||
|
|||||||
@@ -9,7 +9,9 @@
|
|||||||
#include "enums/neochatroomtype.h"
|
#include "enums/neochatroomtype.h"
|
||||||
#include "eventhandler.h"
|
#include "eventhandler.h"
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
|
#include "neochatroom.h"
|
||||||
#include "spacehierarchycache.h"
|
#include "spacehierarchycache.h"
|
||||||
|
#include <Quotient/qt_connection_util.h>
|
||||||
|
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
@@ -170,6 +172,9 @@ void RoomTreeModel::connectRoomSignals(NeoChatRoom *room)
|
|||||||
});
|
});
|
||||||
connect(room, &Room::unreadStatsChanged, this, [this, room] {
|
connect(room, &Room::unreadStatsChanged, this, [this, room] {
|
||||||
refreshRoomRoles(room, {ContextNotificationCountRole, HasHighlightNotificationsRole});
|
refreshRoomRoles(room, {ContextNotificationCountRole, HasHighlightNotificationsRole});
|
||||||
|
if (room->isServerNoticeRoom()) {
|
||||||
|
Q_EMIT invalidateSort();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
connect(room, &Room::avatarChanged, this, [this, room] {
|
connect(room, &Room::avatarChanged, this, [this, room] {
|
||||||
refreshRoomRoles(room, {AvatarRole});
|
refreshRoomRoles(room, {AvatarRole});
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public:
|
|||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void connectionChanged();
|
void connectionChanged();
|
||||||
|
void invalidateSort();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<NeoChatConnection> m_connection;
|
QPointer<NeoChatConnection> m_connection;
|
||||||
|
|||||||
@@ -11,6 +11,8 @@
|
|||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
#include "spacehierarchycache.h"
|
#include "spacehierarchycache.h"
|
||||||
|
|
||||||
|
#include <Quotient/eventstats.h>
|
||||||
|
|
||||||
bool SortFilterRoomTreeModel::m_showAllRoomsInHome = false;
|
bool SortFilterRoomTreeModel::m_showAllRoomsInHome = false;
|
||||||
|
|
||||||
SortFilterRoomTreeModel::SortFilterRoomTreeModel(RoomTreeModel *sourceModel, QObject *parent)
|
SortFilterRoomTreeModel::SortFilterRoomTreeModel(RoomTreeModel *sourceModel, QObject *parent)
|
||||||
@@ -22,6 +24,7 @@ SortFilterRoomTreeModel::SortFilterRoomTreeModel(RoomTreeModel *sourceModel, QOb
|
|||||||
setRecursiveFilteringEnabled(true);
|
setRecursiveFilteringEnabled(true);
|
||||||
sort(0);
|
sort(0);
|
||||||
connect(this, &SortFilterRoomTreeModel::filterTextChanged, this, &SortFilterRoomTreeModel::invalidateFilter);
|
connect(this, &SortFilterRoomTreeModel::filterTextChanged, this, &SortFilterRoomTreeModel::invalidateFilter);
|
||||||
|
connect(sourceModel, &RoomTreeModel::invalidateSort, this, &SortFilterRoomTreeModel::invalidate);
|
||||||
connect(this, &SortFilterRoomTreeModel::sourceModelChanged, this, [this]() {
|
connect(this, &SortFilterRoomTreeModel::sourceModelChanged, this, [this]() {
|
||||||
this->sourceModel()->disconnect(this);
|
this->sourceModel()->disconnect(this);
|
||||||
connect(this->sourceModel(), &QAbstractItemModel::rowsInserted, this, &SortFilterRoomTreeModel::invalidateFilter);
|
connect(this->sourceModel(), &QAbstractItemModel::rowsInserted, this, &SortFilterRoomTreeModel::invalidateFilter);
|
||||||
@@ -31,13 +34,21 @@ SortFilterRoomTreeModel::SortFilterRoomTreeModel(RoomTreeModel *sourceModel, QOb
|
|||||||
|
|
||||||
bool SortFilterRoomTreeModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
bool SortFilterRoomTreeModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
||||||
{
|
{
|
||||||
// Don't sort the top level categories.
|
const auto treeModel = dynamic_cast<RoomTreeModel *>(sourceModel());
|
||||||
if (!source_left.parent().isValid() || !source_right.parent().isValid()) {
|
if (treeModel == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto treeModel = dynamic_cast<RoomTreeModel *>(sourceModel());
|
// Don't sort the top level categories, unless there's a server notice with unread messages.
|
||||||
if (treeModel == nullptr) {
|
if (!source_left.parent().isValid() || !source_right.parent().isValid()) {
|
||||||
|
if (source_left.row() == NeoChatRoomType::ServerNotice) {
|
||||||
|
for (int i = 0; i < treeModel->rowCount(source_left); i++) {
|
||||||
|
auto room = treeModel->connection()->room(treeModel->index(i, 0, source_left).data(RoomTreeModel::RoomIdRole).toString());
|
||||||
|
if (room && room->unreadStats().notableCount > 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user