aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/events/simplestateevents.h18
-rw-r--r--lib/room.cpp16
-rw-r--r--lib/room.h9
3 files changed, 20 insertions, 23 deletions
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<EventContent::SimpleContent<QStringList>> {
@@ -71,21 +72,4 @@ public:
QStringList aliases() const { return content().value; }
};
REGISTER_EVENT_TYPE(RoomAliasesEvent)
-
-class RoomPinnedEvent
- : public StateEvent<EventContent::SimpleContent<QStringList>>
-{
-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<const RoomEvent*> Room::pinnedEvents() const
+QStringList Room::pinnedEventIds() const {
+ return d->getCurrentState<RoomPinnedEvent>()->pinnedEvents();
+}
+
+QVector< const Quotient::RoomEvent* > Quotient::Room::pinnedEvents() const
{
QStringList events = d->getCurrentState<RoomPinnedEvent>()->pinnedEvents();
- QList<const RoomEvent*> pinnedEvents;
+ QVector<const RoomEvent*> 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<RoomCanonicalAliasEvent>(newAlias, altAliases());
}
-void Room::setPinnedMessages(const QStringList& events)
+void Room::setPinnedEvents(const QStringList& events)
{
d->requestSetState<RoomPinnedEvent>(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<const RoomEvent*> pinnedEvents() const;
+ QStringList pinnedEventIds() const;
+ // Returns events available locally, use pinnedEventIds() for full list
+ QVector<const RoomEvent*> 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);