Skip to content

Commit

Permalink
fix(save drive state) validate last logged in user before clean database
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagocarvalhodev committed Jul 26, 2022
1 parent 7c95785 commit a9cfc99
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/blocs/sync/sync_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ class SyncCubit extends Cubit<SyncState> {

syncFormatedPrint('Current block height number $currentBlockHeight');

drives.forEach((drive) {
syncFormatedPrint('Drive last block height: ${drive.lastBlockHeight!}');
});

final driveSyncProcesses = drives.map((drive) => _syncDrive(
drive.id,
lastBlockHeight: calculateSyncLastBlockHeight(
Expand Down Expand Up @@ -560,6 +564,7 @@ class SyncCubit extends Cubit<SyncState> {
200 ~/ (_syncProgress.drivesCount - _syncProgress.drivesSynced);
var currentDriveEntitiesSynced = 0;
var driveSyncProgress = 0.0;
syncFormatedPrint('_syncSecondPhase: $currentBlockHeight');

syncFormatedPrint(
'number of drives at get metadata phase : ${_syncProgress.numberOfDrivesAtGetMetadataPhase}');
Expand Down Expand Up @@ -623,6 +628,8 @@ class SyncCubit extends Cubit<SyncState> {

// Handle the last page of newEntities, i.e; There's nothing more to sync
if (newEntities.length < pageCount) {
syncFormatedPrint(
'Saving last block height at _paginateProcess. $currentBlockHeight');
// Reset the sync cursor after every sync to pick up files from other instances of the app.
// (Different tab, different window, mobile, desktop etc)
await _driveDao.writeToDrive(DrivesCompanion(
Expand Down
7 changes: 6 additions & 1 deletion lib/pages/app_router_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ class AppRouterDelegate extends RouterDelegate<AppRoutePath>
// TODO: Find a better place to do this
final lastLoggedInUser =
state is ProfileLoggedIn ? state.walletAddress : null;
context.read<DriveDao>().deleteSharedPrivateDrives(lastLoggedInUser);
if (lastLoggedInUser != null) {
print('deleteSharedPrivateDrives $lastLoggedInUser');
context
.read<DriveDao>()
.deleteSharedPrivateDrives(lastLoggedInUser);
}
},
builder: (context, state) {
Widget? shell;
Expand Down

0 comments on commit a9cfc99

Please sign in to comment.