Add inviter to the invite reason

fixes #622
This commit is contained in:
Nicolas Werner 2023-06-10 00:49:49 +02:00
parent c7b78ca182
commit 0dbc9444c3
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
6 changed files with 102 additions and 4 deletions

View file

@ -283,6 +283,29 @@ Item {
onClicked: TimelineManager.openLeaveRoomDialog(room.roomId) onClicked: TimelineManager.openLeaveRoomDialog(room.roomId)
} }
RowLayout {
Layout.alignment: Qt.AlignHCenter
spacing: Nheko.paddingMedium
visible: roomPreview && roomPreview.isInvite && reasonField.showReason
MatrixText {
text: qsTr("Invited by %1 (%2)").arg(TimelineManager.escapeEmoji(inviterAvatar.displayName)).arg(TimelineManager.escapeEmoji(TimelineManager.htmlEscape(inviterAvatar.userid)))
}
Avatar {
id: inviterAvatar
Layout.alignment: Qt.AlignHCenter
displayName: roomPreview?.inviterDisplayName ?? ""
enabled: true
height: 48
roomid: preview.roomId
url: (roomPreview?.inviterAvatarUrl ?? "").replace("mxc://", "image://MxcImage/")
userid: roomPreview?.inviterUserId ?? ""
width: 48
onClicked: TimelineManager.openGlobalUserProfile(roomPreview.inviterUserId)
}
}
ScrollView { ScrollView {
id: reasonField id: reasonField
@ -312,7 +335,7 @@ Item {
Layout.leftMargin: Nheko.paddingLarge Layout.leftMargin: Nheko.paddingLarge
Layout.rightMargin: Nheko.paddingLarge Layout.rightMargin: Nheko.paddingLarge
text: reasonField.showReason ? qsTr("Hide invite reason") : qsTr("Show invite reason") text: reasonField.showReason ? qsTr("Hide invite reason") : qsTr("Show invite reason")
visible: preview.reason !== "" visible: roomPreview && roomPreview.isInvite
onClicked: { onClicked: {
reasonField.showReason = !reasonField.showReason; reasonField.showReason = !reasonField.showReason;

View file

@ -2128,8 +2128,16 @@ Cache::saveInvite(lmdb::txn &txn,
auto display_name = auto display_name =
msg->content.display_name.empty() ? msg->state_key : msg->content.display_name; msg->content.display_name.empty() ? msg->state_key : msg->content.display_name;
MemberInfo tmp{ std::string inviter = "";
display_name, msg->content.avatar_url, msg->content.reason, msg->content.is_direct}; if (msg->content.membership == mtx::events::state::Membership::Invite) {
inviter = msg->sender;
}
MemberInfo tmp{display_name,
msg->content.avatar_url,
inviter,
msg->content.reason,
msg->content.is_direct};
membersdb.put(txn, msg->state_key, nlohmann::json(tmp).dump()); membersdb.put(txn, msg->state_key, nlohmann::json(tmp).dump());
} else { } else {
@ -5173,6 +5181,8 @@ to_json(nlohmann::json &j, const MemberInfo &info)
{ {
j["name"] = info.name; j["name"] = info.name;
j["avatar_url"] = info.avatar_url; j["avatar_url"] = info.avatar_url;
if (!info.inviter.empty())
j["inviter"] = info.inviter;
if (info.is_direct) if (info.is_direct)
j["is_direct"] = info.is_direct; j["is_direct"] = info.is_direct;
if (!info.reason.empty()) if (!info.reason.empty())
@ -5186,6 +5196,7 @@ from_json(const nlohmann::json &j, MemberInfo &info)
info.avatar_url = j.value("avatar_url", ""); info.avatar_url = j.value("avatar_url", "");
info.is_direct = j.value("is_direct", false); info.is_direct = j.value("is_direct", false);
info.reason = j.value("reason", ""); info.reason = j.value("reason", "");
info.inviter = j.value("inviter", "");
} }
void void

View file

@ -117,6 +117,7 @@ struct MemberInfo
{ {
std::string name; std::string name;
std::string avatar_url; std::string avatar_url;
std::string inviter = "";
std::string reason = ""; std::string reason = "";
bool is_direct = false; bool is_direct = false;
}; };

View file

@ -394,8 +394,19 @@ private:
auto display_name = auto display_name =
e->content.display_name.empty() ? e->state_key : e->content.display_name; e->content.display_name.empty() ? e->state_key : e->content.display_name;
std::string inviter = "";
if (e->content.membership == mtx::events::state::Membership::Invite) {
inviter = e->sender;
}
// Lightweight representation of a member. // Lightweight representation of a member.
MemberInfo tmp{display_name, e->content.avatar_url, e->content.reason}; MemberInfo tmp{
display_name,
e->content.avatar_url,
inviter,
e->content.reason,
e->content.is_direct,
};
membersdb.put(txn, e->state_key, nlohmann::json(tmp).dump()); membersdb.put(txn, e->state_key, nlohmann::json(tmp).dump());
break; break;

View file

@ -1235,3 +1235,49 @@ FilteredRoomlistModel::previousRoom()
} }
} }
} }
QString
RoomPreview::inviterAvatarUrl() const
{
if (isInvite_) {
auto self = cache::client()->getInviteMember(roomid_.toStdString(),
http::client()->user_id().to_string());
if (self && !self->inviter.empty()) {
auto other = cache::client()->getInviteMember(roomid_.toStdString(), self->inviter);
if (other && other->avatar_url.starts_with("mxc://")) {
return QString::fromStdString(other->avatar_url);
}
}
}
return QString();
}
QString
RoomPreview::inviterDisplayName() const
{
if (isInvite_) {
auto self = cache::client()->getInviteMember(roomid_.toStdString(),
http::client()->user_id().to_string());
if (self && !self->inviter.empty()) {
auto other = cache::client()->getInviteMember(roomid_.toStdString(), self->inviter);
if (other) {
return QString::fromStdString(other->name).toHtmlEscaped();
}
}
}
return QString();
}
QString
RoomPreview::inviterUserId() const
{
if (isInvite_) {
auto self = cache::client()->getInviteMember(roomid_.toStdString(),
http::client()->user_id().to_string());
if (self && !self->inviter.empty()) {
return QString::fromStdString(self->inviter);
}
}
return QString();
}

