diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/events/simplestateevents.h | 1 | ||||
-rw-r--r-- | lib/room.cpp | 25 | ||||
-rw-r--r-- | lib/room.h | 7 |
3 files changed, 33 insertions, 0 deletions
diff --git a/lib/events/simplestateevents.h b/lib/events/simplestateevents.h index 9ce78609..13597979 100644 --- a/lib/events/simplestateevents.h +++ b/lib/events/simplestateevents.h @@ -51,6 +51,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 [[deprecated( "m.room.aliases events are deprecated by the Matrix spec; use" diff --git a/lib/room.cpp b/lib/room.cpp index b3438e08..edf5dcd9 100644 --- a/lib/room.cpp +++ b/lib/room.cpp @@ -558,6 +558,23 @@ QString Room::canonicalAlias() const QString Room::displayName() const { return d->displayname; } +QStringList Room::pinnedEventIds() const { + return d->getCurrentState<RoomPinnedEvent>()->pinnedEvents(); +} + +QVector< const Quotient::RoomEvent* > Quotient::Room::pinnedEvents() const +{ + QStringList events = d->getCurrentState<RoomPinnedEvent>()->pinnedEvents(); + QVector<const RoomEvent*> pinnedEvents; + QStringList::iterator i; + for (i = events.begin(); i != events.end(); ++i) { + auto timelineItem = findInTimeline(*i); + if (timelineItem != historyEdge()) + pinnedEvents.append(timelineItem->event()); + } + return pinnedEvents; +} + QString Room::displayNameForHtml() const { return displayName().toHtmlEscaped(); @@ -2133,6 +2150,10 @@ void Room::setCanonicalAlias(const QString& newAlias) d->requestSetState<RoomCanonicalAliasEvent>(newAlias, altAliases()); } +void Room::setPinnedEvents(const QStringList& events) +{ + d->requestSetState<RoomPinnedEvent>(events); +} void Room::setLocalAliases(const QStringList& aliases) { d->requestSetState<RoomCanonicalAliasEvent>(canonicalAlias(), aliases); @@ -2902,6 +2923,10 @@ Room::Changes Room::processStateEvent(const RoomEvent& e) return Change::Aliases; // clang-format off } + , [this] (const RoomPinnedEvent&) { + emit pinnedEventsChanged(); + return Change::Other; + } , [] (const RoomTopicEvent&) { return Change::Topic; } @@ -124,6 +124,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 displayNameForHtml READ displayNameForHtml NOTIFY displaynameChanged) Q_PROPERTY(QString topic READ topic NOTIFY topicChanged) Q_PROPERTY(QString avatarMediaId READ avatarMediaId NOTIFY avatarChanged @@ -253,6 +255,9 @@ public: //! Get a list of both canonical and alternative aliases QStringList aliases() const; QString displayName() const; + QStringList pinnedEventIds() const; + // Returns events available locally, use pinnedEventIds() for full list + QVector<const RoomEvent*> pinnedEvents() const; QString displayNameForHtml() const; QString topic() const; QString avatarMediaId() const; @@ -832,6 +837,7 @@ public Q_SLOTS: SetRoomStateWithKeyJob* setState(const StateEventBase& evt) const; void setName(const QString& newName); void setCanonicalAlias(const QString& newAlias); + void setPinnedEvents(const QStringList& events); /// Set room aliases on the user's current server void setLocalAliases(const QStringList& aliases); void setTopic(const QString& newTopic); @@ -938,6 +944,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); |