fix(llc): segregate mute from channel mutes
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_model.dart';
|
||||
import 'package:stream_chat/src/core/models/user.dart';
|
||||
|
||||
part 'channel_mute.g.dart';
|
||||
|
||||
/// The class that contains the information about a muted user
|
||||
@JsonSerializable(createToJson: false)
|
||||
class ChannelMute {
|
||||
/// Constructor used for json serialization
|
||||
ChannelMute({
|
||||
required this.user,
|
||||
required this.channel,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
this.expires,
|
||||
});
|
||||
|
||||
/// Create a new instance from a json
|
||||
factory ChannelMute.fromJson(Map<String, dynamic> json) =>
|
||||
_$ChannelMuteFromJson(json);
|
||||
|
||||
/// The user that performed the muting action
|
||||
final User user;
|
||||
|
||||
/// The target user
|
||||
final ChannelModel channel;
|
||||
|
||||
/// The date in which the use was muted
|
||||
final DateTime createdAt;
|
||||
|
||||
/// The date of the last update
|
||||
final DateTime updatedAt;
|
||||
|
||||
/// The date in which the mute expires
|
||||
final DateTime? expires;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'channel_mute.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
ChannelMute _$ChannelMuteFromJson(Map<String, dynamic> json) => ChannelMute(
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
channel: ChannelModel.fromJson(json['channel'] as Map<String, dynamic>),
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
expires: json['expires'] == null
|
||||
? null
|
||||
: DateTime.parse(json['expires'] as String),
|
||||
);
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_model.dart';
|
||||
import 'package:stream_chat/src/core/models/user.dart';
|
||||
import 'package:stream_chat/src/core/util/serializer.dart';
|
||||
|
||||
part 'mute.g.dart';
|
||||
|
||||
@@ -11,27 +9,27 @@ class Mute {
|
||||
/// Constructor used for json serialization
|
||||
Mute({
|
||||
required this.user,
|
||||
required this.channel,
|
||||
required this.target,
|
||||
required this.createdAt,
|
||||
required this.updatedAt,
|
||||
this.expires,
|
||||
});
|
||||
|
||||
/// Create a new instance from a json
|
||||
factory Mute.fromJson(Map<String, dynamic> json) => _$MuteFromJson(json);
|
||||
|
||||
/// The user that performed the muting action
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final User user;
|
||||
|
||||
/// The target user
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final ChannelModel channel;
|
||||
final User target;
|
||||
|
||||
/// The date in which the use was muted
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final DateTime createdAt;
|
||||
|
||||
/// The date of the last update
|
||||
@JsonKey(includeIfNull: false, toJson: Serializer.readOnly)
|
||||
final DateTime updatedAt;
|
||||
|
||||
/// The date in which the mute expires
|
||||
final DateTime? expires;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ part of 'mute.dart';
|
||||
|
||||
Mute _$MuteFromJson(Map<String, dynamic> json) => Mute(
|
||||
user: User.fromJson(json['user'] as Map<String, dynamic>),
|
||||
channel: ChannelModel.fromJson(json['channel'] as Map<String, dynamic>),
|
||||
target: User.fromJson(json['target'] as Map<String, dynamic>),
|
||||
createdAt: DateTime.parse(json['created_at'] as String),
|
||||
updatedAt: DateTime.parse(json['updated_at'] as String),
|
||||
expires: json['expires'] == null
|
||||
? null
|
||||
: DateTime.parse(json['expires'] as String),
|
||||
);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_mute.dart';
|
||||
import 'package:stream_chat/src/core/util/serializer.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
@@ -79,7 +80,7 @@ class OwnUser extends User {
|
||||
bool? banned,
|
||||
DateTime? banExpires,
|
||||
List<String>? teams,
|
||||
List<Mute>? channelMutes,
|
||||
List<ChannelMute>? channelMutes,
|
||||
List<Device>? devices,
|
||||
List<Mute>? mutes,
|
||||
int? totalUnreadCount,
|
||||
@@ -142,7 +143,7 @@ class OwnUser extends User {
|
||||
|
||||
/// List of channels muted by the user.
|
||||
@JsonKey(includeIfNull: false)
|
||||
final List<Mute> channelMutes;
|
||||
final List<ChannelMute> channelMutes;
|
||||
|
||||
/// Total unread messages by the user.
|
||||
@JsonKey(includeIfNull: false)
|
||||
|
||||
@@ -18,7 +18,7 @@ OwnUser _$OwnUserFromJson(Map<String, dynamic> json) => OwnUser(
|
||||
totalUnreadCount: json['total_unread_count'] as int? ?? 0,
|
||||
unreadChannels: json['unread_channels'] as int? ?? 0,
|
||||
channelMutes: (json['channel_mutes'] as List<dynamic>?)
|
||||
?.map((e) => Mute.fromJson(e as Map<String, dynamic>))
|
||||
?.map((e) => ChannelMute.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
const [],
|
||||
id: json['id'] as String,
|
||||
|
||||
Vendored
+3
-3
@@ -1,14 +1,14 @@
|
||||
import 'package:stream_chat/src/core/models/channel_model.dart';
|
||||
import 'package:stream_chat/src/core/models/mute.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_mute.dart';
|
||||
import 'package:stream_chat/src/core/models/user.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../utils.dart';
|
||||
|
||||
void main() {
|
||||
group('src/models/mute', () {
|
||||
group('src/models/channel_mute', () {
|
||||
test('should parse json correctly', () {
|
||||
final mute = Mute.fromJson(jsonFixture('mute.json'));
|
||||
final mute = ChannelMute.fromJson(jsonFixture('channel_mute.json'));
|
||||
expect(mute.channel, isA<ChannelModel>());
|
||||
expect(mute.user, isA<User>());
|
||||
expect(mute.createdAt, DateTime.parse('2020-12-04T10:39:06.512021Z'));
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_mute.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
@@ -6,12 +7,14 @@ import '../../utils.dart';
|
||||
|
||||
class MockMute extends Mock implements Mute {}
|
||||
|
||||
class ChannelMockMute extends Mock implements ChannelMute {}
|
||||
|
||||
class MockDevice extends Mock implements Device {}
|
||||
|
||||
void main() {
|
||||
final devices = [MockDevice(), MockDevice()];
|
||||
final mutes = [MockMute(), MockMute()];
|
||||
final channelMutes = [MockMute()];
|
||||
final channelMutes = [ChannelMockMute()];
|
||||
final createdAt = DateTime.parse('2021-05-03 12:39:21.817646');
|
||||
final updatedAt = DateTime.parse('2021-04-03 12:39:21.817646');
|
||||
final lastActive = DateTime.parse('2021-03-03 12:39:21.817646');
|
||||
|
||||
Reference in New Issue
Block a user