aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp89
1 files changed, 40 insertions, 49 deletions
diff --git a/room.cpp b/room.cpp
index 64ff5a85..b7c6450d 100644
--- a/room.cpp
+++ b/room.cpp
@@ -46,7 +46,7 @@ class Room::Private
public:
/** Map of user names to users. User names potentially duplicate, hence a multi-hashmap. */
typedef QMultiHash<QString, User*> members_map_t;
-
+
Private(Connection* c, const QString& id_)
: q(nullptr), connection(c), id(id_), joinState(JoinState::Join)
, roomMessagesJob(nullptr)
@@ -76,7 +76,7 @@ class Room::Private
QHash<User*, QString> lastReadEvent;
QString prevBatch;
RoomMessagesJob* roomMessagesJob;
-
+
// Convenience methods to work with the membersMap and usersLeft.
// addMember() and removeMember() emit respective Room:: signals
// after a succesful operation.
@@ -335,18 +335,12 @@ void Room::updateData(const SyncRoomData& data)
d->prevBatch = data.timelinePrevBatch;
setJoinState(data.joinState);
- for( Event* stateEvent: data.state )
- {
- processStateEvent(stateEvent);
- }
+ processStateEvents(data.state);
if (!data.timeline.empty())
{
- for( Event* e: data.timeline )
- {
- // State changes can arrive in a timeline event; so check those.
- processStateEvent(e);
- }
+ // State changes can arrive in a timeline event; so check those.
+ processStateEvents(data.timeline);
addNewMessageEvents(data.timeline);
}
@@ -421,56 +415,53 @@ void Room::doAddHistoricalMessageEvents(const Events& events)
std::front_inserter(d->messageEvents));
}
-void Room::processStateEvent(Event* event)
+void Room::processStateEvents(const Events& events)
{
- if( event->type() == EventType::RoomName )
+ for (auto event: events)
{
- if (RoomNameEvent* nameEvent = static_cast<RoomNameEvent*>(event))
+ if( event->type() == EventType::RoomName )
{
+ RoomNameEvent* nameEvent = static_cast<RoomNameEvent*>(event);
d->name = nameEvent->name();
qDebug() << "room name:" << d->name;
d->updateDisplayname();
emit namesChanged(this);
- } else
+ }
+ if( event->type() == EventType::RoomAliases )
{
- qDebug() <<
- "!!! event type is RoomName but the event is not RoomNameEvent";
+ RoomAliasesEvent* aliasesEvent = static_cast<RoomAliasesEvent*>(event);
+ d->aliases = aliasesEvent->aliases();
+ qDebug() << "room aliases:" << d->aliases;
+ // No displayname update - aliases are not used to render a displayname
+ emit namesChanged(this);
}
- }
- if( event->type() == EventType::RoomAliases )
- {
- RoomAliasesEvent* aliasesEvent = static_cast<RoomAliasesEvent*>(event);
- d->aliases = aliasesEvent->aliases();
- qDebug() << "room aliases:" << d->aliases;
- // No displayname update - aliases are not used to render a displayname
- emit namesChanged(this);
- }
- if( event->type() == EventType::RoomCanonicalAlias )
- {
- RoomCanonicalAliasEvent* aliasEvent = static_cast<RoomCanonicalAliasEvent*>(event);
- d->canonicalAlias = aliasEvent->alias();
- qDebug() << "room canonical alias:" << d->canonicalAlias;
- d->updateDisplayname();
- emit namesChanged(this);
- }
- if( event->type() == EventType::RoomTopic )
- {
- RoomTopicEvent* topicEvent = static_cast<RoomTopicEvent*>(event);
- d->topic = topicEvent->topic();
- emit topicChanged();
- }
- if( event->type() == EventType::RoomMember )
- {
- RoomMemberEvent* memberEvent = static_cast<RoomMemberEvent*>(event);
- User* u = d->connection->user(memberEvent->userId());
- u->processEvent(event);
- if( memberEvent->membership() == MembershipType::Join )
+ if( event->type() == EventType::RoomCanonicalAlias )
+ {
+ RoomCanonicalAliasEvent* aliasEvent = static_cast<RoomCanonicalAliasEvent*>(event);
+ d->canonicalAlias = aliasEvent->alias();
+ qDebug() << "room canonical alias:" << d->canonicalAlias;
+ d->updateDisplayname();
+ emit namesChanged(this);
+ }
+ if( event->type() == EventType::RoomTopic )
{
- d->addMember(u);
+ RoomTopicEvent* topicEvent = static_cast<RoomTopicEvent*>(event);
+ d->topic = topicEvent->topic();
+ emit topicChanged();
}
- else if( memberEvent->membership() == MembershipType::Leave )
+ if( event->type() == EventType::RoomMember )
{
- d->removeMember(u);
+ RoomMemberEvent* memberEvent = static_cast<RoomMemberEvent*>(event);
+ User* u = d->connection->user(memberEvent->userId());
+ u->processEvent(event);
+ if( memberEvent->membership() == MembershipType::Join )
+ {
+ d->addMember(u);
+ }
+ else if( memberEvent->membership() == MembershipType::Leave )
+ {
+ d->removeMember(u);
+ }
}
}
}