migrate to nnbd

Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
Sahil Kumar
2021-04-20 19:52:06 +05:30
parent 8f1f7b0b68
commit 3bb1b11ee8
59 changed files with 642 additions and 589 deletions
@@ -620,7 +620,7 @@ class Channel {
Future<SendReactionResponse> sendReaction(
Message message,
String type, {
Map<String, dynamic> extraData = const {},
Map<String, Object> extraData = const {},
bool enforceUnique = false,
}) async {
_checkInitialized();
@@ -209,7 +209,7 @@ class GetMessageResponse extends _BaseResponse {
final res = _$GetMessageResponseFromJson(json);
final jsonChannel = res.message.extraData.remove('channel');
if (jsonChannel != null) {
res.channel = ChannelModel.fromJson(jsonChannel);
res.channel = ChannelModel.fromJson(jsonChannel as Map<String, dynamic>);
}
return res;
}
@@ -24,10 +24,10 @@ abstract class ChatPersistenceClient {
});
/// Get stored connection event
Future<Event> getConnectionInfo();
Future<Event?> getConnectionInfo();
/// Get stored lastSyncAt
Future<DateTime> getLastSyncAt();
Future<DateTime?> getLastSyncAt();
/// Update stored connection event
Future<void> updateConnectionInfo(Event event);
@@ -39,7 +39,7 @@ abstract class ChatPersistenceClient {
Future<List<String>> getChannelCids();
/// Get stored [ChannelModel]s by providing channel [cid]
Future<ChannelModel> getChannelByCid(String cid);
Future<ChannelModel?> getChannelByCid(String cid);
/// Get stored channel [Member]s by providing channel [cid]
Future<List<Member>> getMembersByCid(String cid);
@@ -90,7 +90,7 @@ abstract class ChatPersistenceClient {
/// for filtering out states.
Future<List<ChannelState>> getChannelStates({
Map<String, dynamic>? filter,
List<SortOption<ChannelModel>>? sort = const [],
List<SortOption<ChannelModel>>? sort,
PaginationParams? paginationParams,
});
@@ -111,7 +111,7 @@ class Attachment extends Equatable {
/// Map of custom channel extraData
@JsonKey(includeIfNull: false)
final Map<String, dynamic>? extraData;
final Map<String, Object>? extraData;
/// The attachment ID.
///
@@ -180,7 +180,7 @@ class Attachment extends Equatable {
List<Action>? actions,
AttachmentFile? file,
UploadState? uploadState,
Map<String, dynamic>? extraData,
Map<String, Object>? extraData,
}) =>
Attachment(
id: id ?? this.id,
@@ -30,7 +30,9 @@ Attachment _$AttachmentFromJson(Map<String, dynamic> json) {
?.map((e) => Action.fromJson(e as Map<String, dynamic>))
.toList() ??
[],
extraData: json['extra_data'] as Map<String, dynamic>?,
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as Object),
),
file: json['file'] == null
? null
: AttachmentFile.fromJson(json['file'] as Map<String, dynamic>),
@@ -84,7 +84,7 @@ class ChannelModel {
/// Map of custom channel extraData
@JsonKey(includeIfNull: false)
final Map<String, dynamic>? extraData;
final Map<String, Object>? extraData;
/// The team the channel belongs to
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
@@ -108,8 +108,9 @@ class ChannelModel {
];
/// Shortcut for channel name
String? get name =>
extraData?.containsKey('name') == true ? extraData!['name'] : cid;
String get name => extraData?.containsKey('name') == true
? extraData!['name'] as String
: cid;
/// Serialize to json
Map<String, dynamic> toJson() => Serialization.moveFromExtraDataToRoot(
@@ -129,7 +130,7 @@ class ChannelModel {
DateTime? updatedAt,
DateTime? deletedAt,
int? memberCount,
Map<String, dynamic>? extraData,
Map<String, Object>? extraData,
String? team,
}) =>
ChannelModel(
@@ -31,7 +31,9 @@ ChannelModel _$ChannelModelFromJson(Map<String, dynamic> json) {
? null
: DateTime.parse(json['deleted_at'] as String),
memberCount: json['member_count'] as int? ?? 0,
extraData: json['extra_data'] as Map<String, dynamic>?,
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as Object),
),
team: json['team'] as String?,
);
}
@@ -93,7 +93,7 @@ class Event {
/// Map of custom channel extraData
@JsonKey(defaultValue: {})
final Map<String, dynamic> extraData;
final Map<String, Object> extraData;
/// Known top level fields.
/// Useful for [Serialization] methods.
@@ -140,7 +140,7 @@ class Event {
int? unreadChannels,
bool? online,
String? parentId,
Map<String, dynamic>? extraData,
Map<String, Object>? extraData,
}) =>
Event(
type: type ?? this.type,
@@ -180,7 +180,7 @@ class EventChannel extends ChannelModel {
required DateTime updatedAt,
DateTime? deletedAt,
required int memberCount,
Map<String, dynamic>? extraData,
Map<String, Object>? extraData,
}) : super(
id: id,
type: type,
@@ -38,7 +38,10 @@ Event _$EventFromJson(Map<String, dynamic> json) {
channelId: json['channel_id'] as String?,
channelType: json['channel_type'] as String?,
parentId: json['parent_id'] as String?,
extraData: json['extra_data'] as Map<String, dynamic>? ?? {},
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as Object),
) ??
{},
isLocal: json['is_local'] as bool? ?? false,
);
}
@@ -86,7 +89,9 @@ EventChannel _$EventChannelFromJson(Map<String, dynamic> json) {
? null
: DateTime.parse(json['deleted_at'] as String),
memberCount: json['member_count'] as int? ?? 0,
extraData: json['extra_data'] as Map<String, dynamic>?,
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as Object),
),
);
}
@@ -208,7 +208,7 @@ class Message extends Equatable {
includeIfNull: false,
defaultValue: {},
)
final Map<String, dynamic> extraData;
final Map<String, Object> extraData;
/// True if the message is a system info
bool get isSystem => type == 'system';
@@ -289,7 +289,7 @@ class Message extends Equatable {
DateTime? pinnedAt,
Object? pinExpires = _pinExpires,
User? pinnedBy,
Map<String, dynamic>? extraData,
Map<String, Object>? extraData,
MessageSendingStatus? status,
bool? skipPush,
}) {
@@ -63,7 +63,10 @@ Message _$MessageFromJson(Map<String, dynamic> json) {
pinnedBy: json['pinned_by'] == null
? null
: User.fromJson(json['pinned_by'] as Map<String, dynamic>),
extraData: json['extra_data'] as Map<String, dynamic>? ?? {},
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as Object),
) ??
{},
deletedAt: json['deleted_at'] == null
? null
: DateTime.parse(json['deleted_at'] as String),
@@ -23,7 +23,7 @@ class OwnUser extends User {
DateTime? updatedAt,
DateTime? lastActive,
bool online = false,
Map<String, dynamic> extraData = const {},
Map<String, Object> extraData = const {},
bool banned = false,
}) : super(
id: id,
@@ -34,7 +34,9 @@ OwnUser _$OwnUserFromJson(Map<String, dynamic> json) {
? null
: DateTime.parse(json['last_active'] as String),
online: json['online'] as bool? ?? false,
extraData: json['extra_data'] as Map<String, dynamic>,
extraData: (json['extra_data'] as Map<String, dynamic>).map(
(k, e) => MapEntry(k, e as Object),
),
banned: json['banned'] as bool? ?? false,
);
}
@@ -50,7 +50,7 @@ class Reaction {
/// Reaction custom extraData
@JsonKey(includeIfNull: false)
final Map<String, dynamic>? extraData;
final Map<String, Object>? extraData;
/// Map of custom user extraData
static const topLevelFields = [
@@ -75,7 +75,7 @@ class Reaction {
User? user,
String? userId,
int? score,
Map<String, dynamic>? extraData,
Map<String, Object>? extraData,
}) =>
Reaction(
messageId: messageId ?? this.messageId,
@@ -18,7 +18,9 @@ Reaction _$ReactionFromJson(Map<String, dynamic> json) {
: User.fromJson(json['user'] as Map<String, dynamic>),
userId: json['user_id'] as String?,
score: json['score'] as int? ?? 0,
extraData: json['extra_data'] as Map<String, dynamic>?,
extraData: (json['extra_data'] as Map<String, dynamic>?)?.map(
(k, e) => MapEntry(k, e as Object),
),
);
}
@@ -75,16 +75,19 @@ class User {
/// Map of custom user extraData
@JsonKey(includeIfNull: false)
final Map<String, dynamic> extraData;
final Map<String, Object> extraData;
@override
int get hashCode => id.hashCode;
/// Shortcut for user name
String? get name =>
(extraData.containsKey('name') == true && extraData['name'] != '')
? extraData['name']
: id;
String get name {
if (extraData.containsKey('name')) {
final name = extraData['name'] as String;
if (name.isNotEmpty) return name;
}
return id;
}
@override
bool operator ==(Object other) =>
@@ -104,7 +107,7 @@ class User {
DateTime? updatedAt,
DateTime? lastActive,
bool? online,
Map<String, dynamic>? extraData,
Map<String, Object>? extraData,
bool? banned,
List<String>? teams,
}) =>
@@ -20,7 +20,9 @@ User _$UserFromJson(Map<String, dynamic> json) {
? null
: DateTime.parse(json['last_active'] as String),
online: json['online'] as bool? ?? false,
extraData: json['extra_data'] as Map<String, dynamic>,
extraData: (json['extra_data'] as Map<String, dynamic>).map(
(k, e) => MapEntry(k, e as Object),
),
banned: json['banned'] as bool? ?? false,
teams:
(json['teams'] as List<dynamic>?)?.map((e) => e as String).toList() ??