aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-11-23 15:38:59 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-11-23 15:55:16 +0900
commit49ad563550ba9d2d03fc7a519ccb857a6d08791c (patch)
treec4beac95c51d29c78ca4826898a0d85344769268 /lib
parent64799eaf667840c7f81d80810508d948f64f97d6 (diff)
downloadlibquotient-49ad563550ba9d2d03fc7a519ccb857a6d08791c.tar.gz
libquotient-49ad563550ba9d2d03fc7a519ccb857a6d08791c.zip
Room/Connection: don't save the just loaded room cache
Diffstat (limited to 'lib')
-rw-r--r--lib/connection.cpp6
-rw-r--r--lib/connection.h2
-rw-r--r--lib/room.cpp5
-rw-r--r--lib/room.h17
4 files changed, 16 insertions, 14 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 53835a80..9372acd5 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -316,7 +316,7 @@ void Connection::sync(int timeout)
});
}
-void Connection::onSyncSuccess(SyncData &&data) {
+void Connection::onSyncSuccess(SyncData &&data, bool fromCache) {
d->data->setLastEvent(data.nextBatch());
for (auto&& roomData: data.takeRoomData())
{
@@ -337,7 +337,7 @@ void Connection::onSyncSuccess(SyncData &&data) {
}
if ( auto* r = provideRoom(roomData.roomId, roomData.joinState) )
{
- r->updateData(std::move(roomData));
+ r->updateData(std::move(roomData), fromCache);
if (d->firstTimeRooms.removeOne(r))
emit loadedRoomState(r);
}
@@ -1156,7 +1156,7 @@ void Connection::loadState()
// TODO: to handle load failures, instead of the above block:
// 1. Do initial sync on failed rooms without saving the nextBatch token
// 2. Do the sync across all rooms as normal
- onSyncSuccess(std::move(sync));
+ onSyncSuccess(std::move(sync), true);
qCDebug(PROFILER) << "*** Cached state for" << userId() << "loaded in" << et;
}
diff --git a/lib/connection.h b/lib/connection.h
index 20a1f47e..32533b6e 100644
--- a/lib/connection.h
+++ b/lib/connection.h
@@ -677,7 +677,7 @@ namespace QMatrixClient
/**
* Completes loading sync data.
*/
- void onSyncSuccess(SyncData &&data);
+ void onSyncSuccess(SyncData &&data, bool fromCache = false);
private:
class Private;
diff --git a/lib/room.cpp b/lib/room.cpp
index 2d958dca..22a0d585 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -1106,7 +1106,7 @@ QString Room::roomMembername(const QString& userId) const
return roomMembername(user(userId));
}
-void Room::updateData(SyncRoomData&& data)
+void Room::updateData(SyncRoomData&& data, bool fromCache)
{
if( d->prevBatch.isEmpty() )
d->prevBatch = data.timelinePrevBatch;
@@ -1172,7 +1172,8 @@ void Room::updateData(SyncRoomData&& data)
if (roomChanges != Change::NoChange)
{
emit changed(roomChanges);
- connection()->saveRoomState(this);
+ if (!fromCache)
+ connection()->saveRoomState(this);
}
}
diff --git a/lib/room.h b/lib/room.h
index ab8298d4..480de6fe 100644
--- a/lib/room.h
+++ b/lib/room.h
@@ -456,14 +456,6 @@ namespace QMatrixClient
/// The room is about to be deleted
void beforeDestruction(Room*);
- public: // Used by Connection - not a part of the client API
- QJsonObject toJson() const;
- void updateData(SyncRoomData&& data );
-
- // Clients should use Connection::joinRoom() and Room::leaveRoom()
- // to change the room state
- void setJoinState( JoinState state );
-
protected:
/// Returns true if any of room names/aliases has changed
virtual Changes processStateEvent(const RoomEvent& e);
@@ -473,10 +465,19 @@ namespace QMatrixClient
virtual void onAddHistoricalTimelineEvents(rev_iter_t /*from*/) { }
virtual void onRedaction(const RoomEvent& /*prevEvent*/,
const RoomEvent& /*after*/) { }
+ virtual QJsonObject toJson() const;
+ virtual void updateData(SyncRoomData&& data, bool fromCache = false);
private:
+ friend class Connection;
+
class Private;
Private* d;
+
+ // This is called from Connection, reflecting a state change that
+ // arrived from the server. Clients should use
+ // Connection::joinRoom() and Room::leaveRoom() to change the state.
+ void setJoinState(JoinState state);
};
class MemberSorter