diff --git a/packages/dart_client/lib/src/client.dart b/packages/dart_client/lib/src/client.dart index 603b9b0e..988f0f8f 100644 --- a/packages/dart_client/lib/src/client.dart +++ b/packages/dart_client/lib/src/client.dart @@ -6,7 +6,6 @@ import 'package:dio/dio.dart'; import 'package:meta/meta.dart'; import 'package:logging/logging.dart'; import 'package:rxdart/rxdart.dart'; -import 'package:shared_preferences/shared_preferences.dart'; import 'package:stream_chat/src/api/retry_policy.dart'; import 'package:stream_chat/src/event_type.dart'; import 'package:stream_chat/src/models/channel_model.dart'; @@ -37,15 +36,6 @@ typedef DecoderFunction = T Function(Map); /// own backend server. Function requires a single [userId]. typedef TokenProvider = Future Function(String userId); -/// The key used to save the userId to sharedPreferences -const String KEY_USER_ID = 'KEY_USER_ID'; - -/// The key used to save the token to sharedPreferences -const String KEY_TOKEN = 'KEY_TOKEN'; - -/// The key used to save the apiKey to sharedPreferences -const String KEY_API_KEY = 'KEY_API_KEY'; - /// Provider used to send push notifications. enum PushProvider { /// Send notifications using Google's Firebase Cloud Messaging @@ -378,11 +368,6 @@ class Client { this.token = token; _anonymous = false; - final sharedPreferences = await SharedPreferences.getInstance(); - await sharedPreferences.setString(KEY_USER_ID, user.id); - await sharedPreferences.setString(KEY_TOKEN, token); - await sharedPreferences.setString(KEY_API_KEY, apiKey); - return connect().then((event) { _connectCompleter.complete(event); return event; diff --git a/packages/dart_client/lib/src/notifications.dart b/packages/dart_client/lib/src/notifications.dart deleted file mode 100644 index 82070fd2..00000000 --- a/packages/dart_client/lib/src/notifications.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'dart:convert'; - -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:stream_chat/src/api/responses.dart'; -import 'package:stream_chat/src/models/channel_model.dart'; -import 'package:stream_chat/src/models/channel_state.dart'; -import 'package:stream_chat/src/models/message.dart'; -import 'package:meta/meta.dart'; - -import 'client.dart'; -import 'models/own_user.dart'; - -/// Utility class to handle and show notifications -class NotificationService { - static Future _handleNotification( - Message message, - ChannelModel channelModel, - Client client, - ) async { - if (message != null && client.persistenceEnabled) { - if (client?.state?.channels == null) { - final chatPersistenceClient = client.chatPersistenceClient; - await chatPersistenceClient.updateChannelState( - ChannelState( - channel: channelModel, - messages: [message], - ), - ); - } else { - final channel = client.state.channels[channelModel.cid]; - channel.state.updateChannelState( - ChannelState( - channel: channelModel, - messages: [message], - ), - ); - } - } - } - - static SharedPreferences _sharedPreferences; - - static Future _getSharedPreferences() async { - _sharedPreferences ??= await SharedPreferences.getInstance(); - return _sharedPreferences; - } - - /// Gets the message using the client without storing it in the offline storage - /// It returns an object containing the information about the message and the channel - static Future _getMessage(String messageId) async { - final sharedPreferences = await _getSharedPreferences(); - final apiKey = sharedPreferences.getString(KEY_API_KEY); - - final client = Client(apiKey); - final userId = sharedPreferences.getString(KEY_USER_ID); - final token = sharedPreferences.getString(KEY_TOKEN); - - client.state.user = OwnUser(id: userId); - client.token = token; - - final res = await client.getMessage(messageId); - return res; - } - - /// Gets the message using the client and calls a [storeMessageHandler] callback - /// with the message if the user wants to save the message in db - /// - /// It returns an object containing the information about the message and the channel - static Future getAndStoreMessage({ - @required String messageId, - @required Future Function(GetMessageResponse) storeMessageHandler, - }) async { - final getMessageResponse = await _getMessage(messageId); - await storeMessageHandler(getMessageResponse); - return getMessageResponse; - } - - /// Handles the ios message queue generated by the Notification Service Extension - static Future handleIosMessageQueue(Client client) async { - final sharedPreferences = await SharedPreferences.getInstance(); - await sharedPreferences.reload(); - final messageQueue = sharedPreferences.getStringList('messageQueue'); - if (messageQueue != null) { - messageQueue.forEach((m) { - final jsonMessage = jsonDecode(m); - - final message = Message.fromJson(jsonMessage); - final channelModel = ChannelModel.fromJson(jsonMessage['channel']); - - _handleNotification( - message, - channelModel, - client, - ); - }); - await sharedPreferences.remove('messageQueue'); - } - } -} diff --git a/packages/dart_client/lib/stream_chat.dart b/packages/dart_client/lib/stream_chat.dart index 00525b40..590175c4 100644 --- a/packages/dart_client/lib/stream_chat.dart +++ b/packages/dart_client/lib/stream_chat.dart @@ -26,5 +26,4 @@ export './src/models/own_user.dart'; export './src/models/reaction.dart'; export './src/models/read.dart'; export './src/models/user.dart'; -export './src/notifications.dart'; export './src/db/chat_persistence_client.dart'; diff --git a/packages/dart_client/pubspec.yaml b/packages/dart_client/pubspec.yaml index c55753e6..e548fcae 100644 --- a/packages/dart_client/pubspec.yaml +++ b/packages/dart_client/pubspec.yaml @@ -10,7 +10,6 @@ environment: dependencies: json_annotation: ^3.0.1 - shared_preferences: ^0.5.7+3 logging: ^0.11.4 dio: ^3.0.10 web_socket_channel: ^1.1.0