From 0b7bee1e2600ee80554aa85b18d30ca1964535a0 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 6 May 2016 21:31:14 +0900 Subject: Use lambda captures instead of throwing job pointers around --- room.cpp | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'room.cpp') diff --git a/room.cpp b/room.cpp index ac4275af..07c94987 100644 --- a/room.cpp +++ b/room.cpp @@ -73,6 +73,7 @@ class Room::Private: public QObject QList membersLeft; QHash lastReadEvent; QString prevBatch; + RoomMessagesJob* roomMessagesJob; bool gettingNewContent; // Convenience methods to work with the membersMap and usersLeft. addMember() @@ -86,6 +87,8 @@ class Room::Private: public QObject void renameMember(User* u, QString oldName); void removeMember(User* u); + void getPreviousContent(); + private: QString calculateDisplayname() const; QString roomNameFromMemberNames(const QList& userlist) const; @@ -100,7 +103,7 @@ Room::Room(Connection* connection, QString id) d->id = id; d->connection = connection; d->joinState = JoinState::Join; - d->gettingNewContent = false; + d->roomMessagesJob = nullptr; qDebug() << "New Room:" << id; //connection->getMembers(this); // I don't think we need this anymore in r0.0.1 @@ -373,31 +376,27 @@ void Room::updateData(const SyncRoomData& data) void Room::getPreviousContent() { - if( !d->gettingNewContent ) - { - d->gettingNewContent = true; - RoomMessagesJob* job = d->connection->getMessages(this, d->prevBatch); - connect( job, &RoomMessagesJob::result, d, &Room::Private::gotMessages ); - } + d->getPreviousContent(); } -void Room::Private::gotMessages(KJob* job) +void Room::Private::getPreviousContent() { - RoomMessagesJob* realJob = static_cast(job); - if( realJob->error() ) - { - qDebug() << realJob->errorString(); - } - else + if( !roomMessagesJob ) { - for( Event* event: realJob->events() ) - { - q->processMessageEvent(event); - emit q->newMessage(event); - } - prevBatch = realJob->end(); + roomMessagesJob = connection->getMessages(q, prevBatch); + connect( roomMessagesJob, &RoomMessagesJob::result, [=]() { + if( !roomMessagesJob->error() ) + { + for( Event* event: roomMessagesJob->events() ) + { + q->processMessageEvent(event); + emit q->newMessage(event); + } + prevBatch = roomMessagesJob->end(); + } + roomMessagesJob = nullptr; + }); } - gettingNewContent = false; } Connection* Room::connection() -- cgit v1.2.3 From 5a0e6080a6245aa2c68f254d7105f19629a5a654 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 7 May 2016 18:13:51 +0900 Subject: Minors: one fix, one cleanup --- room.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'room.cpp') diff --git a/room.cpp b/room.cpp index 07c94987..81b64c54 100644 --- a/room.cpp +++ b/room.cpp @@ -74,7 +74,6 @@ class Room::Private: public QObject QHash lastReadEvent; QString prevBatch; RoomMessagesJob* roomMessagesJob; - bool gettingNewContent; // Convenience methods to work with the membersMap and usersLeft. addMember() // and removeMember() emit respective Room:: signals after a succesful -- cgit v1.2.3