Sort rooms by last event, not unread count.

This commit is contained in:
Black Hat 2018-09-18 20:57:38 +08:00
parent 86ea5d02c1
commit 0361432c3d
5 changed files with 14 additions and 3 deletions

View File

@ -73,7 +73,7 @@ Item {
RoleSorter { roleName: "category" },
RoleSorter {
enabled: MSettings.rearrangeByActivity
roleName: "unreadCount"
roleName: "lastActiveTime"
sortOrder: Qt.DescendingOrder
},
StringSorter { roleName: "name" }

View File

@ -163,6 +163,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
if (role == UnreadCountRole) return room->unreadCount();
if (role == HighlightCountRole) return room->highlightCount();
if (role == LastEventRole) return room->lastEvent();
if (role == LastActiveTimeRole) return room->lastActiveTime();
if (role == CurrentRoomRole) return QVariant::fromValue(room);
return QVariant();
}
@ -196,6 +197,7 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
roles[UnreadCountRole] = "unreadCount";
roles[HighlightCountRole] = "highlightCount";
roles[LastEventRole] = "lastEvent";
roles[LastActiveTimeRole] = "lastActiveTime";
roles[CurrentRoomRole] = "currentRoom";
return roles;
}

View File

@ -3,8 +3,8 @@
#include "connection.h"
#include "events/roomevent.h"
#include "spectralroom.h"
#include "room.h"
#include "spectralroom.h"
#include <QtCore/QAbstractListModel>
@ -37,6 +37,7 @@ class RoomListModel : public QAbstractListModel {
UnreadCountRole,
HighlightCountRole,
LastEventRole,
LastActiveTimeRole,
CurrentRoomRole,
};

View File

@ -140,3 +140,8 @@ void SpectralRoom::sendReply(QString userId, QString eventId,
"</blockquote></mx-reply>" + sendContent}};
postJson("m.room.message", json);
}
QDateTime SpectralRoom::lastActiveTime() {
if (timelineSize() == 0) return QDateTime();
return messageEvents().rbegin()->get()->timestamp();
}

View File

@ -35,6 +35,8 @@ class SpectralRoom : public Room {
QString lastEvent();
bool isEventHighlighted(const QMatrixClient::RoomEvent* e) const;
QDateTime lastActiveTime();
private:
QString m_cachedInput;
QSet<const QMatrixClient::RoomEvent*> highlights;
@ -59,7 +61,8 @@ class SpectralRoom : public Room {
void acceptInvitation();
void forget();
void sendTypingNotification(bool isTyping);
void sendReply(QString userId, QString eventId, QString replyContent, QString sendContent);
void sendReply(QString userId, QString eventId, QString replyContent,
QString sendContent);
};
#endif // SpectralRoom_H