|
|
@ -648,46 +648,51 @@ ChatPage::loadStateFromCache() |
|
|
|
qDebug() << "Restored nextBatchToken" << cache_->nextBatchToken(); |
|
|
|
qDebug() << "Restored nextBatchToken" << cache_->nextBatchToken(); |
|
|
|
client_->setNextBatchToken(cache_->nextBatchToken()); |
|
|
|
client_->setNextBatchToken(cache_->nextBatchToken()); |
|
|
|
|
|
|
|
|
|
|
|
// Fetch all the joined room's state.
|
|
|
|
qRegisterMetaType<QMap<QString, RoomState>>(); |
|
|
|
auto rooms = cache_->states(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (auto it = rooms.constBegin(); it != rooms.constEnd(); ++it) { |
|
|
|
QtConcurrent::run(cache_.data(), &Cache::states); |
|
|
|
auto roomState = QSharedPointer<RoomState>(new RoomState(it.value())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Clean up and prepare state for use.
|
|
|
|
connect(cache_.data(), &Cache::statesLoaded, this, [this](QMap<QString, RoomState> rooms) { |
|
|
|
roomState->removeLeaveMemberships(); |
|
|
|
qDebug() << "Cache data loaded"; |
|
|
|
roomState->resolveName(); |
|
|
|
|
|
|
|
roomState->resolveAvatar(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save the current room state.
|
|
|
|
for (auto it = rooms.constBegin(); it != rooms.constEnd(); ++it) { |
|
|
|
roomStates_.insert(it.key(), roomState); |
|
|
|
auto roomState = QSharedPointer<RoomState>(new RoomState(it.value())); |
|
|
|
|
|
|
|
|
|
|
|
// Create or restore the settings for this room.
|
|
|
|
// Clean up and prepare state for use.
|
|
|
|
roomSettings_.insert(it.key(), |
|
|
|
roomState->removeLeaveMemberships(); |
|
|
|
QSharedPointer<RoomSettings>(new RoomSettings(it.key()))); |
|
|
|
roomState->resolveName(); |
|
|
|
|
|
|
|
roomState->resolveAvatar(); |
|
|
|
|
|
|
|
|
|
|
|
// Resolve user avatars.
|
|
|
|
// Save the current room state.
|
|
|
|
for (const auto membership : roomState->memberships) { |
|
|
|
roomStates_.insert(it.key(), roomState); |
|
|
|
updateUserDisplayName(membership.second); |
|
|
|
|
|
|
|
updateUserAvatarUrl(membership.second); |
|
|
|
// Create or restore the settings for this room.
|
|
|
|
|
|
|
|
roomSettings_.insert( |
|
|
|
|
|
|
|
it.key(), QSharedPointer<RoomSettings>(new RoomSettings(it.key()))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Resolve user avatars.
|
|
|
|
|
|
|
|
for (const auto membership : roomState->memberships) { |
|
|
|
|
|
|
|
updateUserDisplayName(membership.second); |
|
|
|
|
|
|
|
updateUserAvatarUrl(membership.second); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initializing empty timelines.
|
|
|
|
// Initializing empty timelines.
|
|
|
|
view_manager_->initialize(rooms.keys()); |
|
|
|
view_manager_->initialize(rooms.keys()); |
|
|
|
|
|
|
|
|
|
|
|
// Initialize room list from the restored state and settings.
|
|
|
|
// Initialize room list from the restored state and settings.
|
|
|
|
room_list_->setInitialRooms(roomSettings_, roomStates_); |
|
|
|
room_list_->setInitialRooms(roomSettings_, roomStates_); |
|
|
|
room_list_->syncInvites(cache_->invites()); |
|
|
|
room_list_->syncInvites(cache_->invites()); |
|
|
|
|
|
|
|
|
|
|
|
// Check periodically if the timelines have been loaded.
|
|
|
|
// Check periodically if the timelines have been loaded.
|
|
|
|
consensusTimer_->start(CONSENSUS_TIMEOUT); |
|
|
|
consensusTimer_->start(CONSENSUS_TIMEOUT); |
|
|
|
|
|
|
|
|
|
|
|
// Show the content if consensus can't be achieved.
|
|
|
|
// Show the content if consensus can't be achieved.
|
|
|
|
showContentTimer_->start(SHOW_CONTENT_TIMEOUT); |
|
|
|
showContentTimer_->start(SHOW_CONTENT_TIMEOUT); |
|
|
|
|
|
|
|
|
|
|
|
// Start receiving events.
|
|
|
|
// Start receiving events.
|
|
|
|
client_->sync(); |
|
|
|
client_->sync(); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
|