View file

@ -31,6 +31,9 @@ class RoomPreview
Q_PROPERTY(QString roomTopic READ roomTopic CONSTANT) Q_PROPERTY(QString roomTopic READ roomTopic CONSTANT)
Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl CONSTANT) Q_PROPERTY(QString roomAvatarUrl READ roomAvatarUrl CONSTANT)
Q_PROPERTY(QString reason READ reason CONSTANT) Q_PROPERTY(QString reason READ reason CONSTANT)
Q_PROPERTY(QString inviterAvatarUrl READ inviterAvatarUrl CONSTANT)
Q_PROPERTY(QString inviterDisplayName READ inviterDisplayName CONSTANT)
Q_PROPERTY(QString inviterUserId READ inviterUserId CONSTANT)
Q_PROPERTY(bool isInvite READ isInvite CONSTANT) Q_PROPERTY(bool isInvite READ isInvite CONSTANT)
Q_PROPERTY(bool isFetched READ isFetched CONSTANT) Q_PROPERTY(bool isFetched READ isFetched CONSTANT)
@ -42,6 +45,9 @@ public:
QString roomTopic() const { return roomTopic_; } QString roomTopic() const { return roomTopic_; }
QString roomAvatarUrl() const { return roomAvatarUrl_; } QString roomAvatarUrl() const { return roomAvatarUrl_; }
QString reason() const { return reason_; } QString reason() const { return reason_; }
QString inviterAvatarUrl() const;
QString inviterDisplayName() const;
QString inviterUserId() const;
bool isInvite() const { return isInvite_; } bool isInvite() const { return isInvite_; }
bool isFetched() const { return isFetched_; } bool isFetched() const { return isFetched_; }