@@ -334,20 +334,87 @@ void main() {
|
|||||||
expectLater(
|
expectLater(
|
||||||
// skipping first seed message list -> [] messages
|
// skipping first seed message list -> [] messages
|
||||||
channel.state?.messagesStream.skip(1),
|
channel.state?.messagesStream.skip(1),
|
||||||
emitsInOrder([
|
emitsInOrder(
|
||||||
[
|
[
|
||||||
isSameMessageAs(
|
// preparing attachments to upload
|
||||||
message.copyWith(status: MessageSendingStatus.sending),
|
[
|
||||||
matchSendingStatus: true,
|
isSameMessageAs(
|
||||||
),
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.sending,
|
||||||
|
attachments: [
|
||||||
|
...attachments.map((it) => it.copyWith(
|
||||||
|
uploadState: const UploadState.preparing()))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
// 0th attachment is successfully uploaded
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.sending,
|
||||||
|
attachments: [...attachments]..[0] =
|
||||||
|
attachments[0].copyWith(
|
||||||
|
uploadState: const UploadState.success(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
// 0th and 1st attachment is successfully uploaded
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.sending,
|
||||||
|
attachments: [...attachments]
|
||||||
|
..[0] = attachments[0].copyWith(
|
||||||
|
uploadState: const UploadState.success(),
|
||||||
|
)
|
||||||
|
..[1] = attachments[1].copyWith(
|
||||||
|
uploadState: const UploadState.success(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
// all the attachments are successfully uploaded
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.sending,
|
||||||
|
attachments: [
|
||||||
|
...attachments.map((it) =>
|
||||||
|
it.copyWith(uploadState: const UploadState.success()))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
|
attachments: [
|
||||||
|
...attachments.map((it) =>
|
||||||
|
it.copyWith(uploadState: const UploadState.success()))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
[
|
),
|
||||||
isSameMessageAs(
|
|
||||||
message.copyWith(status: MessageSendingStatus.sent),
|
|
||||||
matchSendingStatus: true,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final res = await channel.sendMessage(message);
|
final res = await channel.sendMessage(message);
|
||||||
@@ -472,20 +539,87 @@ void main() {
|
|||||||
expectLater(
|
expectLater(
|
||||||
// skipping first seed message list -> [] messages
|
// skipping first seed message list -> [] messages
|
||||||
channel.state?.messagesStream.skip(1),
|
channel.state?.messagesStream.skip(1),
|
||||||
emitsInOrder([
|
emitsInOrder(
|
||||||
[
|
[
|
||||||
isSameMessageAs(
|
// preparing attachments to upload
|
||||||
message.copyWith(status: MessageSendingStatus.updating),
|
[
|
||||||
matchSendingStatus: true,
|
isSameMessageAs(
|
||||||
),
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.updating,
|
||||||
|
attachments: [
|
||||||
|
...attachments.map((it) => it.copyWith(
|
||||||
|
uploadState: const UploadState.preparing()))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
// 0th attachment is successfully uploaded
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.updating,
|
||||||
|
attachments: [...attachments]..[0] =
|
||||||
|
attachments[0].copyWith(
|
||||||
|
uploadState: const UploadState.success(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
// 0th and 1st attachment is successfully uploaded
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.updating,
|
||||||
|
attachments: [...attachments]
|
||||||
|
..[0] = attachments[0].copyWith(
|
||||||
|
uploadState: const UploadState.success(),
|
||||||
|
)
|
||||||
|
..[1] = attachments[1].copyWith(
|
||||||
|
uploadState: const UploadState.success(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
// all the attachments are successfully uploaded
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.updating,
|
||||||
|
attachments: [
|
||||||
|
...attachments.map((it) =>
|
||||||
|
it.copyWith(uploadState: const UploadState.success()))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
isSameMessageAs(
|
||||||
|
message.copyWith(
|
||||||
|
status: MessageSendingStatus.sent,
|
||||||
|
attachments: [
|
||||||
|
...attachments.map((it) =>
|
||||||
|
it.copyWith(uploadState: const UploadState.success()))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
matchSendingStatus: true,
|
||||||
|
matchAttachments: true,
|
||||||
|
matchAttachmentsUploadState: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
[
|
),
|
||||||
isSameMessageAs(
|
|
||||||
message.copyWith(status: MessageSendingStatus.sent),
|
|
||||||
matchSendingStatus: true,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
]),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final res = await channel.updateMessage(message);
|
final res = await channel.updateMessage(message);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:dio/dio.dart' show MultipartFile;
|
import 'package:dio/dio.dart' show MultipartFile;
|
||||||
import 'package:stream_chat/src/client/channel.dart';
|
import 'package:stream_chat/src/client/channel.dart';
|
||||||
|
import 'package:stream_chat/src/core/models/attachment.dart';
|
||||||
import 'package:stream_chat/src/core/models/channel_state.dart';
|
import 'package:stream_chat/src/core/models/channel_state.dart';
|
||||||
import 'package:stream_chat/src/core/models/event.dart';
|
import 'package:stream_chat/src/core/models/event.dart';
|
||||||
import 'package:stream_chat/src/core/models/message.dart';
|
import 'package:stream_chat/src/core/models/message.dart';
|
||||||
@@ -46,12 +47,16 @@ Matcher isSameMessageAs(
|
|||||||
bool matchText = false,
|
bool matchText = false,
|
||||||
bool matchReactions = false,
|
bool matchReactions = false,
|
||||||
bool matchSendingStatus = false,
|
bool matchSendingStatus = false,
|
||||||
|
bool matchAttachments = false,
|
||||||
|
bool matchAttachmentsUploadState = false,
|
||||||
}) =>
|
}) =>
|
||||||
_IsSameMessageAs(
|
_IsSameMessageAs(
|
||||||
targetMessage: targetMessage,
|
targetMessage: targetMessage,
|
||||||
matchText: matchText,
|
matchText: matchText,
|
||||||
matchReactions: matchReactions,
|
matchReactions: matchReactions,
|
||||||
matchSendingStatus: matchSendingStatus,
|
matchSendingStatus: matchSendingStatus,
|
||||||
|
matchAttachments: matchAttachments,
|
||||||
|
matchAttachmentsUploadState: matchAttachmentsUploadState,
|
||||||
);
|
);
|
||||||
|
|
||||||
class _IsSameMessageAs extends Matcher {
|
class _IsSameMessageAs extends Matcher {
|
||||||
@@ -60,12 +65,16 @@ class _IsSameMessageAs extends Matcher {
|
|||||||
this.matchText = false,
|
this.matchText = false,
|
||||||
this.matchReactions = false,
|
this.matchReactions = false,
|
||||||
this.matchSendingStatus = false,
|
this.matchSendingStatus = false,
|
||||||
|
this.matchAttachments = false,
|
||||||
|
this.matchAttachmentsUploadState = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Message targetMessage;
|
final Message targetMessage;
|
||||||
final bool matchText;
|
final bool matchText;
|
||||||
final bool matchReactions;
|
final bool matchReactions;
|
||||||
final bool matchSendingStatus;
|
final bool matchSendingStatus;
|
||||||
|
final bool matchAttachments;
|
||||||
|
final bool matchAttachmentsUploadState;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Description describe(Description description) =>
|
Description describe(Description description) =>
|
||||||
@@ -96,6 +105,56 @@ class _IsSameMessageAs extends Matcher {
|
|||||||
?.map((it) => '${it.type}-${it.messageId}')
|
?.map((it) => '${it.type}-${it.messageId}')
|
||||||
.toList());
|
.toList());
|
||||||
}
|
}
|
||||||
|
if (matchAttachments) {
|
||||||
|
bool matchAttachments() {
|
||||||
|
final attachments = message.attachments;
|
||||||
|
final targetAttachments = targetMessage.attachments;
|
||||||
|
if (identical(attachments, targetAttachments)) return true;
|
||||||
|
final length = attachments.length;
|
||||||
|
if (length != targetAttachments.length) return false;
|
||||||
|
for (var i = 0; i < length; i++) {
|
||||||
|
if (!isSameAttachmentAs(
|
||||||
|
attachments[i],
|
||||||
|
matchUploadState: matchAttachmentsUploadState,
|
||||||
|
).matches(targetAttachments[i], matchState)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
matches &= matchAttachments();
|
||||||
|
}
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Matcher isSameAttachmentAs(
|
||||||
|
Attachment targetAttachment, {
|
||||||
|
bool matchUploadState = false,
|
||||||
|
}) =>
|
||||||
|
_IsSameAttachmentAs(
|
||||||
|
targetAttachment: targetAttachment,
|
||||||
|
matchUploadState: matchUploadState,
|
||||||
|
);
|
||||||
|
|
||||||
|
class _IsSameAttachmentAs extends Matcher {
|
||||||
|
const _IsSameAttachmentAs({
|
||||||
|
required this.targetAttachment,
|
||||||
|
this.matchUploadState = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Attachment targetAttachment;
|
||||||
|
final bool matchUploadState;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Description describe(Description description) =>
|
||||||
|
description.add('is same attachment as $targetAttachment');
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool matches(covariant Attachment attachment, Map matchState) {
|
||||||
|
var matches = attachment.id == targetAttachment.id;
|
||||||
|
if (matchUploadState) {
|
||||||
|
matches &= attachment.uploadState == targetAttachment.uploadState;
|
||||||
|
}
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user