Add direct chat handling for previews and invites

This commit is contained in:
Loren Burkholder 2021-09-06 21:45:55 -04:00
parent 8e5f91a579
commit 87bff3493d
2 changed files with 13 additions and 1 deletions

View file

@ -164,6 +164,13 @@ RoomlistModel::data(const QModelIndex &index, int role) const
return false; return false;
case Roles::Tags: case Roles::Tags:
return QStringList(); 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: default:
return {}; return {};
} }
@ -196,6 +203,11 @@ RoomlistModel::data(const QModelIndex &index, int role) const
return true; return true;
case Roles::Tags: case Roles::Tags:
return QStringList(); return QStringList();
case Roles::IsDirect:
return room.member_count == 1;
case Roles::DirectChatOtherUserId:
return QString::fromStdString(
cache::roomMembers(roomid.toStdString()).front());
default: default:
return {}; return {};
} }

View file

@ -295,7 +295,7 @@ public:
bool isEncrypted() const { return isEncrypted_; } bool isEncrypted() const { return isEncrypted_; }
crypto::Trust trustlevel() const; crypto::Trust trustlevel() const;
int roomMemberCount() const; int roomMemberCount() const;
bool isDirect() const { return roomMemberCount() <= 2; } // TODO: handle invites bool isDirect() const { return roomMemberCount() <= 2; }
QString directChatOtherUserId() const; QString directChatOtherUserId() const;
std::optional<mtx::events::collections::TimelineEvents> eventById(const QString &id) std::optional<mtx::events::collections::TimelineEvents> eventById(const QString &id)