diff --git a/src/app/qml/InvitationView.qml b/src/app/qml/InvitationView.qml index 52d9f44fe..e9afcc93e 100644 --- a/src/app/qml/InvitationView.qml +++ b/src/app/qml/InvitationView.qml @@ -16,6 +16,7 @@ ColumnLayout { required property NeoChatRoom currentRoom readonly property var invitingMember: currentRoom.member(currentRoom.invitingUserId()) + readonly property string inviteTimestamp: root.currentRoom.inviteTimestamp.toLocaleString(Qt.locale(), Locale.ShortFormat) spacing: Kirigami.Units.smallSpacing @@ -39,7 +40,7 @@ ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { - text: i18nc("@info:label", "%1 has invited you to join", root.invitingMember.displayName) + text: i18nc("@info:label 'Username' has invited you to this room at 'timestamp'.", "%1 has invited you to this room at %2.", root.invitingMember.displayName, root.inviteTimestamp) Layout.alignment: Qt.AlignHCenter } @@ -67,7 +68,7 @@ ColumnLayout { } QQC2.Label { - text: i18nc("@info:label", "This user is inviting you to chat.") + text: i18nc("@info:label This user invited you to chat at 'timestamp'", "This user invited you to chat at %1.", root.inviteTimestamp) Layout.alignment: Qt.AlignHCenter } diff --git a/src/libneochat/neochatroom.cpp b/src/libneochat/neochatroom.cpp index 20389350e..43d47be42 100644 --- a/src/libneochat/neochatroom.cpp +++ b/src/libneochat/neochatroom.cpp @@ -124,6 +124,7 @@ NeoChatRoom::NeoChatRoom(Connection *connection, QString roomId, JoinState joinS updatePushNotificationState(u"m.push_rules"_s); Q_EMIT canEncryptRoomChanged(); + Q_EMIT inviteTimestampChanged(); }, Qt::SingleShotConnection); connect(this, &Room::changed, this, [this] { @@ -1665,6 +1666,15 @@ QString NeoChatRoom::invitingUserId() const return event->senderId(); } +QDateTime NeoChatRoom::inviteTimestamp() const +{ + auto event = currentState().get(connection()->userId()); + if (!event) { + return {}; + } + return event->originTimestamp(); +} + void NeoChatRoom::setRoomState(const QString &type, const QString &stateKey, const QByteArray &content) { setState(type, stateKey, QJsonDocument::fromJson(content).object()); diff --git a/src/libneochat/neochatroom.h b/src/libneochat/neochatroom.h index 8eff6fef8..9fe2cc696 100644 --- a/src/libneochat/neochatroom.h +++ b/src/libneochat/neochatroom.h @@ -192,6 +192,11 @@ class NeoChatRoom : public Quotient::Room */ Q_PROPERTY(ChatBarCache *threadCache READ threadCache CONSTANT) + /** + * @brief When the current user was invited to the room. + */ + Q_PROPERTY(QDateTime inviteTimestamp READ inviteTimestamp NOTIFY inviteTimestampChanged) + public: explicit NeoChatRoom(Quotient::Connection *connection, QString roomId, Quotient::JoinState joinState = {}); @@ -525,6 +530,11 @@ public: */ Q_INVOKABLE QString invitingUserId() const; + /** + * If we're invited to this room, the timestamp when we were invited in. Undefined in other cases. + */ + Q_INVOKABLE QDateTime inviteTimestamp() const; + /** * @brief Return the cached file transfer information for the event. * @@ -621,6 +631,7 @@ Q_SIGNALS: void maxRoomVersionChanged(); void extraEventLoaded(const QString &eventId); void extraEventNotFound(const QString &eventId); + void inviteTimestampChanged(); /** * @brief Request a message be shown to the user of the given type.