refactor(llc, ui): migrate enums to v3
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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._({
|
||||
|
||||
@@ -108,10 +108,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;
|
||||
|
||||
|
||||
@@ -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<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:
|
||||
|
||||
@@ -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]!;
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user