diff --git a/lib/core/initialization_cubit/initialization_cubit.dart b/lib/core/initialization_cubit/initialization_cubit.dart index 57544ae5..a3db291f 100644 --- a/lib/core/initialization_cubit/initialization_cubit.dart +++ b/lib/core/initialization_cubit/initialization_cubit.dart @@ -12,7 +12,6 @@ class InitializationCubit extends Cubit { runInitialization() async { try { await TokenStorage.haveTokenInStorage(); - final wsUrl = await chatRepository.getWebsocket(); PusherOptions options = PusherOptions( @@ -22,12 +21,12 @@ class InitializationCubit extends Cubit { auth: PusherAuth( 'wss://' + wsUrl.host + '/app/' + wsUrl.key, headers: { - 'Authorization': 'Bearer ${TokenStorage.getTokenFromStorage()}', + 'Authorization': 'Bearer ${await TokenStorage.getTokenFromStorage()}', }, ), ); - PusherClient pusherClient = PusherClient( + PusherClient pusherClient = await PusherClient( wsUrl.key, options, autoConnect: true, @@ -37,15 +36,6 @@ class InitializationCubit extends Cubit { await pusherClient.connect(); emit(const InitializationState.success()); - - Channel channel = pusherClient.subscribe('private-direct-chat.' + '7909ea56-7822-4d5f-8892-134bc937127f'); - - channel.bind("pusher_internal:subscription_succeeded", (PusherEvent? event) { - channel.trigger("pusher_internal:subscription_succeeded", {}); - }); - - channel.registerListener('pusher:subscribe', (data) => print(data.toString())); - } catch (e) { print(e); emit(InitializationState.error(errorMessage: e.toString())); diff --git a/lib/core/token_storage.dart b/lib/core/token_storage.dart index 82d2935e..1179241b 100644 --- a/lib/core/token_storage.dart +++ b/lib/core/token_storage.dart @@ -3,7 +3,7 @@ import 'package:eatvio_app/locator_service.dart'; import 'package:hive_flutter/hive_flutter.dart'; abstract class TokenStorage { - static addTokenToDioHeader(String token) { + static _addTokenToDioHeader(String token) { sl().options.headers['Authorization'] = 'Bearer $token'; } @@ -13,20 +13,17 @@ abstract class TokenStorage { if (token == null) { return false; } else { - addTokenToDioHeader(token); + _addTokenToDioHeader(token); return true; } } - static getTokenFromStorage() async => await Hive.openBox('token') - ..get('token'); + static Future getTokenFromStorage() async => (await Hive.openBox('token')).get('token'); static saveTokenInStorage(String token) async { - await Hive.openBox('token') - ..put('token', token); - addTokenToDioHeader(token); + (await Hive.openBox('token')).put('token', token); + _addTokenToDioHeader(token); } - static removeTokenInStorage(String token) async => await Hive.openBox('token') - ..delete('token'); + static removeTokenInStorage() async => (await Hive.openBox('token')).delete('token'); } diff --git a/pubspec.yaml b/pubspec.yaml index 353e7efd..86335375 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -60,9 +60,7 @@ dependencies: # http request dio: ^5.4.3+1 # websocket - pusher_client: - git: - url: https://github.com/bihim/pusher_client + pusher_client: ^2.0.0 # photo gallery viewer + dismissible page photo_view: ^0.15.0 dismissible_page: ^1.0.2