From 44b4358c3d514d2fd2f42d02841e825fe5025b59 Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Fri, 23 Jul 2021 14:53:43 +0530 Subject: [PATCH] chore(llc): minor changes Signed-off-by: xsahil03x --- packages/stream_chat/lib/src/client/client.dart | 13 +++++++------ .../lib/src/core/http/stream_http_client.dart | 2 +- .../src/core/http/stream_http_client_options.dart | 4 ++-- packages/stream_chat/lib/src/ws/websocket.dart | 6 +++--- packages/stream_chat/lib/version.dart | 6 ------ .../core/http/stream_http_client_options_test.dart | 12 ++++-------- 6 files changed, 17 insertions(+), 26 deletions(-) diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index 3d314063..41fe2e7a 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -25,6 +25,7 @@ import 'package:stream_chat/src/core/models/member.dart'; import 'package:stream_chat/src/core/models/message.dart'; import 'package:stream_chat/src/core/models/own_user.dart'; import 'package:stream_chat/src/core/models/user.dart'; +import 'package:stream_chat/src/core/platform_detector/platform_detector.dart'; import 'package:stream_chat/src/core/util/utils.dart'; import 'package:stream_chat/src/db/chat_persistence_client.dart'; import 'package:stream_chat/src/event_type.dart'; @@ -43,6 +44,10 @@ final _levelEmojiMapper = { Level.SEVERE: '🚨', }; +final _userAgent = 'stream-chat-dart-client-' + '${CurrentPlatform.name}-' + '${PACKAGE_VERSION.split('+')[0]}'; + /// The official Dart client for Stream Chat, /// a service for building chat applications. /// This library can be used on any Dart project and on both mobile and web apps @@ -81,9 +86,7 @@ class StreamChatClient { location: location, connectTimeout: connectTimeout, receiveTimeout: receiveTimeout, - headers: { - 'X-Stream-Client': userAgent, - }, + headers: {'X-Stream-Client': _userAgent}, ); _chatApi = chatApi ?? @@ -103,9 +106,7 @@ class StreamChatClient { tokenManager: _tokenManager, handler: handleEvent, logger: detachedLogger('🔌'), - queryParams: { - 'X-Stream-Client': userAgent, - }, + queryParameters: {'X-Stream-Client': _userAgent}, ); _retryPolicy = retryPolicy ?? diff --git a/packages/stream_chat/lib/src/core/http/stream_http_client.dart b/packages/stream_chat/lib/src/core/http/stream_http_client.dart index 900b71e9..c19cdb8a 100644 --- a/packages/stream_chat/lib/src/core/http/stream_http_client.dart +++ b/packages/stream_chat/lib/src/core/http/stream_http_client.dart @@ -33,7 +33,7 @@ class StreamHttpClient { ..options.connectTimeout = _options.connectTimeout.inMilliseconds ..options.queryParameters = { 'api_key': apiKey, - ..._options.queryParams, + ..._options.queryParameters, } ..options.headers = { 'Content-Type': 'application/json', diff --git a/packages/stream_chat/lib/src/core/http/stream_http_client_options.dart b/packages/stream_chat/lib/src/core/http/stream_http_client_options.dart index a2fe22e8..01cdb12e 100644 --- a/packages/stream_chat/lib/src/core/http/stream_http_client_options.dart +++ b/packages/stream_chat/lib/src/core/http/stream_http_client_options.dart @@ -10,7 +10,7 @@ class StreamHttpClientOptions { this.location, this.connectTimeout = const Duration(seconds: 6), this.receiveTimeout = const Duration(seconds: 6), - this.queryParams = const {}, + this.queryParameters = const {}, this.headers = const {}, }) : _baseUrl = baseUrl ?? _defaultBaseURL; @@ -40,7 +40,7 @@ class StreamHttpClientOptions { /// /// The value can be overridden per parameter by adding a [MultiParam] /// object wrapping the actual List value and the desired format. - final Map queryParams; + final Map queryParameters; /// Http request headers. /// The keys of initial headers will be converted to lowercase, diff --git a/packages/stream_chat/lib/src/ws/websocket.dart b/packages/stream_chat/lib/src/ws/websocket.dart index 53529d55..b26d811e 100644 --- a/packages/stream_chat/lib/src/ws/websocket.dart +++ b/packages/stream_chat/lib/src/ws/websocket.dart @@ -41,14 +41,14 @@ class WebSocket with TimerHelper { this.reconnectionMonitorInterval = 10, this.healthCheckInterval = 20, this.reconnectionMonitorTimeout = 40, - this.queryParams = const {}, + this.queryParameters = const {}, }) : _logger = logger; /// final String apiKey; /// Additional query parameters to be added to the websocket url - final Map queryParams; + final Map queryParameters; /// WS base url final String baseUrl; @@ -160,7 +160,7 @@ class WebSocket with TimerHelper { 'api_key': apiKey, 'authorization': token.rawValue, 'stream-auth-type': token.authType.raw, - ...queryParams, + ...queryParameters, }; final scheme = baseUrl.startsWith('https') ? 'wss' : 'ws'; final host = baseUrl.replaceAll(RegExp(r'(^\w+:|^)\/\/'), ''); diff --git a/packages/stream_chat/lib/version.dart b/packages/stream_chat/lib/version.dart index d3314525..d09a2ccc 100644 --- a/packages/stream_chat/lib/version.dart +++ b/packages/stream_chat/lib/version.dart @@ -1,12 +1,6 @@ import 'package:stream_chat/src/client/client.dart'; -import 'package:stream_chat/src/core/platform_detector/platform_detector.dart'; /// Current package version /// Used in [StreamChatClient] to build the `x-stream-client` header // ignore: constant_identifier_names const PACKAGE_VERSION = '2.0.0'; - -/// Get the current user agent -String get userAgent => 'stream-chat-dart-client-' - '${CurrentPlatform.name}-' - '${PACKAGE_VERSION.split('+')[0]}'; diff --git a/packages/stream_chat/test/src/core/http/stream_http_client_options_test.dart b/packages/stream_chat/test/src/core/http/stream_http_client_options_test.dart index ab70462f..02cfc07a 100644 --- a/packages/stream_chat/test/src/core/http/stream_http_client_options_test.dart +++ b/packages/stream_chat/test/src/core/http/stream_http_client_options_test.dart @@ -9,7 +9,7 @@ void main() { expect(options.baseUrl, 'https://chat-us-east-1.stream-io-api.com'); expect(options.connectTimeout, const Duration(seconds: 6)); expect(options.receiveTimeout, const Duration(seconds: 6)); - expect(options.queryParams, const {}); + expect(options.queryParameters, const {}); expect(options.headers, const {}); }); @@ -18,19 +18,15 @@ void main() { baseUrl: 'base-url', connectTimeout: Duration(seconds: 3), receiveTimeout: Duration(seconds: 3), - headers: { - 'test': 'test', - }, - queryParams: { - '123': '123', - }, + headers: {'test': 'test'}, + queryParameters: {'123': '123'}, ); expect(options.location, isNull); expect(options.baseUrl, 'base-url'); expect(options.connectTimeout, const Duration(seconds: 3)); expect(options.receiveTimeout, const Duration(seconds: 3)); expect(options.headers, {'test': 'test'}); - expect(options.queryParams, {'123': '123'}); + expect(options.queryParameters, {'123': '123'}); }); group('should create baseUrl according to provided location', () {