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)
onNewMessage: window.active ? {} : matriqueController.showMessage(roomName, content, icon)
onDataChanged: roomListForm.rawCurrentIndex = -1
}
RowLayout {

View File

@ -12,6 +12,7 @@ import "qrc:/qml/component"
Item {
property alias listModel: roomListProxyModel.sourceModel
property alias rawCurrentIndex: listView.currentIndex
readonly property int currentIndex: roomListProxyModel.mapToSource(listView.currentIndex)
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".
@ -96,6 +97,10 @@ Item {
sorters: [
RoleSorter { roleName: "category" },
RoleSorter {
roleName: "unreadCount"
sortOrder: Qt.DescendingOrder
},
StringSorter { roleName: "name" }
]
}
@ -165,7 +170,7 @@ Item {
Layout.fillWidth: true
Layout.fillHeight: true
text: name ? name : ""
text: name || "No Name"
font.pointSize: 16
elide: Text.ElideRight
wrapMode: Text.NoWrap
@ -175,7 +180,7 @@ Item {
Layout.fillWidth: true
Layout.fillHeight: true
text: topic ? topic : "No topic yet."
text: lastEvent || topic
elide: Text.ElideRight
wrapMode: Text.NoWrap
}

View File

@ -97,3 +97,10 @@ void MatriqueRoom::sendTypingNotification(bool isTyping) {
connection()->callApi<SetTypingJob>(BackgroundRequest, localUser()->id(),
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();
QString getUsersTyping();
QString lastEvent();
private:
QString m_cachedInput;
bool m_isTyping;

View File

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

View File

@ -35,6 +35,7 @@ class RoomListModel : public QAbstractListModel {
TopicRole,
CategoryRole,
UnreadCountRole,
LastEventRole
};
RoomListModel(QObject* parent = 0);
@ -70,7 +71,8 @@ class RoomListModel : public QAbstractListModel {
signals:
void connectionChanged();
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