Display room's latest event instead of topic when possible.

This commit is contained in:
Black Hat 2018-08-22 23:21:39 +08:00
parent e428e9f005
commit cca9467703
6 changed files with 25 additions and 3 deletions

View File

@ -16,6 +16,8 @@ Page {
onRoomAdded: MatriqueSettings.lazyLoad ? {} : room.getPreviousContent(20) onRoomAdded: MatriqueSettings.lazyLoad ? {} : room.getPreviousContent(20)
onNewMessage: window.active ? {} : matriqueController.showMessage(roomName, content, icon) onNewMessage: window.active ? {} : matriqueController.showMessage(roomName, content, icon)
onDataChanged: roomListForm.rawCurrentIndex = -1
} }
RowLayout { RowLayout {

View File

@ -12,6 +12,7 @@ import "qrc:/qml/component"
Item { Item {
property alias listModel: roomListProxyModel.sourceModel property alias listModel: roomListProxyModel.sourceModel
property alias rawCurrentIndex: listView.currentIndex
readonly property int currentIndex: roomListProxyModel.mapToSource(listView.currentIndex) readonly property int currentIndex: roomListProxyModel.mapToSource(listView.currentIndex)
readonly property var currentRoom: currentIndex != -1 ? listModel.roomAt(currentIndex) : null readonly property var currentRoom: currentIndex != -1 ? listModel.roomAt(currentIndex) : null
readonly property bool mini: MatriqueSettings.miniMode // Used as an indicator of whether the listform should be displayed as "Mini mode". readonly property bool mini: MatriqueSettings.miniMode // Used as an indicator of whether the listform should be displayed as "Mini mode".
@ -96,6 +97,10 @@ Item {
sorters: [ sorters: [
RoleSorter { roleName: "category" }, RoleSorter { roleName: "category" },
RoleSorter {
roleName: "unreadCount"
sortOrder: Qt.DescendingOrder
},
StringSorter { roleName: "name" } StringSorter { roleName: "name" }
] ]
} }
@ -165,7 +170,7 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
text: name ? name : "" text: name || "No Name"
font.pointSize: 16 font.pointSize: 16
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
@ -175,7 +180,7 @@ Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
text: topic ? topic : "No topic yet." text: lastEvent || topic
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap wrapMode: Text.NoWrap
} }

View File

@ -97,3 +97,10 @@ void MatriqueRoom::sendTypingNotification(bool isTyping) {
connection()->callApi<SetTypingJob>(BackgroundRequest, localUser()->id(), connection()->callApi<SetTypingJob>(BackgroundRequest, localUser()->id(),
id(), isTyping, 10000); id(), isTyping, 10000);
} }
QString MatriqueRoom::lastEvent() {
if (timelineSize() == 0) return "";
const RoomEvent* lastEvent = messageEvents().rbegin()->get();
return user(lastEvent->senderId())->displayname() + ": " +
lastEvent->contentJson().value("body").toString();
}

View File

@ -40,6 +40,8 @@ class MatriqueRoom : public Room {
bool hasUsersTyping(); bool hasUsersTyping();
QString getUsersTyping(); QString getUsersTyping();
QString lastEvent();
private: private:
QString m_cachedInput; QString m_cachedInput;
bool m_isTyping; bool m_isTyping;

View File

@ -62,6 +62,8 @@ void RoomListModel::connectRoomSignals(MatriqueRoom* room) {
connect(room, &Room::joinStateChanged, this, [=] { refresh(room); }); connect(room, &Room::joinStateChanged, this, [=] { refresh(room); });
connect(room, &Room::avatarChanged, this, connect(room, &Room::avatarChanged, this,
[=] { refresh(room, {AvatarRole}); }); [=] { refresh(room, {AvatarRole}); });
connect(room, &Room::addedMessages, this,
[=] { refresh(room, {LastEventRole}); });
connect(room, &QMatrixClient::Room::aboutToAddNewMessages, this, connect(room, &QMatrixClient::Room::aboutToAddNewMessages, this,
[=](QMatrixClient::RoomEventsRange eventsRange) { [=](QMatrixClient::RoomEventsRange eventsRange) {
RoomEvent* event = (eventsRange.end() - 1)->get(); RoomEvent* event = (eventsRange.end() - 1)->get();
@ -150,6 +152,7 @@ QVariant RoomListModel::data(const QModelIndex& index, int role) const {
return RoomType::Normal; return RoomType::Normal;
} }
if (role == UnreadCountRole) return room->unreadCount(); if (role == UnreadCountRole) return room->unreadCount();
if (role == LastEventRole) return room->lastEvent();
return QVariant(); return QVariant();
} }
@ -180,5 +183,6 @@ QHash<int, QByteArray> RoomListModel::roleNames() const {
roles[TopicRole] = "topic"; roles[TopicRole] = "topic";
roles[CategoryRole] = "category"; roles[CategoryRole] = "category";
roles[UnreadCountRole] = "unreadCount"; roles[UnreadCountRole] = "unreadCount";
roles[LastEventRole] = "lastEvent";
return roles; return roles;
} }

View File

@ -35,6 +35,7 @@ class RoomListModel : public QAbstractListModel {
TopicRole, TopicRole,
CategoryRole, CategoryRole,
UnreadCountRole, UnreadCountRole,
LastEventRole
}; };
RoomListModel(QObject* parent = 0); RoomListModel(QObject* parent = 0);
@ -70,7 +71,8 @@ class RoomListModel : public QAbstractListModel {
signals: signals:
void connectionChanged(); void connectionChanged();
void roomAdded(MatriqueRoom* room); void roomAdded(MatriqueRoom* room);
void newMessage(const QString& roomName, const QString& content, const QIcon& icon); void newMessage(const QString& roomName, const QString& content,
const QIcon& icon);
}; };
#endif // ROOMLISTMODEL_H #endif // ROOMLISTMODEL_H