Get direct chat jdenticons to line up

This commit is contained in:
Loren Burkholder 2021-08-13 20:05:26 -04:00
parent 7a200d7e77
commit 1fdecdcc21
6 changed files with 29 additions and 0 deletions

View file

@ -143,6 +143,8 @@ Page {
required property int notificationCount required property int notificationCount
required property bool hasLoudNotification required property bool hasLoudNotification
required property bool hasUnreadMessages required property bool hasUnreadMessages
required property int roomMemberCount
required property string directChatAvatarMxid
color: background color: background
height: avatarSize + 2 * Nheko.paddingMedium height: avatarSize + 2 * Nheko.paddingMedium
@ -237,6 +239,7 @@ Page {
width: avatarSize width: avatarSize
url: avatarUrl.replace("mxc://", "image://MxcImage/") url: avatarUrl.replace("mxc://", "image://MxcImage/")
displayName: roomName displayName: roomName
userid: roomMemberCount < 3 ? directChatAvatarMxid : roomId
Rectangle { Rectangle {
id: collapsedNotificationBubble id: collapsedNotificationBubble

View file

@ -65,6 +65,7 @@ Rectangle {
width: Nheko.avatarSize width: Nheko.avatarSize
height: Nheko.avatarSize height: Nheko.avatarSize
url: avatarUrl.replace("mxc://", "image://MxcImage/") url: avatarUrl.replace("mxc://", "image://MxcImage/")
userid: room.roomMemberCount < 3 ? room.directChatAvatarMxid : room.roomId
displayName: roomName displayName: roomName
onClicked: { onClicked: {
if (room) if (room)

View file

@ -76,6 +76,8 @@ RoomlistModel::roleNames() const
{IsSpace, "isSpace"}, {IsSpace, "isSpace"},
{Tags, "tags"}, {Tags, "tags"},
{ParentSpaces, "parentSpaces"}, {ParentSpaces, "parentSpaces"},
{RoomMemberCount, "roomMemberCount"},
{DirectChatAvatarMxid, "directChatAvatarMxid"},
}; };
} }
@ -129,6 +131,10 @@ RoomlistModel::data(const QModelIndex &index, int role) const
list.push_back(QString::fromStdString(t)); list.push_back(QString::fromStdString(t));
return list; return list;
} }
case Roles::RoomMemberCount:
return room->roomMemberCount();
case Roles::DirectChatAvatarMxid:
return room->directChatAvatarMxid();
default: default:
return {}; return {};
} }

View file

@ -65,6 +65,8 @@ public:
IsPreviewFetched, IsPreviewFetched,
Tags, Tags,
ParentSpaces, ParentSpaces,
RoomMemberCount,
DirectChatAvatarMxid,
}; };
RoomlistModel(TimelineViewManager *parent = nullptr); RoomlistModel(TimelineViewManager *parent = nullptr);

View file

@ -2073,3 +2073,16 @@ TimelineModel::roomMemberCount() const
{ {
return (int)cache::client()->memberCount(room_id_.toStdString()); return (int)cache::client()->memberCount(room_id_.toStdString());
} }
QString
TimelineModel::directChatAvatarMxid() const
{
if (roomMemberCount() < 3) {
QString id;
for (auto member : cache::getMembers(room_id_.toStdString()))
if (member.user_id != UserSettings::instance()->userId())
id = member.user_id;
return id;
} else
return "";
}

View file

@ -176,6 +176,8 @@ class TimelineModel : public QAbstractListModel
Q_PROPERTY(bool isEncrypted READ isEncrypted NOTIFY encryptionChanged) Q_PROPERTY(bool isEncrypted READ isEncrypted NOTIFY encryptionChanged)
Q_PROPERTY(bool isSpace READ isSpace CONSTANT) Q_PROPERTY(bool isSpace READ isSpace CONSTANT)
Q_PROPERTY(int trustlevel READ trustlevel NOTIFY trustlevelChanged) Q_PROPERTY(int trustlevel READ trustlevel NOTIFY trustlevelChanged)
Q_PROPERTY(
QString directChatAvatarMxid READ directChatAvatarMxid NOTIFY directChatAvatarMxidChanged)
Q_PROPERTY(InputBar *input READ input CONSTANT) Q_PROPERTY(InputBar *input READ input CONSTANT)
Q_PROPERTY(Permissions *permissions READ permissions NOTIFY permissionsChanged) Q_PROPERTY(Permissions *permissions READ permissions NOTIFY permissionsChanged)
@ -292,6 +294,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;
QString directChatAvatarMxid() const;
std::optional<mtx::events::collections::TimelineEvents> eventById(const QString &id) std::optional<mtx::events::collections::TimelineEvents> eventById(const QString &id)
{ {
@ -391,6 +394,7 @@ signals:
void roomTopicChanged(); void roomTopicChanged();
void roomAvatarUrlChanged(); void roomAvatarUrlChanged();
void roomMemberCountChanged(); void roomMemberCountChanged();
void directChatAvatarMxidChanged();
void permissionsChanged(); void permissionsChanged();
void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId); void forwardToRoom(mtx::events::collections::TimelineEvents *e, QString roomId);