From 87bff3493d9c884eff09d5653e5df29b3489616d Mon Sep 17 00:00:00 2001 From: Loren Burkholder Date: Mon, 6 Sep 2021 21:45:55 -0400 Subject: [PATCH] Add direct chat handling for previews and invites --- src/timeline/RoomlistModel.cpp | 12 ++++++++++++ src/timeline/TimelineModel.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/timeline/RoomlistModel.cpp b/src/timeline/RoomlistModel.cpp index 094b0df6..a423090c 100644 --- a/src/timeline/RoomlistModel.cpp +++ b/src/timeline/RoomlistModel.cpp @@ -164,6 +164,13 @@ RoomlistModel::data(const QModelIndex &index, int role) const return false; case Roles::Tags: return QStringList(); + case Roles::IsDirect: + return room.member_count == 1; + case Roles::DirectChatOtherUserId: + // if this is a direct chat, the front member is correct; otherwise, + // it won't be used anyway + return QString::fromStdString( + cache::roomMembers(roomid.toStdString()).front()); default: return {}; } @@ -196,6 +203,11 @@ RoomlistModel::data(const QModelIndex &index, int role) const return true; case Roles::Tags: return QStringList(); + case Roles::IsDirect: + return room.member_count == 1; + case Roles::DirectChatOtherUserId: + return QString::fromStdString( + cache::roomMembers(roomid.toStdString()).front()); default: return {}; } diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index 46e146b3..66e0622e 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -295,7 +295,7 @@ public: bool isEncrypted() const { return isEncrypted_; } crypto::Trust trustlevel() const; int roomMemberCount() const; - bool isDirect() const { return roomMemberCount() <= 2; } // TODO: handle invites + bool isDirect() const { return roomMemberCount() <= 2; } QString directChatOtherUserId() const; std::optional eventById(const QString &id)