aboutsummaryrefslogtreecommitdiff
path: root/room.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'room.cpp')
-rw-r--r--room.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/room.cpp b/room.cpp
index ac4275af..81b64c54 100644
--- a/room.cpp
+++ b/room.cpp
@@ -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()