diff --git a/packages/stream_chat/lib/src/core/api/device_api.dart b/packages/stream_chat/lib/src/core/api/device_api.dart index df137cdc..cc0a1952 100644 --- a/packages/stream_chat/lib/src/core/api/device_api.dart +++ b/packages/stream_chat/lib/src/core/api/device_api.dart @@ -10,15 +10,6 @@ enum PushProvider { apn, } -/// Helper extension for [PushProvider] -extension PushProviderX on PushProvider { - /// Returns the string notion for [PushProvider]. - String get name => { - PushProvider.apn: 'apn', - PushProvider.firebase: 'firebase', - }[this]!; -} - /// Defines the api dedicated to device operations class DeviceApi { /// Initialize a new device api diff --git a/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart b/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart index 0ef1a408..7748f96f 100644 --- a/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart +++ b/packages/stream_chat/lib/src/core/http/interceptor/auth_interceptor.dart @@ -36,7 +36,7 @@ class AuthInterceptor extends Interceptor { final params = {'user_id': token.userId}; final headers = { 'Authorization': token.rawValue, - 'stream-auth-type': token.authType.raw, + 'stream-auth-type': token.authType.name, }; options ..queryParameters.addAll(params) diff --git a/packages/stream_chat/lib/src/core/http/token.dart b/packages/stream_chat/lib/src/core/http/token.dart index eba49b82..2472a1f7 100644 --- a/packages/stream_chat/lib/src/core/http/token.dart +++ b/packages/stream_chat/lib/src/core/http/token.dart @@ -18,15 +18,6 @@ enum AuthType { anonymous, } -/// Extension for returning the AuthType as a string -extension AuthTypeX on AuthType { - /// Returns the AuthType as a string - String get raw => { - AuthType.jwt: 'jwt', - AuthType.anonymous: 'anonymous', - }[this]!; -} - /// Token designed to store the JWT and the user it is related to. class Token extends Equatable { const Token._({ diff --git a/packages/stream_chat/lib/src/core/models/attachment_file.dart b/packages/stream_chat/lib/src/core/models/attachment_file.dart index 71cdec29..f63eff89 100644 --- a/packages/stream_chat/lib/src/core/models/attachment_file.dart +++ b/packages/stream_chat/lib/src/core/models/attachment_file.dart @@ -108,10 +108,7 @@ class UploadState with _$UploadState { /// Creates a new instance from a json factory UploadState.fromJson(Map json) => _$UploadStateFromJson(json); -} -/// Helper extension for UploadState -extension UploadStateX on UploadState? { /// Returns true if state is [Preparing] bool get isPreparing => this is Preparing; diff --git a/packages/stream_chat/lib/src/core/models/filter.dart b/packages/stream_chat/lib/src/core/models/filter.dart index 13247588..2122519d 100644 --- a/packages/stream_chat/lib/src/core/models/filter.dart +++ b/packages/stream_chat/lib/src/core/models/filter.dart @@ -53,29 +53,43 @@ enum FilterOperator { nor, /// Matches any list that contains the specified value - contains, -} + contains; -/// Helper extension for [FilterOperator] -extension FilterOperatorX on FilterOperator { - /// Converts [FilterOperator] into rew values - String get rawValue => { - FilterOperator.equal: r'$eq', - FilterOperator.notEqual: r'$ne', - FilterOperator.greater: r'$gt', - FilterOperator.greaterOrEqual: r'$gte', - FilterOperator.less: r'$lt', - FilterOperator.lessOrEqual: r'$lte', - FilterOperator.in_: r'$in', - FilterOperator.notIn: r'$nin', - FilterOperator.query: r'$q', - FilterOperator.autoComplete: r'$autocomplete', - FilterOperator.exists: r'$exists', - FilterOperator.and: r'$and', - FilterOperator.or: r'$or', - FilterOperator.nor: r'$nor', - FilterOperator.contains: r'$contains', - }[this]!; + @override + String toString() { + switch (this) { + case FilterOperator.equal: + return r'$eq'; + case FilterOperator.notEqual: + return r'$ne'; + case FilterOperator.greater: + return r'$gt'; + case FilterOperator.greaterOrEqual: + return r'$gte'; + case FilterOperator.less: + return r'$lt'; + case FilterOperator.lessOrEqual: + return r'$lte'; + case FilterOperator.in_: + return r'$in'; + case FilterOperator.notIn: + return r'$nin'; + case FilterOperator.query: + return r'$q'; + case FilterOperator.autoComplete: + return r'$autocomplete'; + case FilterOperator.exists: + return r'$exists'; + case FilterOperator.and: + return r'$and'; + case FilterOperator.or: + return r'$or'; + case FilterOperator.nor: + return r'$nor'; + case FilterOperator.contains: + return r'$contains'; + } + } } /// Stream supports a limited set of filters for querying channels, @@ -96,11 +110,11 @@ class Filter extends Equatable { this.key, }); - Filter._({ + const Filter._({ required FilterOperator operator, required this.value, this.key, - }) : operator = operator.rawValue; + }) : operator = '$operator'; /// An empty filter const Filter.empty() @@ -215,7 +229,7 @@ class Filter extends Equatable { /// Serializes to json object Map toJson() { final json = {}; - final groupOperators = _groupOperators.map((it) => it.rawValue); + final groupOperators = _groupOperators.map((it) => '$it'); if (groupOperators.contains(operator)) { // Filters with group operators are encoded in the following form: diff --git a/packages/stream_chat/lib/src/location.dart b/packages/stream_chat/lib/src/location.dart deleted file mode 100644 index 86813a0a..00000000 --- a/packages/stream_chat/lib/src/location.dart +++ /dev/null @@ -1,29 +0,0 @@ -/// -enum Location { - /// - usEast, - - /// - euWest, - - /// - mumbai, - - /// - sydney, - - /// - singapore, -} - -/// -extension LocationX on Location { - /// - String get name => { - Location.usEast: 'us-east', - Location.euWest: 'dublin', - Location.mumbai: 'mumbai', - Location.sydney: 'sydney', - Location.singapore: 'singapore', - }[this]!; -} diff --git a/packages/stream_chat/lib/src/ws/websocket.dart b/packages/stream_chat/lib/src/ws/websocket.dart index a26bd1f6..7627b0d9 100644 --- a/packages/stream_chat/lib/src/ws/websocket.dart +++ b/packages/stream_chat/lib/src/ws/websocket.dart @@ -163,7 +163,7 @@ class WebSocket with TimerHelper { 'json': jsonEncode(params), 'api_key': apiKey, 'authorization': token.rawValue, - 'stream-auth-type': token.authType.raw, + 'stream-auth-type': token.authType.name, ...queryParameters, }; final scheme = baseUrl.startsWith('https') ? 'wss' : 'ws'; diff --git a/packages/stream_chat/lib/stream_chat.dart b/packages/stream_chat/lib/stream_chat.dart index 0fce9d63..0479a378 100644 --- a/packages/stream_chat/lib/stream_chat.dart +++ b/packages/stream_chat/lib/stream_chat.dart @@ -36,7 +36,6 @@ export './src/core/models/user.dart'; export './src/core/util/extension.dart'; export './src/db/chat_persistence_client.dart'; export './src/event_type.dart'; -export './src/location.dart'; export './src/permission_type.dart'; export './src/ws/connection_status.dart'; export 'src/client/channel.dart'; @@ -67,5 +66,4 @@ export 'src/core/models/user.dart'; export 'src/core/util/extension.dart'; export 'src/db/chat_persistence_client.dart'; export 'src/event_type.dart'; -export 'src/location.dart'; export 'src/ws/connection_status.dart'; diff --git a/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart b/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart index 82dcdfb9..1e88ea1e 100644 --- a/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart +++ b/packages/stream_chat/test/src/core/http/interceptor/auth_interceptor_test.dart @@ -46,7 +46,7 @@ void main() { expect(updateHeaders.containsKey('Authorization'), isTrue); expect(updateHeaders['Authorization'], token.rawValue); expect(updateHeaders.containsKey('stream-auth-type'), isTrue); - expect(updateHeaders['stream-auth-type'], token.authType.raw); + expect(updateHeaders['stream-auth-type'], token.authType.name); expect(updatedQueryParams.containsKey('user_id'), isTrue); expect(updatedQueryParams['user_id'], token.userId); diff --git a/packages/stream_chat/test/src/core/http/token_test.dart b/packages/stream_chat/test/src/core/http/token_test.dart index b448884e..0f0e0425 100644 --- a/packages/stream_chat/test/src/core/http/token_test.dart +++ b/packages/stream_chat/test/src/core/http/token_test.dart @@ -10,7 +10,7 @@ void main() { expect(token.userId, userId); expect(token.rawValue, isEmpty); expect(token.authType, AuthType.anonymous); - expect(token.authType.raw, AuthType.anonymous.raw); + expect(token.authType.name, AuthType.anonymous.name); }); test('`.fromRawValue` should create token from rawValue', () { @@ -36,7 +36,7 @@ void main() { expect(token.userId, userId); expect(token.rawValue, isNotEmpty); expect(token.authType, AuthType.jwt); - expect(token.authType.raw, AuthType.jwt.raw); + expect(token.authType.name, AuthType.jwt.name); }); test( @@ -51,7 +51,7 @@ void main() { expect(token.userId, user.id); expect(token.rawValue, isNotEmpty); expect(token.authType, AuthType.jwt); - expect(token.authType.raw, AuthType.jwt.raw); + expect(token.authType.name, AuthType.jwt.name); }, ); } diff --git a/packages/stream_chat/test/src/core/models/filter_test.dart b/packages/stream_chat/test/src/core/models/filter_test.dart index f9c6ebd0..851d1cab 100644 --- a/packages/stream_chat/test/src/core/models/filter_test.dart +++ b/packages/stream_chat/test/src/core/models/filter_test.dart @@ -11,7 +11,7 @@ void main() { final filter = Filter.equal(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.equal.rawValue); + expect(filter.operator, FilterOperator.equal.toString()); }); test('notEqual', () { @@ -20,7 +20,7 @@ void main() { final filter = Filter.notEqual(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.notEqual.rawValue); + expect(filter.operator, FilterOperator.notEqual.toString()); }); test('greater', () { @@ -29,7 +29,7 @@ void main() { final filter = Filter.greater(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.greater.rawValue); + expect(filter.operator, FilterOperator.greater.toString()); }); test('greaterOrEqual', () { @@ -38,7 +38,7 @@ void main() { final filter = Filter.greaterOrEqual(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.greaterOrEqual.rawValue); + expect(filter.operator, FilterOperator.greaterOrEqual.toString()); }); test('less', () { @@ -47,7 +47,7 @@ void main() { final filter = Filter.less(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.less.rawValue); + expect(filter.operator, FilterOperator.less.toString()); }); test('lessOrEqual', () { @@ -56,7 +56,7 @@ void main() { final filter = Filter.lessOrEqual(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.lessOrEqual.rawValue); + expect(filter.operator, FilterOperator.lessOrEqual.toString()); }); test('in', () { @@ -65,7 +65,7 @@ void main() { final filter = Filter.in_(key, values); expect(filter.key, key); expect(filter.value, values); - expect(filter.operator, FilterOperator.in_.rawValue); + expect(filter.operator, FilterOperator.in_.toString()); }); test('in', () { @@ -74,7 +74,7 @@ void main() { final filter = Filter.in_(key, values); expect(filter.key, key); expect(filter.value, values); - expect(filter.operator, FilterOperator.in_.rawValue); + expect(filter.operator, FilterOperator.in_.toString()); }); test('notIn', () { @@ -83,7 +83,7 @@ void main() { final filter = Filter.notIn(key, values); expect(filter.key, key); expect(filter.value, values); - expect(filter.operator, FilterOperator.notIn.rawValue); + expect(filter.operator, FilterOperator.notIn.toString()); }); test('query', () { @@ -92,7 +92,7 @@ void main() { final filter = Filter.query(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.query.rawValue); + expect(filter.operator, FilterOperator.query.toString()); }); test('autoComplete', () { @@ -101,7 +101,7 @@ void main() { final filter = Filter.autoComplete(key, value); expect(filter.key, key); expect(filter.value, value); - expect(filter.operator, FilterOperator.autoComplete.rawValue); + expect(filter.operator, FilterOperator.autoComplete.toString()); }); test('exists', () { @@ -109,7 +109,7 @@ void main() { final filter = Filter.exists(key); expect(filter.key, key); expect(filter.value, isTrue); - expect(filter.operator, FilterOperator.exists.rawValue); + expect(filter.operator, FilterOperator.exists.toString()); }); test('notExists', () { @@ -117,7 +117,7 @@ void main() { final filter = Filter.notExists(key); expect(filter.key, key); expect(filter.value, isFalse); - expect(filter.operator, FilterOperator.exists.rawValue); + expect(filter.operator, FilterOperator.exists.toString()); }); test('custom', () { @@ -149,7 +149,7 @@ void main() { final filter = Filter.contains(key, values); expect(filter.key, key); expect(filter.value, values); - expect(filter.operator, FilterOperator.contains.rawValue); + expect(filter.operator, FilterOperator.contains.toString()); }); group('groupedOperator', () { @@ -161,21 +161,21 @@ void main() { final filter = Filter.and(filters); expect(filter.key, isNull); expect(filter.value, filters); - expect(filter.operator, FilterOperator.and.rawValue); + expect(filter.operator, FilterOperator.and.toString()); }); test('or', () { final filter = Filter.or(filters); expect(filter.key, isNull); expect(filter.value, filters); - expect(filter.operator, FilterOperator.or.rawValue); + expect(filter.operator, FilterOperator.or.toString()); }); test('nor', () { final filter = Filter.nor(filters); expect(filter.key, isNull); expect(filter.value, filters); - expect(filter.operator, FilterOperator.nor.rawValue); + expect(filter.operator, FilterOperator.nor.toString()); }); }); }); @@ -189,7 +189,7 @@ void main() { final encoded = json.encode(filter); expect( encoded, - '{"$key":{"${FilterOperator.equal.rawValue}":${json.encode(value)}}}', + '{"$key":{"${FilterOperator.equal.toString()}":${json.encode(value)}}}', ); }); test('listValue', () { @@ -199,7 +199,7 @@ void main() { final encoded = json.encode(filter); expect( encoded, - '{"$key":{"${FilterOperator.in_.rawValue}":${json.encode(values)}}}', + '{"$key":{"${FilterOperator.in_.toString()}":${json.encode(values)}}}', ); }); @@ -243,7 +243,7 @@ void main() { final encoded = json.encode(filter); expect( encoded, - '{"${FilterOperator.and.rawValue}":${json.encode(filters)}}', + '{"${FilterOperator.and.toString()}":${json.encode(filters)}}', ); }); diff --git a/packages/stream_chat_flutter/lib/src/attachment/attachment_widget.dart b/packages/stream_chat_flutter/lib/src/attachment/attachment_widget.dart index f3ff22c6..bf1d0f67 100644 --- a/packages/stream_chat_flutter/lib/src/attachment/attachment_widget.dart +++ b/packages/stream_chat_flutter/lib/src/attachment/attachment_widget.dart @@ -7,14 +7,10 @@ enum AttachmentSource { local, /// Attachment is uploaded - network, -} + network; -/// Extension for identifying type of attachment -extension AttachmentSourceX on AttachmentSource { /// The [when] method is the equivalent to pattern matching. /// Its prototype depends on the AttachmentSource defined. - // ignore: missing_return T when({ required T Function() local, required T Function() network,