Skip to content

Commit

Permalink
Merge branch 'develop' into release/4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
imtoori committed May 20, 2022
2 parents 6d6e484 + f8997ff commit 24c80fe
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 124 deletions.
9 changes: 0 additions & 9 deletions packages/stream_chat/lib/src/core/api/device_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions packages/stream_chat/lib/src/core/http/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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._({
Expand Down
6 changes: 3 additions & 3 deletions packages/stream_chat/lib/src/core/models/attachment_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class AttachmentFile {
/// Union class to hold various [UploadState] of a attachment.
@freezed
class UploadState with _$UploadState {
// Dummy private constructor in order to use getters
const UploadState._();

/// Preparing state of the union
const factory UploadState.preparing() = Preparing;

Expand All @@ -108,10 +111,7 @@ class UploadState with _$UploadState {
/// Creates a new instance from a json
factory UploadState.fromJson(Map<String, dynamic> json) =>
_$UploadStateFromJson(json);
}

/// Helper extension for UploadState
extension UploadStateX on UploadState? {
/// Returns true if state is [Preparing]
bool get isPreparing => this is Preparing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ class __$$PreparingCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>

/// @nodoc
@JsonSerializable()
class _$Preparing implements Preparing {
const _$Preparing({final String? $type}) : $type = $type ?? 'preparing';
class _$Preparing extends Preparing {
const _$Preparing({final String? $type})
: $type = $type ?? 'preparing',
super._();

factory _$Preparing.fromJson(Map<String, dynamic> json) =>
_$$PreparingFromJson(json);
Expand Down Expand Up @@ -226,8 +228,9 @@ class _$Preparing implements Preparing {
}
}

abstract class Preparing implements UploadState {
abstract class Preparing extends UploadState {
const factory Preparing() = _$Preparing;
const Preparing._() : super._();

factory Preparing.fromJson(Map<String, dynamic> json) = _$Preparing.fromJson;
}
Expand Down Expand Up @@ -270,10 +273,11 @@ class __$$InProgressCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>

/// @nodoc
@JsonSerializable()
class _$InProgress implements InProgress {
class _$InProgress extends InProgress {
const _$InProgress(
{required this.uploaded, required this.total, final String? $type})
: $type = $type ?? 'inProgress';
: $type = $type ?? 'inProgress',
super._();

factory _$InProgress.fromJson(Map<String, dynamic> json) =>
_$$InProgressFromJson(json);
Expand Down Expand Up @@ -392,9 +396,10 @@ class _$InProgress implements InProgress {
}
}

abstract class InProgress implements UploadState {
abstract class InProgress extends UploadState {
const factory InProgress(
{required final int uploaded, required final int total}) = _$InProgress;
const InProgress._() : super._();

factory InProgress.fromJson(Map<String, dynamic> json) =
_$InProgress.fromJson;
Expand Down Expand Up @@ -424,8 +429,10 @@ class __$$SuccessCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>

/// @nodoc
@JsonSerializable()
class _$Success implements Success {
const _$Success({final String? $type}) : $type = $type ?? 'success';
class _$Success extends Success {
const _$Success({final String? $type})
: $type = $type ?? 'success',
super._();

factory _$Success.fromJson(Map<String, dynamic> json) =>
_$$SuccessFromJson(json);
Expand Down Expand Up @@ -528,8 +535,9 @@ class _$Success implements Success {
}
}

abstract class Success implements UploadState {
abstract class Success extends UploadState {
const factory Success() = _$Success;
const Success._() : super._();

factory Success.fromJson(Map<String, dynamic> json) = _$Success.fromJson;
}
Expand Down Expand Up @@ -565,9 +573,10 @@ class __$$FailedCopyWithImpl<$Res> extends _$UploadStateCopyWithImpl<$Res>

/// @nodoc
@JsonSerializable()
class _$Failed implements Failed {
class _$Failed extends Failed {
const _$Failed({required this.error, final String? $type})
: $type = $type ?? 'failed';
: $type = $type ?? 'failed',
super._();

factory _$Failed.fromJson(Map<String, dynamic> json) =>
_$$FailedFromJson(json);
Expand Down Expand Up @@ -681,8 +690,9 @@ class _$Failed implements Failed {
}
}

abstract class Failed implements UploadState {
abstract class Failed extends UploadState {
const factory Failed({required final String error}) = _$Failed;
const Failed._() : super._();

factory Failed.fromJson(Map<String, dynamic> json) = _$Failed.fromJson;

Expand Down
64 changes: 39 additions & 25 deletions packages/stream_chat/lib/src/core/models/filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -215,7 +229,7 @@ class Filter extends Equatable {
/// Serializes to json object
Map<String, Object?> toJson() {
final json = <String, Object?>{};
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:
Expand Down
29 changes: 0 additions & 29 deletions packages/stream_chat/lib/src/location.dart

This file was deleted.

3 changes: 1 addition & 2 deletions packages/stream_chat/lib/src/ws/websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:rxdart/rxdart.dart';
import 'package:stream_chat/src/core/error/error.dart';
import 'package:stream_chat/src/core/http/token.dart';
import 'package:stream_chat/src/core/http/token_manager.dart';
import 'package:stream_chat/src/core/models/event.dart';
import 'package:stream_chat/src/core/models/user.dart';
Expand Down Expand Up @@ -163,7 +162,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';
Expand Down
2 changes: 0 additions & 2 deletions packages/stream_chat/lib/stream_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
1 change: 0 additions & 1 deletion packages/stream_chat/test/src/client/client_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/api/device_api.dart';
import 'package:stream_chat/src/core/http/token.dart';
import 'package:stream_chat/src/core/models/banned_user.dart';
import 'package:stream_chat/stream_chat.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions packages/stream_chat/test/src/core/http/token_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand All @@ -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(
Expand All @@ -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);
},
);
}
Loading

0 comments on commit 24c80fe

Please sign in to comment.