[LLC] Add pin message feature
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -330,7 +330,7 @@ class Channel {
|
|||||||
state?.addMessage(message);
|
state?.addMessage(message);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (message.attachments?.isNotEmpty == true) {
|
if (message.attachments?.any((it) => !it.uploadState.isSuccess) == true) {
|
||||||
final attachmentsUploadCompleter = Completer<Message>();
|
final attachmentsUploadCompleter = Completer<Message>();
|
||||||
_messageAttachmentsUploadCompleter[message.id] =
|
_messageAttachmentsUploadCompleter[message.id] =
|
||||||
attachmentsUploadCompleter;
|
attachmentsUploadCompleter;
|
||||||
@@ -383,7 +383,7 @@ class Channel {
|
|||||||
state?.addMessage(message);
|
state?.addMessage(message);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (message.attachments?.isNotEmpty == true) {
|
if (message.attachments?.any((it) => !it.uploadState.isSuccess) == true) {
|
||||||
final attachmentsUploadCompleter = Completer<Message>();
|
final attachmentsUploadCompleter = Completer<Message>();
|
||||||
_messageAttachmentsUploadCompleter[message.id] =
|
_messageAttachmentsUploadCompleter[message.id] =
|
||||||
attachmentsUploadCompleter;
|
attachmentsUploadCompleter;
|
||||||
@@ -449,6 +449,41 @@ class Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pins provided message
|
||||||
|
Future<UpdateMessageResponse> pinMessage(
|
||||||
|
Message message,
|
||||||
|
Object timeoutOrExpirationDate,
|
||||||
|
) {
|
||||||
|
assert(() {
|
||||||
|
if (timeoutOrExpirationDate is! DateTime &&
|
||||||
|
timeoutOrExpirationDate is! num &&
|
||||||
|
timeoutOrExpirationDate != null) {
|
||||||
|
throw ArgumentError('Invalid timeout or Expiration date');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
|
||||||
|
DateTime pinExpires;
|
||||||
|
if (timeoutOrExpirationDate is DateTime) {
|
||||||
|
pinExpires = timeoutOrExpirationDate;
|
||||||
|
} else if (timeoutOrExpirationDate is num) {
|
||||||
|
pinExpires = DateTime.now().add(
|
||||||
|
Duration(seconds: timeoutOrExpirationDate.toInt()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return updateMessage(
|
||||||
|
message.copyWith(
|
||||||
|
pinned: true,
|
||||||
|
pinExpires: pinExpires,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Unpins provided message
|
||||||
|
Future<UpdateMessageResponse> unpinMessage(Message message) {
|
||||||
|
return updateMessage(message.copyWith(pinned: false));
|
||||||
|
}
|
||||||
|
|
||||||
/// Send a file to this channel
|
/// Send a file to this channel
|
||||||
Future<SendFileResponse> sendFile(
|
Future<SendFileResponse> sendFile(
|
||||||
AttachmentFile file, {
|
AttachmentFile file, {
|
||||||
|
|||||||
@@ -1295,7 +1295,7 @@ class StreamChatClient {
|
|||||||
Future<UpdateMessageResponse> updateMessage(Message message) async {
|
Future<UpdateMessageResponse> updateMessage(Message message) async {
|
||||||
final response = await post(
|
final response = await post(
|
||||||
'/messages/${message.id}',
|
'/messages/${message.id}',
|
||||||
data: {'message': message},
|
data: {'message': message.toJson()},
|
||||||
);
|
);
|
||||||
return decode(response.data, UpdateMessageResponse.fromJson);
|
return decode(response.data, UpdateMessageResponse.fromJson);
|
||||||
}
|
}
|
||||||
@@ -1311,6 +1311,38 @@ class StreamChatClient {
|
|||||||
final response = await get('/messages/$messageId');
|
final response = await get('/messages/$messageId');
|
||||||
return decode(response.data, GetMessageResponse.fromJson);
|
return decode(response.data, GetMessageResponse.fromJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pins provided message
|
||||||
|
Future<UpdateMessageResponse> pinMessage(
|
||||||
|
Message message,
|
||||||
|
Object timeoutOrExpirationDate,
|
||||||
|
) {
|
||||||
|
assert(() {
|
||||||
|
if (timeoutOrExpirationDate is! DateTime &&
|
||||||
|
timeoutOrExpirationDate is! num &&
|
||||||
|
timeoutOrExpirationDate != null) {
|
||||||
|
throw ArgumentError('Invalid timeout or Expiration date');
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}());
|
||||||
|
|
||||||
|
DateTime pinExpires;
|
||||||
|
if (timeoutOrExpirationDate is DateTime) {
|
||||||
|
pinExpires = timeoutOrExpirationDate.toUtc();
|
||||||
|
} else if (timeoutOrExpirationDate is num) {
|
||||||
|
pinExpires = DateTime.now().add(
|
||||||
|
Duration(seconds: timeoutOrExpirationDate.toInt()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return updateMessage(
|
||||||
|
message.copyWith(pinned: true, pinExpires: pinExpires),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Unpins provided message
|
||||||
|
Future<UpdateMessageResponse> unpinMessage(Message message) {
|
||||||
|
return updateMessage(message.copyWith(pinned: false));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The class that handles the state of the channel listening to the events
|
/// The class that handles the state of the channel listening to the events
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ class ChannelState {
|
|||||||
/// A paginated list of channel members
|
/// A paginated list of channel members
|
||||||
final List<Member> members;
|
final List<Member> members;
|
||||||
|
|
||||||
|
/// A paginated list of pinned messages
|
||||||
|
final List<Message> pinnedMessages;
|
||||||
|
|
||||||
/// The count of users watching the channel
|
/// The count of users watching the channel
|
||||||
final int watcherCount;
|
final int watcherCount;
|
||||||
|
|
||||||
@@ -34,6 +37,7 @@ class ChannelState {
|
|||||||
this.channel,
|
this.channel,
|
||||||
this.messages = const [],
|
this.messages = const [],
|
||||||
this.members = const [],
|
this.members = const [],
|
||||||
|
this.pinnedMessages = const [],
|
||||||
this.watcherCount,
|
this.watcherCount,
|
||||||
this.watchers = const [],
|
this.watchers = const [],
|
||||||
this.read = const [],
|
this.read = const [],
|
||||||
@@ -51,6 +55,7 @@ class ChannelState {
|
|||||||
ChannelModel channel,
|
ChannelModel channel,
|
||||||
List<Message> messages,
|
List<Message> messages,
|
||||||
List<Member> members,
|
List<Member> members,
|
||||||
|
List<Message> pinnedMessages,
|
||||||
int watcherCount,
|
int watcherCount,
|
||||||
List<User> watchers,
|
List<User> watchers,
|
||||||
List<Read> read,
|
List<Read> read,
|
||||||
@@ -59,6 +64,7 @@ class ChannelState {
|
|||||||
channel: channel ?? this.channel,
|
channel: channel ?? this.channel,
|
||||||
messages: messages ?? this.messages,
|
messages: messages ?? this.messages,
|
||||||
members: members ?? this.members,
|
members: members ?? this.members,
|
||||||
|
pinnedMessages: pinnedMessages ?? this.pinnedMessages,
|
||||||
watcherCount: watcherCount ?? this.watcherCount,
|
watcherCount: watcherCount ?? this.watcherCount,
|
||||||
watchers: watchers ?? this.watchers,
|
watchers: watchers ?? this.watchers,
|
||||||
read: read ?? this.read,
|
read: read ?? this.read,
|
||||||
|
|||||||
@@ -27,6 +27,13 @@ ChannelState _$ChannelStateFromJson(Map json) {
|
|||||||
(k, e) => MapEntry(k as String, e),
|
(k, e) => MapEntry(k as String, e),
|
||||||
)))
|
)))
|
||||||
?.toList(),
|
?.toList(),
|
||||||
|
pinnedMessages: (json['pinned_messages'] as List)
|
||||||
|
?.map((e) => e == null
|
||||||
|
? null
|
||||||
|
: Message.fromJson((e as Map)?.map(
|
||||||
|
(k, e) => MapEntry(k as String, e),
|
||||||
|
)))
|
||||||
|
?.toList(),
|
||||||
watcherCount: json['watcher_count'] as int,
|
watcherCount: json['watcher_count'] as int,
|
||||||
watchers: (json['watchers'] as List)
|
watchers: (json['watchers'] as List)
|
||||||
?.map((e) => e == null
|
?.map((e) => e == null
|
||||||
@@ -50,6 +57,8 @@ Map<String, dynamic> _$ChannelStateToJson(ChannelState instance) =>
|
|||||||
'channel': instance.channel?.toJson(),
|
'channel': instance.channel?.toJson(),
|
||||||
'messages': instance.messages?.map((e) => e?.toJson())?.toList(),
|
'messages': instance.messages?.map((e) => e?.toJson())?.toList(),
|
||||||
'members': instance.members?.map((e) => e?.toJson())?.toList(),
|
'members': instance.members?.map((e) => e?.toJson())?.toList(),
|
||||||
|
'pinned_messages':
|
||||||
|
instance.pinnedMessages?.map((e) => e?.toJson())?.toList(),
|
||||||
'watcher_count': instance.watcherCount,
|
'watcher_count': instance.watcherCount,
|
||||||
'watchers': instance.watchers?.map((e) => e?.toJson())?.toList(),
|
'watchers': instance.watchers?.map((e) => e?.toJson())?.toList(),
|
||||||
'read': instance.read?.map((e) => e?.toJson())?.toList(),
|
'read': instance.read?.map((e) => e?.toJson())?.toList(),
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ import 'user.dart';
|
|||||||
|
|
||||||
part 'message.g.dart';
|
part 'message.g.dart';
|
||||||
|
|
||||||
|
class _PinExpires {
|
||||||
|
const _PinExpires();
|
||||||
|
}
|
||||||
|
|
||||||
|
const _pinExpires = _PinExpires();
|
||||||
|
|
||||||
/// Enum defining the status of a sending message
|
/// Enum defining the status of a sending message
|
||||||
enum MessageSendingStatus {
|
enum MessageSendingStatus {
|
||||||
/// Message is being sent
|
/// Message is being sent
|
||||||
@@ -117,6 +123,20 @@ class Message {
|
|||||||
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
|
@JsonKey(includeIfNull: false, toJson: Serialization.readOnly)
|
||||||
final User user;
|
final User user;
|
||||||
|
|
||||||
|
///
|
||||||
|
final bool pinned;
|
||||||
|
|
||||||
|
/// Reserved field indicating when the message was created.
|
||||||
|
@JsonKey(toJson: Serialization.readOnly)
|
||||||
|
final DateTime pinnedAt;
|
||||||
|
|
||||||
|
/// Reserved field indicating when the message was created.
|
||||||
|
final DateTime pinExpires;
|
||||||
|
|
||||||
|
///
|
||||||
|
@JsonKey(toJson: Serialization.readOnly)
|
||||||
|
final User pinnedBy;
|
||||||
|
|
||||||
/// Message custom extraData
|
/// Message custom extraData
|
||||||
@JsonKey(includeIfNull: false)
|
@JsonKey(includeIfNull: false)
|
||||||
final Map<String, dynamic> extraData;
|
final Map<String, dynamic> extraData;
|
||||||
@@ -160,6 +180,10 @@ class Message {
|
|||||||
'updated_at',
|
'updated_at',
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
'user',
|
'user',
|
||||||
|
'pinned',
|
||||||
|
'pinned_at',
|
||||||
|
'pin_expires',
|
||||||
|
'pinned_by',
|
||||||
];
|
];
|
||||||
|
|
||||||
/// Constructor used for json serialization
|
/// Constructor used for json serialization
|
||||||
@@ -185,10 +209,15 @@ class Message {
|
|||||||
this.createdAt,
|
this.createdAt,
|
||||||
this.updatedAt,
|
this.updatedAt,
|
||||||
this.user,
|
this.user,
|
||||||
|
this.pinned = false,
|
||||||
|
this.pinnedAt,
|
||||||
|
DateTime pinExpires,
|
||||||
|
this.pinnedBy,
|
||||||
this.extraData,
|
this.extraData,
|
||||||
this.deletedAt,
|
this.deletedAt,
|
||||||
this.status = MessageSendingStatus.sent,
|
this.status = MessageSendingStatus.sent,
|
||||||
}) : id = id ?? Uuid().v4();
|
}) : id = id ?? Uuid().v4(),
|
||||||
|
pinExpires = pinExpires?.toUtc();
|
||||||
|
|
||||||
/// Create a new instance from a json
|
/// Create a new instance from a json
|
||||||
factory Message.fromJson(Map<String, dynamic> json) => _$MessageFromJson(
|
factory Message.fromJson(Map<String, dynamic> json) => _$MessageFromJson(
|
||||||
@@ -222,35 +251,52 @@ class Message {
|
|||||||
DateTime updatedAt,
|
DateTime updatedAt,
|
||||||
DateTime deletedAt,
|
DateTime deletedAt,
|
||||||
User user,
|
User user,
|
||||||
|
bool pinned,
|
||||||
|
DateTime pinnedAt,
|
||||||
|
Object pinExpires = _pinExpires,
|
||||||
|
User pinnedBy,
|
||||||
Map<String, dynamic> extraData,
|
Map<String, dynamic> extraData,
|
||||||
MessageSendingStatus status,
|
MessageSendingStatus status,
|
||||||
}) =>
|
}) {
|
||||||
Message(
|
assert(() {
|
||||||
id: id ?? this.id,
|
if (pinExpires is! DateTime &&
|
||||||
text: text ?? this.text,
|
pinExpires != null &&
|
||||||
type: type ?? this.type,
|
pinExpires is! _PinExpires) {
|
||||||
attachments: attachments ?? this.attachments,
|
throw ArgumentError('`pinExpires` can only be set as DateTime or null');
|
||||||
mentionedUsers: mentionedUsers ?? this.mentionedUsers,
|
}
|
||||||
reactionCounts: reactionCounts ?? this.reactionCounts,
|
return true;
|
||||||
reactionScores: reactionScores ?? this.reactionScores,
|
}());
|
||||||
latestReactions: latestReactions ?? this.latestReactions,
|
return Message(
|
||||||
ownReactions: ownReactions ?? this.ownReactions,
|
id: id ?? this.id,
|
||||||
parentId: parentId ?? this.parentId,
|
text: text ?? this.text,
|
||||||
quotedMessage: quotedMessage ?? this.quotedMessage,
|
type: type ?? this.type,
|
||||||
quotedMessageId: quotedMessageId ?? this.quotedMessageId,
|
attachments: attachments ?? this.attachments,
|
||||||
replyCount: replyCount ?? this.replyCount,
|
mentionedUsers: mentionedUsers ?? this.mentionedUsers,
|
||||||
threadParticipants: threadParticipants ?? this.threadParticipants,
|
reactionCounts: reactionCounts ?? this.reactionCounts,
|
||||||
showInChannel: showInChannel ?? this.showInChannel,
|
reactionScores: reactionScores ?? this.reactionScores,
|
||||||
command: command ?? this.command,
|
latestReactions: latestReactions ?? this.latestReactions,
|
||||||
createdAt: createdAt ?? this.createdAt,
|
ownReactions: ownReactions ?? this.ownReactions,
|
||||||
silent: silent ?? this.silent,
|
parentId: parentId ?? this.parentId,
|
||||||
extraData: extraData ?? this.extraData,
|
quotedMessage: quotedMessage ?? this.quotedMessage,
|
||||||
user: user ?? this.user,
|
quotedMessageId: quotedMessageId ?? this.quotedMessageId,
|
||||||
shadowed: shadowed ?? this.shadowed,
|
replyCount: replyCount ?? this.replyCount,
|
||||||
updatedAt: updatedAt ?? this.updatedAt,
|
threadParticipants: threadParticipants ?? this.threadParticipants,
|
||||||
deletedAt: deletedAt ?? this.deletedAt,
|
showInChannel: showInChannel ?? this.showInChannel,
|
||||||
status: status ?? this.status,
|
command: command ?? this.command,
|
||||||
);
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
silent: silent ?? this.silent,
|
||||||
|
extraData: extraData ?? this.extraData,
|
||||||
|
user: user ?? this.user,
|
||||||
|
shadowed: shadowed ?? this.shadowed,
|
||||||
|
updatedAt: updatedAt ?? this.updatedAt,
|
||||||
|
deletedAt: deletedAt ?? this.deletedAt,
|
||||||
|
status: status ?? this.status,
|
||||||
|
pinned: pinned ?? this.pinned,
|
||||||
|
pinnedAt: pinnedAt ?? this.pinnedAt,
|
||||||
|
pinnedBy: pinnedBy ?? this.pinnedBy,
|
||||||
|
pinExpires: pinExpires == _pinExpires ? this.pinExpires : pinExpires,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns a new [Message] that is a combination of this message and the given
|
/// Returns a new [Message] that is a combination of this message and the given
|
||||||
/// [other] message.
|
/// [other] message.
|
||||||
@@ -281,6 +327,10 @@ class Message {
|
|||||||
updatedAt: other.updatedAt,
|
updatedAt: other.updatedAt,
|
||||||
deletedAt: other.deletedAt,
|
deletedAt: other.deletedAt,
|
||||||
status: other.status,
|
status: other.status,
|
||||||
|
pinned: other.pinned,
|
||||||
|
pinnedAt: other.pinnedAt,
|
||||||
|
pinExpires: other.pinExpires,
|
||||||
|
pinnedBy: other.pinnedBy,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,18 @@ Message _$MessageFromJson(Map json) {
|
|||||||
: User.fromJson((json['user'] as Map)?.map(
|
: User.fromJson((json['user'] as Map)?.map(
|
||||||
(k, e) => MapEntry(k as String, e),
|
(k, e) => MapEntry(k as String, e),
|
||||||
)),
|
)),
|
||||||
|
pinned: json['pinned'] as bool,
|
||||||
|
pinnedAt: json['pinned_at'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['pinned_at'] as String),
|
||||||
|
pinExpires: json['pin_expires'] == null
|
||||||
|
? null
|
||||||
|
: DateTime.parse(json['pin_expires'] as String),
|
||||||
|
pinnedBy: json['pinned_by'] == null
|
||||||
|
? null
|
||||||
|
: User.fromJson((json['pinned_by'] as Map)?.map(
|
||||||
|
(k, e) => MapEntry(k as String, e),
|
||||||
|
)),
|
||||||
extraData: (json['extra_data'] as Map)?.map(
|
extraData: (json['extra_data'] as Map)?.map(
|
||||||
(k, e) => MapEntry(k as String, e),
|
(k, e) => MapEntry(k as String, e),
|
||||||
),
|
),
|
||||||
@@ -116,6 +128,10 @@ Map<String, dynamic> _$MessageToJson(Message instance) {
|
|||||||
writeNotNull('created_at', readonly(instance.createdAt));
|
writeNotNull('created_at', readonly(instance.createdAt));
|
||||||
writeNotNull('updated_at', readonly(instance.updatedAt));
|
writeNotNull('updated_at', readonly(instance.updatedAt));
|
||||||
writeNotNull('user', readonly(instance.user));
|
writeNotNull('user', readonly(instance.user));
|
||||||
|
val['pinned'] = instance.pinned;
|
||||||
|
val['pinned_at'] = readonly(instance.pinnedAt);
|
||||||
|
val['pin_expires'] = instance.pinExpires?.toIso8601String();
|
||||||
|
val['pinned_by'] = readonly(instance.pinnedBy);
|
||||||
writeNotNull('extra_data', instance.extraData);
|
writeNotNull('extra_data', instance.extraData);
|
||||||
writeNotNull('deleted_at', readonly(instance.deletedAt));
|
writeNotNull('deleted_at', readonly(instance.deletedAt));
|
||||||
return val;
|
return val;
|
||||||
|
|||||||
@@ -273,6 +273,79 @@ void main() {
|
|||||||
verify(mockDio.delete<String>('/channels/messaging/testid/image',
|
verify(mockDio.delete<String>('/channels/messaging/testid/image',
|
||||||
queryParameters: {'url': url})).called(1);
|
queryParameters: {'url': url})).called(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('pinMessage should throw argument error', () {
|
||||||
|
final client = StreamChatClient('api-key');
|
||||||
|
|
||||||
|
final channelClient = client.channel('messaging', id: 'testid');
|
||||||
|
|
||||||
|
final message = Message(text: 'Hello');
|
||||||
|
|
||||||
|
expect(
|
||||||
|
() => channelClient.pinMessage(message, 'InvalidType'),
|
||||||
|
throwsArgumentError,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should be pinned successfully', () async {
|
||||||
|
final mockDio = MockDio();
|
||||||
|
|
||||||
|
when(mockDio.options).thenReturn(BaseOptions());
|
||||||
|
when(mockDio.interceptors).thenReturn(Interceptors());
|
||||||
|
|
||||||
|
final client = StreamChatClient(
|
||||||
|
'api-key',
|
||||||
|
httpClient: mockDio,
|
||||||
|
tokenProvider: (_) async => '',
|
||||||
|
);
|
||||||
|
|
||||||
|
final channelClient = client.channel('messaging', id: 'testid');
|
||||||
|
|
||||||
|
final message = Message(
|
||||||
|
text: 'Hello',
|
||||||
|
id: 'test',
|
||||||
|
);
|
||||||
|
|
||||||
|
when(mockDio.post<String>(
|
||||||
|
'/messages/${message.id}',
|
||||||
|
data: anything,
|
||||||
|
)).thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
||||||
|
|
||||||
|
await channelClient.pinMessage(message, 30);
|
||||||
|
|
||||||
|
verify(mockDio.post<String>('/messages/${message.id}', data: anything))
|
||||||
|
.called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should be unpinned successfully', () async {
|
||||||
|
final mockDio = MockDio();
|
||||||
|
|
||||||
|
when(mockDio.options).thenReturn(BaseOptions());
|
||||||
|
when(mockDio.interceptors).thenReturn(Interceptors());
|
||||||
|
|
||||||
|
final client = StreamChatClient(
|
||||||
|
'api-key',
|
||||||
|
httpClient: mockDio,
|
||||||
|
tokenProvider: (_) async => '',
|
||||||
|
);
|
||||||
|
|
||||||
|
final channelClient = client.channel('messaging', id: 'testid');
|
||||||
|
|
||||||
|
final message = Message(
|
||||||
|
text: 'Hello',
|
||||||
|
id: 'test',
|
||||||
|
);
|
||||||
|
|
||||||
|
when(mockDio.post<String>(
|
||||||
|
'/messages/${message.id}',
|
||||||
|
data: anything,
|
||||||
|
)).thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
||||||
|
|
||||||
|
await channelClient.unpinMessage(message);
|
||||||
|
|
||||||
|
verify(mockDio.post<String>('/messages/${message.id}', data: anything))
|
||||||
|
.called(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sendEvent', () async {
|
test('sendEvent', () async {
|
||||||
|
|||||||
@@ -934,6 +934,56 @@ void main() {
|
|||||||
expect(client.delete('/test'), throwsA(ApiError('test error', 400)));
|
expect(client.delete('/test'), throwsA(ApiError('test error', 400)));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('pin message', () {
|
||||||
|
final mockDio = MockDio();
|
||||||
|
|
||||||
|
when(mockDio.options).thenReturn(BaseOptions());
|
||||||
|
when(mockDio.interceptors).thenReturn(Interceptors());
|
||||||
|
|
||||||
|
final client = StreamChatClient(
|
||||||
|
'api-key',
|
||||||
|
httpClient: mockDio,
|
||||||
|
);
|
||||||
|
|
||||||
|
test('should throw argument error', () {
|
||||||
|
final message = Message(text: 'Hello');
|
||||||
|
expect(
|
||||||
|
() => client.pinMessage(message, 'InvalidType'),
|
||||||
|
throwsArgumentError,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should complete successfully', () async {
|
||||||
|
final timeout = 30;
|
||||||
|
final message = Message(text: 'Hello');
|
||||||
|
|
||||||
|
when(mockDio.post<String>(
|
||||||
|
'/messages/${message.id}',
|
||||||
|
data: anything,
|
||||||
|
)).thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
||||||
|
|
||||||
|
await client.pinMessage(message, timeout);
|
||||||
|
|
||||||
|
verify(mockDio.post<String>('/messages/${message.id}',
|
||||||
|
data: {'message': anything})).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should unpin message successfully', () async {
|
||||||
|
final message = Message(text: 'Hello');
|
||||||
|
|
||||||
|
when(mockDio.post<String>(
|
||||||
|
'/messages/${message.id}',
|
||||||
|
data: anything,
|
||||||
|
)).thenAnswer((_) async => Response(data: '{}', statusCode: 200));
|
||||||
|
|
||||||
|
await client.unpinMessage(message);
|
||||||
|
|
||||||
|
verify(mockDio.post<String>('/messages/${message.id}',
|
||||||
|
data: anything))
|
||||||
|
.called(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user