diff options
author | Felix Rohrbach <fxrh@gmx.de> | 2016-05-08 18:59:11 +0200 |
---|---|---|
committer | Felix Rohrbach <fxrh@gmx.de> | 2016-05-08 18:59:11 +0200 |
commit | 1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca (patch) | |
tree | fa0f4aded71f27974c9922bd587ba78774ade46c /room.cpp | |
parent | fc95edb7a63bcacb02418c55e15a1aa21ac080cd (diff) | |
parent | 5a0e6080a6245aa2c68f254d7105f19629a5a654 (diff) | |
download | libquotient-1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca.tar.gz libquotient-1cd8802c73ee3c0cc0095f8be30a9bbf3442c3ca.zip |
Merge pull request #5 from KitsuneRal/basejob-improvement
Basejob improvement
Diffstat (limited to 'room.cpp')
-rw-r--r-- | room.cpp | 42 |
1 files changed, 20 insertions, 22 deletions
@@ -73,7 +73,7 @@ class Room::Private: public QObject QList<User*> membersLeft; QHash<User*, QString> lastReadEvent; QString prevBatch; - bool gettingNewContent; + RoomMessagesJob* roomMessagesJob; // Convenience methods to work with the membersMap and usersLeft. addMember() // and removeMember() emit respective Room:: signals after a succesful @@ -86,6 +86,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<User*>& userlist) const; @@ -100,7 +102,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 +375,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<RoomMessagesJob*>(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() |