From a95d5e83b4d0ab3a9bf2adef1ae4246adc317d04 Mon Sep 17 00:00:00 2001 From: Arnav Rawat Date: Thu, 11 Mar 2021 16:09:55 -0600 Subject: Support for pinned messages Fixes issue #188 --- lib/events/simplestateevents.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/events') diff --git a/lib/events/simplestateevents.h b/lib/events/simplestateevents.h index d6261a8f..f22f313d 100644 --- a/lib/events/simplestateevents.h +++ b/lib/events/simplestateevents.h @@ -71,4 +71,21 @@ public: QStringList aliases() const { return content().value; } }; REGISTER_EVENT_TYPE(RoomAliasesEvent) + +class RoomPinnedEvent + : public StateEvent> +{ +public: + DEFINE_EVENT_TYPEID("m.room.pinned_messages", RoomPinnedEvent) + + explicit RoomPinnedEvent(const QJsonObject& json) + : StateEvent(typeId(), json, QStringLiteral("pinned")) + { } + explicit RoomPinnedEvent(const QStringList& roomEvents) + : StateEvent(typeId(), matrixTypeId(), {}, + QStringLiteral("pinned"), roomEvents) + { } + QStringList pinnedEvents() const { return content().value; } +}; +REGISTER_EVENT_TYPE(RoomPinnedEvent) } // namespace Quotient -- cgit v1.2.3 From 17bf4d180297c7e87363e179b8afa79ddb15dca7 Mon Sep 17 00:00:00 2001 From: Arnav Rawat Date: Tue, 25 May 2021 14:01:51 -0500 Subject: Fixes --- lib/events/simplestateevents.h | 18 +----------------- lib/room.cpp | 16 ++++++++++++---- lib/room.h | 9 +++++++-- 3 files changed, 20 insertions(+), 23 deletions(-) (limited to 'lib/events') diff --git a/lib/events/simplestateevents.h b/lib/events/simplestateevents.h index f22f313d..c977cb6e 100644 --- a/lib/events/simplestateevents.h +++ b/lib/events/simplestateevents.h @@ -55,6 +55,7 @@ namespace EventContent { DEFINE_SIMPLE_STATE_EVENT(RoomNameEvent, "m.room.name", QString, name) DEFINE_SIMPLE_STATE_EVENT(RoomTopicEvent, "m.room.topic", QString, topic) +DEFINE_SIMPLE_STATE_EVENT(RoomPinnedEvent, "m.room.pinned_messages", QStringList, pinnedEvents) class RoomAliasesEvent : public StateEvent> { @@ -71,21 +72,4 @@ public: QStringList aliases() const { return content().value; } }; REGISTER_EVENT_TYPE(RoomAliasesEvent) - -class RoomPinnedEvent - : public StateEvent> -{ -public: - DEFINE_EVENT_TYPEID("m.room.pinned_messages", RoomPinnedEvent) - - explicit RoomPinnedEvent(const QJsonObject& json) - : StateEvent(typeId(), json, QStringLiteral("pinned")) - { } - explicit RoomPinnedEvent(const QStringList& roomEvents) - : StateEvent(typeId(), matrixTypeId(), {}, - QStringLiteral("pinned"), roomEvents) - { } - QStringList pinnedEvents() const { return content().value; } -}; -REGISTER_EVENT_TYPE(RoomPinnedEvent) } // namespace Quotient diff --git a/lib/room.cpp b/lib/room.cpp index ed07868b..2a9cc0d8 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -557,13 +557,17 @@ QString Room::canonicalAlias() const QString Room::displayName() const { return d->displayname; } -QList Room::pinnedEvents() const +QStringList Room::pinnedEventIds() const { + return d->getCurrentState()->pinnedEvents(); +} + +QVector< const Quotient::RoomEvent* > Quotient::Room::pinnedEvents() const { QStringList events = d->getCurrentState()->pinnedEvents(); - QList pinnedEvents; + QVector pinnedEvents; QStringList::iterator i; for (i = events.begin(); i != events.end(); ++i) { - auto timelineItem = findInTimeline(*i); + auto timelineItem = findInTimeline(*i); if (timelineItem != historyEdge()) pinnedEvents.append(timelineItem->event()); } @@ -1843,7 +1847,7 @@ void Room::setCanonicalAlias(const QString& newAlias) d->requestSetState(newAlias, altAliases()); } -void Room::setPinnedMessages(const QStringList& events) +void Room::setPinnedEvents(const QStringList& events) { d->requestSetState(events); } @@ -2610,6 +2614,10 @@ Room::Changes Room::processStateEvent(const RoomEvent& e) return AliasesChange; // clang-format off } + , [this] (const RoomPinnedEvent&) { + emit pinnedEventsChanged(); + return OtherChange; + } , [] (const RoomTopicEvent&) { return TopicChange; } diff --git a/lib/room.h b/lib/room.h index 60eadacc..23c0c846 100644 --- a/lib/room.h +++ b/lib/room.h @@ -85,6 +85,8 @@ class Room : public QObject { Q_PROPERTY(QStringList altAliases READ altAliases NOTIFY namesChanged) Q_PROPERTY(QString canonicalAlias READ canonicalAlias NOTIFY namesChanged) Q_PROPERTY(QString displayName READ displayName NOTIFY displaynameChanged) + Q_PROPERTY(QStringList pinnedEventIds READ pinnedEventIds WRITE setPinnedEvents + NOTIFY pinnedEventsChanged) Q_PROPERTY(QString topic READ topic NOTIFY topicChanged) Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged STORED false) @@ -191,7 +193,9 @@ public: QStringList altAliases() const; QStringList aliases() const; QString displayName() const; - QList pinnedEvents() const; + QStringList pinnedEventIds() const; + // Returns events available locally, use pinnedEventIds() for full list + QVector pinnedEvents() const; QString topic() const; QString avatarMediaId() const; QUrl avatarUrl() const; @@ -567,7 +571,7 @@ public Q_SLOTS: SetRoomStateWithKeyJob* setState(const StateEventBase& evt) const; void setName(const QString& newName); void setCanonicalAlias(const QString& newAlias); - void setPinnedMessages(const QStringList& events); + void setPinnedEvents(const QStringList& events); /// Set room aliases on the user's current server void setLocalAliases(const QStringList& aliases); void setTopic(const QString& newTopic); @@ -663,6 +667,7 @@ Q_SIGNALS: void namesChanged(Quotient::Room* room); void displaynameAboutToChange(Quotient::Room* room); void displaynameChanged(Quotient::Room* room, QString oldName); + void pinnedEventsChanged(); void topicChanged(); void avatarChanged(); void userAdded(Quotient::User* user); -- cgit v1.2.3