Skip to content

Commit

Permalink
TW-1193: Store/get/delete active account in persistent storage
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhhdev committed Jan 3, 2024
1 parent 8f3bb79 commit a8a2cc5
Show file tree
Hide file tree
Showing 37 changed files with 618 additions and 723 deletions.
1 change: 0 additions & 1 deletion devtools_options.yaml

This file was deleted.

33 changes: 16 additions & 17 deletions lib/config/go_routes/go_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import 'package:fluffychat/pages/settings_dashboard/settings_security/settings_s
import 'package:fluffychat/pages/settings_dashboard/settings_stories/settings_stories.dart';
import 'package:fluffychat/pages/settings_dashboard/settings_style/settings_style.dart';
import 'package:fluffychat/pages/sign_up/signup.dart';
import 'package:fluffychat/widgets/layouts/agruments/app_adaptive_scaffold_body_args.dart';
import 'package:fluffychat/widgets/log_view.dart';
import 'package:fluffychat/widgets/matrix.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -98,7 +99,9 @@ abstract class AppRoutes {
pageBuilder: (context, state) => defaultPageBuilder(
context,
TwakeId(
arg: state.extra as TwakeIdArg?,
arg: state.extra is TwakeIdArg?
? state.extra as TwakeIdArg?
: null,
),
),
redirect: loggedInRedirect,
Expand Down Expand Up @@ -148,9 +151,10 @@ abstract class AppRoutes {
state.fullPath?.startsWith('/rooms/settings') == false
? AppAdaptiveScaffold(
body: AppAdaptiveScaffoldBody(
args: AppAdaptiveScaffoldBodyArgs(
activeRoomId: state.pathParameters['roomid'],
),
activeRoomId: state.pathParameters['roomid'],
args: state.extra is AbsAppAdaptiveScaffoldBodyArgs
? state.extra as AbsAppAdaptiveScaffoldBodyArgs
: null,
),
secondaryBody: child,
)
Expand All @@ -165,17 +169,10 @@ abstract class AppRoutes {
!_responsive.isMobile(context)
? const ChatBlank()
: AppAdaptiveScaffoldBody(
args: AppAdaptiveScaffoldBodyArgs(
activeRoomId: state.pathParameters['roomid'],
client: state.extra is AppAdaptiveScaffoldBodyArgs
? (state.extra as AppAdaptiveScaffoldBodyArgs).client
: null,
isLogoutMultipleAccount:
state.extra is AppAdaptiveScaffoldBodyArgs
? (state.extra as AppAdaptiveScaffoldBodyArgs)
.isLogoutMultipleAccount
: false,
),
activeRoomId: state.pathParameters['roomid'],
args: state.extra is AbsAppAdaptiveScaffoldBodyArgs
? state.extra as AbsAppAdaptiveScaffoldBodyArgs
: null,
),
),
routes: [
Expand Down Expand Up @@ -371,7 +368,9 @@ abstract class AppRoutes {
pageBuilder: (context, state) => defaultPageBuilder(
context,
TwakeId(
arg: state.extra as TwakeIdArg?,
arg: state.extra is TwakeIdArg?
? state.extra as TwakeIdArg?
: null,
),
),
),
Expand All @@ -384,7 +383,7 @@ abstract class AppRoutes {
redirect: loggedOutRedirect,
),
GoRoute(
path: 'homeserverpicker',
path: 'addhomeserver',
pageBuilder: (context, state) => defaultPageBuilder(
context,
const HomeserverPicker(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abstract class MultipleAccountDatasource {
Future<void> storePersistActiveAccount(String userId);

Future<String?> getPersistActiveAccount();

Future<void> deletePersistActiveAccount();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart';
import 'package:fluffychat/data/local/multiple_account/multiple_account_cache_manager.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';

class MultipleAccountDatasourceImpl implements MultipleAccountDatasource {
final MultipleAccountCacheManager _multipleAccountCacheManager =
getIt.get<MultipleAccountCacheManager>();

@override
Future<String?> getPersistActiveAccount() {
return _multipleAccountCacheManager.getPersistActiveAccount();
}

@override
Future<void> storePersistActiveAccount(String userId) {
return _multipleAccountCacheManager.storePersistActiveAccount(userId);
}

@override
Future<void> deletePersistActiveAccount() {
return _multipleAccountCacheManager.deletePersistActiveAccount();
}
}
4 changes: 0 additions & 4 deletions lib/data/hive/hive_collection_tom_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,4 @@ class HiveCollectionToMDatabase {
await _collection.deleteFromDisk();
}
}

Future<void> clearCache() async {
await tomConfigurationsBox.clear();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/utils/famedlysdk_store.dart';

class MultipleAccountCacheManager {
final pres = getIt.get<Store>();

static const String persistActiveAccountKey = 'persist_active_account_key';

Future<void> storePersistActiveAccount(String userId) async {
await pres.setItem(persistActiveAccountKey, userId);
}

Future<String?> getPersistActiveAccount() async {
return await pres.getItem(persistActiveAccountKey);
}

Future<void> deletePersistActiveAccount() async {
await pres.deleteItem(persistActiveAccountKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart';

class MultipleAccountRepositoryImpl extends MultipleAccountRepository {
final MultipleAccountDatasource _multipleAccountDatasource =
getIt.get<MultipleAccountDatasource>();

@override
Future<String?> getPersistActiveAccount() {
return _multipleAccountDatasource.getPersistActiveAccount();
}

@override
Future<void> storePersistActiveAccount(String userId) {
return _multipleAccountDatasource.storePersistActiveAccount(userId);
}

@override
Future<void> deletePersistActiveAccount() {
return _multipleAccountDatasource.deletePersistActiveAccount();
}
}
15 changes: 13 additions & 2 deletions lib/di/global/get_it_initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:collection';
import 'package:fluffychat/data/datasource/localizations/localizations_datasource.dart';
import 'package:fluffychat/data/datasource/lookup_datasource.dart';
import 'package:fluffychat/data/datasource/media/media_data_source.dart';
import 'package:fluffychat/data/datasource/multiple_account/multiple_account_datasource.dart';
import 'package:fluffychat/data/datasource/phonebook_datasouce.dart';
import 'package:fluffychat/data/datasource/recovery_words_data_source.dart';
import 'package:fluffychat/data/datasource/server_search_datasource.dart';
Expand All @@ -13,10 +14,12 @@ import 'package:fluffychat/data/datasource_impl/contact/phonebook_contact_dataso
import 'package:fluffychat/data/datasource_impl/contact/tom_contacts_datasource_impl.dart';
import 'package:fluffychat/data/datasource_impl/localizations/localizations_datasource_impl.dart';
import 'package:fluffychat/data/datasource_impl/media/media_data_source_impl.dart';
import 'package:fluffychat/data/datasource_impl/multiple_account/multiple_account_datasource_impl.dart';
import 'package:fluffychat/data/datasource_impl/recovery_words_data_source_impl.dart';
import 'package:fluffychat/data/datasource_impl/server_search_datasource_impl.dart';
import 'package:fluffychat/data/datasource_impl/tom_configurations_datasource_impl.dart';
import 'package:fluffychat/data/local/localizations/language_cache_manager.dart';
import 'package:fluffychat/data/local/multiple_account/multiple_account_cache_manager.dart';
import 'package:fluffychat/data/network/contact/lookup_api.dart';
import 'package:fluffychat/data/network/contact/tom_contact_api.dart';
import 'package:fluffychat/data/network/dio_cache_option.dart';
Expand All @@ -28,6 +31,7 @@ import 'package:fluffychat/data/repository/contact/phonebook_contact_repository_
import 'package:fluffychat/data/repository/contact/tom_contact_repository_impl.dart';
import 'package:fluffychat/data/repository/localizations/localizations_repository_impl.dart';
import 'package:fluffychat/data/repository/media/media_repository_impl.dart';
import 'package:fluffychat/data/repository/multiple_account/multiple_account_repository_impl.dart';
import 'package:fluffychat/data/repository/recovery_words_repository_impl.dart';
import 'package:fluffychat/data/repository/server_search_repository_impl.dart';
import 'package:fluffychat/data/repository/tom_configurations_repository_impl.dart';
Expand All @@ -38,6 +42,7 @@ import 'package:fluffychat/domain/contact_manager/contacts_manager.dart';
import 'package:fluffychat/domain/repository/contact_repository.dart';
import 'package:fluffychat/domain/repository/localizations/localizations_repository.dart';
import 'package:fluffychat/domain/repository/lookup_repository.dart';
import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart';
import 'package:fluffychat/domain/repository/phonebook_contact_repository.dart';
import 'package:fluffychat/domain/repository/recovery_words_repository.dart';
import 'package:fluffychat/domain/repository/server_search_repository.dart';
Expand Down Expand Up @@ -87,7 +92,7 @@ class GetItInitializer {

GetItInitializer._internal();

void setUp() async {
void setUp() {
bindingGlobal();
bindingQueue();
bindingAPI();
Expand All @@ -99,9 +104,9 @@ class GetItInitializer {
}

void bindingGlobal() {
HiveDI().bind();
setupDioCache();
NetworkDI().bind();
HiveDI().bind();
NetworkConnectivityDI().bind();
getIt.registerSingleton(ResponsiveUtils());
getIt.registerSingleton(TwakeEventDispatcher());
Expand Down Expand Up @@ -149,6 +154,9 @@ class GetItInitializer {
getIt.registerFactory<ServerSearchDatasource>(
() => ServerSearchDatasourceImpl(),
);
getIt.registerFactory<MultipleAccountDatasource>(
() => MultipleAccountDatasourceImpl(),
);
}

void bindingDatasourceImpl() {
Expand Down Expand Up @@ -201,6 +209,9 @@ class GetItInitializer {
getIt.registerFactory<ServerSearchRepository>(
() => ServerSearchRepositoryImpl(),
);
getIt.registerFactory<MultipleAccountRepository>(
() => MultipleAccountRepositoryImpl(),
);
}

void bindingInteractor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abstract class MultipleAccountRepository {
Future<void> storePersistActiveAccount(String userId);

Future<String?> getPersistActiveAccount();

Future<void> deletePersistActiveAccount();
}
5 changes: 5 additions & 0 deletions lib/migrate_steps/migrate_steps.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
abstract class MigrateSteps {
const MigrateSteps();

Future<void> onMigrate(int currentVersion, int newVersion) async {}
}
25 changes: 25 additions & 0 deletions lib/migrate_steps/migrate_v6_to_v7/migrate_v6_to_v7.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:fluffychat/data/hive/hive_collection_tom_database.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/domain/repository/multiple_account/multiple_account_repository.dart';
import 'package:fluffychat/migrate_steps/migrate_steps.dart';
import 'package:matrix/matrix.dart';

class MigrateV6ToV7 extends MigrateSteps {
@override
Future<void> onMigrate(int currentVersion, int newVersion) async {
Logs().d(
'MigrateV6ToV7::onMigrate() Starting migration from v6 to v7',
);
final hiveCollectionToMDatabase =
await getIt.getAsync<HiveCollectionToMDatabase>();
await hiveCollectionToMDatabase.clear();
Logs().d(
'MigrateV6ToV7::onMigrate(): Delete ToM database success',
);
final multipleAccountRepository = getIt.get<MultipleAccountRepository>();
await multipleAccountRepository.deletePersistActiveAccount();
Logs().d(
'MigrateV6ToV7::onMigrate(): Delete persist active account success',
);
}
}
Loading

0 comments on commit a8a2cc5

Please sign in to comment.