chore: migrate and update tests.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -133,7 +133,7 @@ void main() {
|
||||
|
||||
final retryPolicy = RetryPolicy(
|
||||
shouldRetry: (_, __, ___) => false,
|
||||
retryTimeout: (_, __, ___) => Duration.zero,
|
||||
delayFactor: Duration.zero,
|
||||
);
|
||||
when(() => client.retryPolicy).thenReturn(retryPolicy);
|
||||
|
||||
@@ -191,7 +191,7 @@ void main() {
|
||||
|
||||
final retryPolicy = RetryPolicy(
|
||||
shouldRetry: (_, __, ___) => false,
|
||||
retryTimeout: (_, __, ___) => Duration.zero,
|
||||
delayFactor: Duration.zero,
|
||||
);
|
||||
when(() => client.retryPolicy).thenReturn(retryPolicy);
|
||||
|
||||
@@ -253,7 +253,7 @@ void main() {
|
||||
);
|
||||
|
||||
final sendMessageResponse = SendMessageResponse()
|
||||
..message = message.copyWith(status: MessageSendingStatus.sent);
|
||||
..message = message.copyWith(state: MessageState.sent);
|
||||
|
||||
when(() => client.sendMessage(
|
||||
any(that: isSameMessageAs(message)),
|
||||
@@ -267,14 +267,14 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sending),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.sending),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.sent),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -338,7 +338,7 @@ void main() {
|
||||
.map((it) =>
|
||||
it.copyWith(uploadState: const UploadState.success()))
|
||||
.toList(growable: false),
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
));
|
||||
|
||||
expectLater(
|
||||
@@ -350,13 +350,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sending,
|
||||
state: MessageState.sending,
|
||||
attachments: [
|
||||
...attachments.map((it) => it.copyWith(
|
||||
uploadState: const UploadState.preparing()))
|
||||
],
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -365,13 +365,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sending,
|
||||
state: MessageState.sending,
|
||||
attachments: [...attachments]..[0] =
|
||||
attachments[0].copyWith(
|
||||
uploadState: const UploadState.success(),
|
||||
),
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -380,7 +380,7 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sending,
|
||||
state: MessageState.sending,
|
||||
attachments: [...attachments]
|
||||
..[0] = attachments[0].copyWith(
|
||||
uploadState: const UploadState.success(),
|
||||
@@ -389,7 +389,7 @@ void main() {
|
||||
uploadState: const UploadState.success(),
|
||||
),
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -398,13 +398,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sending,
|
||||
state: MessageState.sending,
|
||||
attachments: [
|
||||
...attachments.map((it) =>
|
||||
it.copyWith(uploadState: const UploadState.success()))
|
||||
],
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -412,13 +412,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
attachments: [
|
||||
...attachments.map((it) =>
|
||||
it.copyWith(uploadState: const UploadState.success()))
|
||||
],
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -469,7 +469,7 @@ void main() {
|
||||
test('should work fine', () async {
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
final updateMessageResponse = UpdateMessageResponse()
|
||||
@@ -484,14 +484,14 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.updating),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.updating),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.updated),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -547,7 +547,7 @@ void main() {
|
||||
any(that: isSameMessageAs(message)),
|
||||
)).thenAnswer((_) async => UpdateMessageResponse()
|
||||
..message = message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
attachments: attachments
|
||||
.map((it) =>
|
||||
it.copyWith(uploadState: const UploadState.success()))
|
||||
@@ -563,13 +563,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.updating,
|
||||
state: MessageState.updating,
|
||||
attachments: [
|
||||
...attachments.map((it) => it.copyWith(
|
||||
uploadState: const UploadState.preparing()))
|
||||
],
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -578,13 +578,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.updating,
|
||||
state: MessageState.updating,
|
||||
attachments: [...attachments]..[0] =
|
||||
attachments[0].copyWith(
|
||||
uploadState: const UploadState.success(),
|
||||
),
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -593,7 +593,7 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.updating,
|
||||
state: MessageState.updating,
|
||||
attachments: [...attachments]
|
||||
..[0] = attachments[0].copyWith(
|
||||
uploadState: const UploadState.success(),
|
||||
@@ -602,7 +602,7 @@ void main() {
|
||||
uploadState: const UploadState.success(),
|
||||
),
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -611,13 +611,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.updating,
|
||||
state: MessageState.updating,
|
||||
attachments: [
|
||||
...attachments.map((it) =>
|
||||
it.copyWith(uploadState: const UploadState.success()))
|
||||
],
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -625,13 +625,13 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.updated,
|
||||
attachments: [
|
||||
...attachments.map((it) =>
|
||||
it.copyWith(uploadState: const UploadState.success()))
|
||||
],
|
||||
),
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchAttachments: true,
|
||||
matchAttachmentsUploadState: true,
|
||||
),
|
||||
@@ -677,7 +677,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('`.partialUpdateMessage`', () async {
|
||||
final message = Message(id: 'test-message-id');
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
const set = {'text': 'Update Message text'};
|
||||
const unset = ['pinExpires'];
|
||||
@@ -689,19 +692,26 @@ void main() {
|
||||
() => client.partialUpdateMessage(message.id, set: set, unset: unset),
|
||||
).thenAnswer((_) async => updateMessageResponse);
|
||||
|
||||
channel.state?.messagesStream.skip(1).listen(print);
|
||||
|
||||
expectLater(
|
||||
// skipping first seed message list -> [] messages
|
||||
channel.state?.messagesStream.skip(1),
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
updateMessageResponse.message.copyWith(
|
||||
status: MessageSendingStatus.sending,
|
||||
message.copyWith(
|
||||
state: MessageState.updating,
|
||||
),
|
||||
matchText: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
updateMessageResponse.message.copyWith(
|
||||
state: MessageState.updated,
|
||||
),
|
||||
matchText: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -729,7 +739,8 @@ void main() {
|
||||
const messageId = 'test-message-id';
|
||||
final message = Message(
|
||||
id: messageId,
|
||||
status: MessageSendingStatus.sent,
|
||||
createdAt: DateTime.now(),
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
when(() => client.deleteMessage(messageId))
|
||||
@@ -741,14 +752,14 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.deleting),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.softDeleting),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.softDeleted),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -775,8 +786,8 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.softDeleted),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -785,6 +796,7 @@ void main() {
|
||||
final res = await channel.deleteMessage(message);
|
||||
|
||||
expect(res, isNotNull);
|
||||
verifyNever(() => client.deleteMessage(messageId));
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -802,7 +814,6 @@ void main() {
|
||||
..message = message.copyWith(
|
||||
pinned: true,
|
||||
pinExpires: null,
|
||||
status: MessageSendingStatus.sent,
|
||||
));
|
||||
|
||||
expectLater(
|
||||
@@ -811,8 +822,14 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.updating),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(state: MessageState.updated),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -847,7 +864,6 @@ void main() {
|
||||
pinExpires: DateTime.now().add(
|
||||
const Duration(seconds: timeoutOrExpirationDate),
|
||||
),
|
||||
status: MessageSendingStatus.sent,
|
||||
));
|
||||
|
||||
expectLater(
|
||||
@@ -856,8 +872,14 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.updating),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(state: MessageState.updated),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -895,7 +917,6 @@ void main() {
|
||||
..message = message.copyWith(
|
||||
pinned: true,
|
||||
pinExpires: timeoutOrExpirationDate,
|
||||
status: MessageSendingStatus.sent,
|
||||
));
|
||||
|
||||
expectLater(
|
||||
@@ -904,8 +925,14 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.updating),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(state: MessageState.updated),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -954,10 +981,7 @@ void main() {
|
||||
message.id,
|
||||
set: {'pinned': false},
|
||||
)).thenAnswer((_) async => UpdateMessageResponse()
|
||||
..message = message.copyWith(
|
||||
pinned: false,
|
||||
status: MessageSendingStatus.sent,
|
||||
));
|
||||
..message = message.copyWith(pinned: false));
|
||||
|
||||
expectLater(
|
||||
// skipping first seed message list -> [] messages
|
||||
@@ -965,8 +989,14 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(status: MessageSendingStatus.sent),
|
||||
matchSendingStatus: true,
|
||||
message.copyWith(state: MessageState.updating),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(state: MessageState.updated),
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1101,7 +1131,7 @@ void main() {
|
||||
const type = 'test-reaction-type';
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
final reaction = Reaction(type: type, messageId: message.id);
|
||||
@@ -1119,14 +1149,14 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: 1},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1145,7 +1175,7 @@ void main() {
|
||||
const type = 'test-reaction-type';
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
const score = 5;
|
||||
@@ -1172,14 +1202,14 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: score},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1208,7 +1238,7 @@ void main() {
|
||||
const type = 'test-reaction-type';
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
const score = 5;
|
||||
@@ -1240,14 +1270,14 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: extraDataScore},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1282,7 +1312,7 @@ void main() {
|
||||
const type = 'test-reaction-type';
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
final reaction = Reaction(type: type, messageId: message.id);
|
||||
@@ -1297,21 +1327,21 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: 1},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message,
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1344,7 +1374,7 @@ void main() {
|
||||
latestReactions: [prevReaction],
|
||||
reactionScores: const {prevType: 1},
|
||||
reactionCounts: const {prevType: 1},
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
const type = 'test-reaction-type-2';
|
||||
@@ -1378,7 +1408,7 @@ void main() {
|
||||
isSameMessageAs(
|
||||
newMessage,
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1409,7 +1439,7 @@ void main() {
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
parentId: 'test-parent-id', // is thread message
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
final reaction = Reaction(type: type, messageId: message.id);
|
||||
@@ -1429,14 +1459,14 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: 1},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
@@ -1459,7 +1489,7 @@ void main() {
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
parentId: 'test-parent-id', // is thread message
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
final reaction = Reaction(type: type, messageId: message.id);
|
||||
@@ -1476,14 +1506,14 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
reactionCounts: {type: 1},
|
||||
reactionScores: {type: 1},
|
||||
latestReactions: [reaction],
|
||||
ownReactions: [reaction],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
@@ -1491,7 +1521,7 @@ void main() {
|
||||
isSameMessageAs(
|
||||
message,
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
@@ -1527,7 +1557,7 @@ void main() {
|
||||
latestReactions: [prevReaction],
|
||||
reactionScores: const {prevType: 1},
|
||||
reactionCounts: const {prevType: 1},
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
const type = 'test-reaction-type-2';
|
||||
@@ -1561,9 +1591,9 @@ void main() {
|
||||
emitsInOrder([
|
||||
[
|
||||
isSameMessageAs(
|
||||
newMessage.copyWith(status: MessageSendingStatus.sent),
|
||||
newMessage.copyWith(state: MessageState.sent),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
@@ -1605,7 +1635,7 @@ void main() {
|
||||
latestReactions: [reaction],
|
||||
reactionScores: const {type: 1},
|
||||
reactionCounts: const {type: 1},
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
when(() => client.deleteReaction(messageId, type))
|
||||
@@ -1618,12 +1648,12 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
latestReactions: [],
|
||||
ownReactions: [],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1653,7 +1683,7 @@ void main() {
|
||||
latestReactions: [reaction],
|
||||
reactionScores: const {type: 1},
|
||||
reactionCounts: const {type: 1},
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
when(() => client.deleteReaction(messageId, type))
|
||||
@@ -1666,19 +1696,19 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
latestReactions: [],
|
||||
ownReactions: [],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
[
|
||||
isSameMessageAs(
|
||||
message,
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
@@ -1714,7 +1744,7 @@ void main() {
|
||||
latestReactions: [reaction],
|
||||
reactionScores: const {type: 1},
|
||||
reactionCounts: const {type: 1},
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
when(() => client.deleteReaction(messageId, type))
|
||||
@@ -1729,12 +1759,12 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
latestReactions: [],
|
||||
ownReactions: [],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
@@ -1767,7 +1797,7 @@ void main() {
|
||||
latestReactions: [reaction],
|
||||
reactionScores: const {type: 1},
|
||||
reactionCounts: const {type: 1},
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
);
|
||||
|
||||
when(() => client.deleteReaction(messageId, type))
|
||||
@@ -1782,12 +1812,12 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message.copyWith(
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
latestReactions: [],
|
||||
ownReactions: [],
|
||||
),
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
@@ -1795,7 +1825,7 @@ void main() {
|
||||
isSameMessageAs(
|
||||
message,
|
||||
matchReactions: true,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
matchParentId: true,
|
||||
),
|
||||
],
|
||||
@@ -2144,7 +2174,7 @@ void main() {
|
||||
[
|
||||
isSameMessageAs(
|
||||
message,
|
||||
matchSendingStatus: true,
|
||||
matchMessageState: true,
|
||||
),
|
||||
],
|
||||
]),
|
||||
|
||||
@@ -2236,13 +2236,13 @@ void main() {
|
||||
test('`.deleteMessage`', () async {
|
||||
const messageId = 'test-message-id';
|
||||
|
||||
when(() => api.message.deleteMessage(messageId))
|
||||
when(() => api.message.deleteMessage(messageId, hard: false))
|
||||
.thenAnswer((_) async => EmptyResponse());
|
||||
|
||||
final res = await client.deleteMessage(messageId);
|
||||
expect(res, isNotNull);
|
||||
|
||||
verify(() => api.message.deleteMessage(messageId)).called(1);
|
||||
verify(() => api.message.deleteMessage(messageId, hard: false)).called(1);
|
||||
verifyNoMoreInteractions(api.message);
|
||||
});
|
||||
|
||||
@@ -2359,7 +2359,7 @@ void main() {
|
||||
..message = message.copyWith(
|
||||
pinned: true,
|
||||
pinExpires: null,
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
));
|
||||
|
||||
final res = await client.pinMessage(messageId);
|
||||
@@ -2393,7 +2393,7 @@ void main() {
|
||||
pinExpires: DateTime.now().add(
|
||||
const Duration(seconds: timeoutOrExpirationDate),
|
||||
),
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
));
|
||||
|
||||
final res = await client.pinMessage(
|
||||
@@ -2430,7 +2430,7 @@ void main() {
|
||||
..message = message.copyWith(
|
||||
pinned: true,
|
||||
pinExpires: timeoutOrExpirationDate,
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
));
|
||||
|
||||
final res = await client.pinMessage(
|
||||
@@ -2480,7 +2480,7 @@ void main() {
|
||||
)).thenAnswer((_) async => UpdateMessageResponse()
|
||||
..message = message.copyWith(
|
||||
pinned: false,
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
));
|
||||
|
||||
final res = await client.unpinMessage(messageId);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:stream_chat/src/client/retry_policy.dart';
|
||||
import 'package:stream_chat/src/client/retry_queue.dart';
|
||||
import 'package:stream_chat/src/core/models/event.dart';
|
||||
import 'package:stream_chat/src/core/models/message.dart';
|
||||
import 'package:stream_chat/src/event_type.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../mocks.dart';
|
||||
@@ -15,8 +13,9 @@ void main() {
|
||||
|
||||
setUpAll(() {
|
||||
final retryPolicy = RetryPolicy(
|
||||
shouldRetry: (_, attempt, __) => attempt < 5,
|
||||
retryTimeout: (_, attempt, __) => Duration(seconds: attempt),
|
||||
shouldRetry: (_, __, error) {
|
||||
return error is StreamChatNetworkError && error.isRetriable;
|
||||
},
|
||||
);
|
||||
when(() => channel.client.retryPolicy).thenReturn(retryPolicy);
|
||||
|
||||
@@ -48,21 +47,32 @@ void main() {
|
||||
verifyNever(() => logger.info(any()));
|
||||
});
|
||||
|
||||
test('should throw if message state is not failed', () {
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
text: 'Sample message test',
|
||||
state: MessageState.sent,
|
||||
);
|
||||
expect(() => retryQueue.add([message]), throwsA(isA<AssertionError>()));
|
||||
});
|
||||
|
||||
test('should return if queue already contains the message', () {
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
text: 'Sample message test',
|
||||
state: MessageState.sendingFailed,
|
||||
);
|
||||
retryQueue.add([message]);
|
||||
expect(() => retryQueue.add([message]), returnsNormally);
|
||||
// Called only for the first message
|
||||
verify(() => logger.info('Adding 1 messages')).called(1);
|
||||
verify(() => logger.info('Adding 1 messages to the queue')).called(1);
|
||||
});
|
||||
|
||||
test('`.add` should add failed request to the queue', () async {
|
||||
final message = Message(
|
||||
id: 'test-message-id',
|
||||
text: 'Sample message test',
|
||||
state: MessageState.sendingFailed,
|
||||
);
|
||||
retryQueue.add([message]);
|
||||
expect(retryQueue.hasMessages, isTrue);
|
||||
|
||||
@@ -46,7 +46,7 @@ Matcher isSameMessageAs(
|
||||
Message targetMessage, {
|
||||
bool matchText = false,
|
||||
bool matchReactions = false,
|
||||
bool matchSendingStatus = false,
|
||||
bool matchMessageState = false,
|
||||
bool matchAttachments = false,
|
||||
bool matchAttachmentsUploadState = false,
|
||||
bool matchParentId = false,
|
||||
@@ -55,7 +55,7 @@ Matcher isSameMessageAs(
|
||||
targetMessage: targetMessage,
|
||||
matchText: matchText,
|
||||
matchReactions: matchReactions,
|
||||
matchSendingStatus: matchSendingStatus,
|
||||
matchMessageState: matchMessageState,
|
||||
matchAttachments: matchAttachments,
|
||||
matchAttachmentsUploadState: matchAttachmentsUploadState,
|
||||
matchParentId: matchParentId,
|
||||
@@ -66,7 +66,7 @@ class _IsSameMessageAs extends Matcher {
|
||||
required this.targetMessage,
|
||||
this.matchText = false,
|
||||
this.matchReactions = false,
|
||||
this.matchSendingStatus = false,
|
||||
this.matchMessageState = false,
|
||||
this.matchAttachments = false,
|
||||
this.matchAttachmentsUploadState = false,
|
||||
this.matchParentId = false,
|
||||
@@ -75,7 +75,7 @@ class _IsSameMessageAs extends Matcher {
|
||||
final Message targetMessage;
|
||||
final bool matchText;
|
||||
final bool matchReactions;
|
||||
final bool matchSendingStatus;
|
||||
final bool matchMessageState;
|
||||
final bool matchAttachments;
|
||||
final bool matchAttachmentsUploadState;
|
||||
final bool matchParentId;
|
||||
@@ -90,8 +90,8 @@ class _IsSameMessageAs extends Matcher {
|
||||
if (matchText) {
|
||||
matches &= message.text == targetMessage.text;
|
||||
}
|
||||
if (matchSendingStatus) {
|
||||
matches &= message.status == targetMessage.status;
|
||||
if (matchMessageState) {
|
||||
matches &= message.state == targetMessage.state;
|
||||
}
|
||||
if (matchReactions) {
|
||||
matches &= const ListEquality().equals(
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ class StreamAttachmentUploadStateBuilder extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (message.status == MessageSendingStatus.sent) {
|
||||
if (message.state.isCompleted) {
|
||||
return const Offstage();
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ class _FailedState extends StatelessWidget {
|
||||
horizontal: 12,
|
||||
),
|
||||
child: Text(
|
||||
context.translations.uploadErrorLabel,
|
||||
error ?? 'Failed to upload file',
|
||||
style: theme.textTheme.footnote.copyWith(
|
||||
color: theme.colorTheme.barsBg,
|
||||
),
|
||||
|
||||
@@ -236,7 +236,7 @@ class _Trailing extends StatelessWidget {
|
||||
final channel = StreamChannel.of(context).channel;
|
||||
final attachmentId = attachment.id;
|
||||
|
||||
if (message.status == MessageSendingStatus.sent) {
|
||||
if (message.state.isCompleted) {
|
||||
return IconButton(
|
||||
icon: StreamSvgIcon.cloudDownload(
|
||||
color: theme.colorTheme.textHighEmphasis,
|
||||
|
||||
@@ -30,14 +30,13 @@ class StreamSendingIndicator extends StatelessWidget {
|
||||
color: StreamChatTheme.of(context).colorTheme.accentPrimary,
|
||||
);
|
||||
}
|
||||
if (message.status == MessageSendingStatus.sent) {
|
||||
if (message.state.isCompleted) {
|
||||
return StreamSvgIcon.check(
|
||||
size: size,
|
||||
color: StreamChatTheme.of(context).colorTheme.textLowEmphasis,
|
||||
);
|
||||
}
|
||||
if (message.status == MessageSendingStatus.sending ||
|
||||
message.status == MessageSendingStatus.updating) {
|
||||
if (message.state.isOutgoing) {
|
||||
return Icon(
|
||||
Icons.access_time,
|
||||
size: size,
|
||||
|
||||
+7
-20
@@ -19,7 +19,6 @@ class MessageActionsModal extends StatefulWidget {
|
||||
this.showDeleteMessage = true,
|
||||
this.showEditMessage = true,
|
||||
this.onReplyTap,
|
||||
this.onConfirmDeleteTap,
|
||||
this.onThreadReplyTap,
|
||||
this.showCopyMessage = true,
|
||||
this.showReplyMessage = true,
|
||||
@@ -45,9 +44,6 @@ class MessageActionsModal extends StatefulWidget {
|
||||
/// The action to perform when "reply" is tapped
|
||||
final OnMessageTap? onReplyTap;
|
||||
|
||||
/// The action to perform when delete confirmation button is tapped.
|
||||
final Future<void> Function(Message)? onConfirmDeleteTap;
|
||||
|
||||
/// Message in focus for actions
|
||||
final Message message;
|
||||
|
||||
@@ -98,9 +94,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
||||
bool _showActions = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => _showMessageOptionsModal();
|
||||
|
||||
Widget _showMessageOptionsModal() {
|
||||
Widget build(BuildContext context) {
|
||||
final mediaQueryData = MediaQuery.of(context);
|
||||
final user = StreamChat.of(context).currentUser;
|
||||
final orientation = mediaQueryData.orientation;
|
||||
@@ -119,8 +113,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
||||
? CrossAxisAlignment.end
|
||||
: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
if (widget.showReactions &&
|
||||
(widget.message.status == MessageSendingStatus.sent))
|
||||
if (widget.showReactions && widget.message.state.isCompleted)
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Align(
|
||||
@@ -161,7 +154,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (widget.showReplyMessage &&
|
||||
widget.message.status == MessageSendingStatus.sent)
|
||||
widget.message.state.isCompleted)
|
||||
ReplyButton(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
@@ -171,8 +164,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
||||
},
|
||||
),
|
||||
if (widget.showThreadReplyMessage &&
|
||||
(widget.message.status ==
|
||||
MessageSendingStatus.sent) &&
|
||||
(widget.message.state.isCompleted) &&
|
||||
widget.message.parentId == null)
|
||||
ThreadReplyButton(
|
||||
message: widget.message,
|
||||
@@ -208,8 +200,8 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
||||
),
|
||||
if (widget.showDeleteMessage)
|
||||
DeleteMessageButton(
|
||||
isDeleteFailed: widget.message.status ==
|
||||
MessageSendingStatus.failed_delete,
|
||||
isDeleteFailed:
|
||||
widget.message.state.isDeletingFailed,
|
||||
onTap: _showDeleteBottomSheet,
|
||||
),
|
||||
...widget.customActions
|
||||
@@ -367,12 +359,7 @@ class _MessageActionsModalState extends State<MessageActionsModal> {
|
||||
if (answer == true) {
|
||||
try {
|
||||
Navigator.of(context).pop();
|
||||
final onConfirmDeleteTap = widget.onConfirmDeleteTap;
|
||||
if (onConfirmDeleteTap != null) {
|
||||
await onConfirmDeleteTap(widget.message);
|
||||
} else {
|
||||
await StreamChannel.of(context).channel.deleteMessage(widget.message);
|
||||
}
|
||||
await StreamChannel.of(context).channel.deleteMessage(widget.message);
|
||||
} catch (err) {
|
||||
_showErrorAlertBottomSheet();
|
||||
}
|
||||
|
||||
+7
-6
@@ -22,16 +22,17 @@ class ResendMessageButton extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isUpdateFailed = message.status == MessageSendingStatus.failed_update;
|
||||
final isUpdateFailed = message.state.isUpdatingFailed;
|
||||
final streamChatThemeData = StreamChatTheme.of(context);
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
if (isUpdateFailed) {
|
||||
channel.updateMessage(message);
|
||||
} else {
|
||||
channel.sendMessage(message);
|
||||
}
|
||||
message.state.whenOrNull(failed: (state, error) {
|
||||
state.whenOrNull(
|
||||
sendingFailed: () => channel.sendMessage(message),
|
||||
updatingFailed: () => channel.updateMessage(message),
|
||||
);
|
||||
});
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 11, horizontal: 16),
|
||||
|
||||
@@ -129,7 +129,6 @@ class StreamMessageInput extends StatefulWidget {
|
||||
this.customAutocompleteTriggers = const [],
|
||||
this.mentionAllAppUsers = false,
|
||||
this.sendButtonBuilder,
|
||||
this.quotedMessageBuilder,
|
||||
this.shouldKeepFocusAfterMessage,
|
||||
this.validator = _defaultValidator,
|
||||
this.restorationId,
|
||||
@@ -267,9 +266,6 @@ class StreamMessageInput extends StatefulWidget {
|
||||
/// Builder for creating send button
|
||||
final MessageRelatedBuilder? sendButtonBuilder;
|
||||
|
||||
/// Builder for building quoted message
|
||||
final Widget Function(BuildContext, Message)? quotedMessageBuilder;
|
||||
|
||||
/// Defines if the [StreamMessageInput] loses focuses after a message is sent.
|
||||
/// The default behaviour keeps focus until a command is enabled.
|
||||
final bool? shouldKeepFocusAfterMessage;
|
||||
@@ -370,8 +366,8 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
||||
bool get _hasQuotedMessage =>
|
||||
_effectiveController.message.quotedMessage != null;
|
||||
|
||||
bool get _isEditing =>
|
||||
_effectiveController.message.status != MessageSendingStatus.sending;
|
||||
// TODO:
|
||||
bool get _isEditing => _effectiveController.message.state.isCompleted;
|
||||
|
||||
BoxBorder? _draggingBorder;
|
||||
|
||||
@@ -786,6 +782,7 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
||||
Future<void> _onAttachmentButtonPressed() async {
|
||||
final attachments = await showStreamAttachmentPickerModalBottomSheet(
|
||||
context: context,
|
||||
useRootNavigator: true,
|
||||
allowedTypes: widget.allowedAttachmentPickerTypes,
|
||||
initialAttachments: _effectiveController.attachments,
|
||||
);
|
||||
@@ -1135,20 +1132,14 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
||||
if (!_hasQuotedMessage) return const Offstage();
|
||||
final containsUrl = _effectiveController.message.quotedMessage!.attachments
|
||||
.any((element) => element.titleLink != null);
|
||||
|
||||
return widget.quotedMessageBuilder?.call(
|
||||
context,
|
||||
_effectiveController.message.quotedMessage!,
|
||||
) ??
|
||||
StreamQuotedMessageWidget(
|
||||
reverse: true,
|
||||
showBorder: !containsUrl,
|
||||
message: _effectiveController.message.quotedMessage!,
|
||||
messageTheme: _streamChatTheme.otherMessageTheme,
|
||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
|
||||
onQuotedMessageClear: widget.onQuotedMessageCleared,
|
||||
attachmentThumbnailBuilders: widget.attachmentThumbnailBuilders,
|
||||
);
|
||||
return StreamQuotedMessageWidget(
|
||||
reverse: true,
|
||||
showBorder: !containsUrl,
|
||||
message: _effectiveController.message.quotedMessage!,
|
||||
messageTheme: _streamChatTheme.otherMessageTheme,
|
||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 0),
|
||||
onQuotedMessageClear: widget.onQuotedMessageCleared,
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAttachments() {
|
||||
@@ -1451,10 +1442,12 @@ class StreamMessageInputState extends State<StreamMessageInput>
|
||||
skipEnrichUrl: skipEnrichUrl,
|
||||
);
|
||||
|
||||
if (shouldKeepFocus) {
|
||||
FocusScope.of(context).requestFocus(_effectiveFocusNode);
|
||||
} else {
|
||||
FocusScope.of(context).unfocus();
|
||||
if (mounted) {
|
||||
if (shouldKeepFocus) {
|
||||
FocusScope.of(context).requestFocus(_effectiveFocusNode);
|
||||
} else {
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ class StreamMessageWidget extends StatefulWidget {
|
||||
this.showInChannelIndicator = false,
|
||||
this.onReplyTap,
|
||||
this.onThreadTap,
|
||||
this.onConfirmDeleteTap,
|
||||
this.showUsername = true,
|
||||
this.showTimestamp = true,
|
||||
this.showReactions = true,
|
||||
@@ -79,7 +78,6 @@ class StreamMessageWidget extends StatefulWidget {
|
||||
this.onMessageActions,
|
||||
this.onShowMessage,
|
||||
this.userAvatarBuilder,
|
||||
this.quotedMessageBuilder,
|
||||
this.editMessageInputBuilder,
|
||||
this.textBuilder,
|
||||
@Deprecated('''
|
||||
@@ -309,11 +307,6 @@ class StreamMessageWidget extends StatefulWidget {
|
||||
/// {@endtemplate}
|
||||
final void Function(Message)? onReplyTap;
|
||||
|
||||
/// {@template onDeleteTap}
|
||||
/// The function called when delete confirmation button is tapped.
|
||||
/// {@endtemplate}
|
||||
final Future<void> Function(Message)? onConfirmDeleteTap;
|
||||
|
||||
/// {@template editMessageInputBuilder}
|
||||
/// Widget builder for edit message layout
|
||||
/// {@endtemplate}
|
||||
@@ -355,11 +348,6 @@ class StreamMessageWidget extends StatefulWidget {
|
||||
/// {@endtemplate}
|
||||
final Widget Function(BuildContext, User)? userAvatarBuilder;
|
||||
|
||||
/// {@template quotedMessageBuilder}
|
||||
/// Widget builder for building quoted message
|
||||
/// {@endtemplate}
|
||||
final Widget Function(BuildContext, Message)? quotedMessageBuilder;
|
||||
|
||||
/// {@template message}
|
||||
/// The message to display.
|
||||
/// {@endtemplate}
|
||||
@@ -580,10 +568,8 @@ class StreamMessageWidget extends StatefulWidget {
|
||||
void Function(User)? onMentionTap,
|
||||
void Function(Message)? onThreadTap,
|
||||
void Function(Message)? onReplyTap,
|
||||
Future<void> Function(Message)? onConfirmDeleteTap,
|
||||
Widget Function(BuildContext, Message)? editMessageInputBuilder,
|
||||
Widget Function(BuildContext, Message)? textBuilder,
|
||||
Widget Function(BuildContext, Message)? quotedMessageBuilder,
|
||||
@Deprecated('''
|
||||
Use [bottomRowBuilderWithDefaultWidget] instead.
|
||||
Will be removed in the next major version.
|
||||
@@ -673,11 +659,9 @@ class StreamMessageWidget extends StatefulWidget {
|
||||
onMentionTap: onMentionTap ?? this.onMentionTap,
|
||||
onThreadTap: onThreadTap ?? this.onThreadTap,
|
||||
onReplyTap: onReplyTap ?? this.onReplyTap,
|
||||
onConfirmDeleteTap: onConfirmDeleteTap ?? this.onConfirmDeleteTap,
|
||||
editMessageInputBuilder:
|
||||
editMessageInputBuilder ?? this.editMessageInputBuilder,
|
||||
textBuilder: textBuilder ?? this.textBuilder,
|
||||
quotedMessageBuilder: quotedMessageBuilder ?? this.quotedMessageBuilder,
|
||||
bottomRowBuilderWithDefaultWidget: _bottomRowBuilderWithDefaultWidget,
|
||||
onMessageActions: onMessageActions ?? this.onMessageActions,
|
||||
message: message ?? this.message,
|
||||
@@ -760,13 +744,11 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
|
||||
/// {@endtemplate}
|
||||
bool get hasQuotedMessage => widget.message.quotedMessage != null;
|
||||
|
||||
bool get isSendFailed => widget.message.status == MessageSendingStatus.failed;
|
||||
bool get isSendFailed => widget.message.state.isSendingFailed;
|
||||
|
||||
bool get isUpdateFailed =>
|
||||
widget.message.status == MessageSendingStatus.failed_update;
|
||||
bool get isUpdateFailed => widget.message.state.isUpdatingFailed;
|
||||
|
||||
bool get isDeleteFailed =>
|
||||
widget.message.status == MessageSendingStatus.failed_delete;
|
||||
bool get isDeleteFailed => widget.message.state.isDeletingFailed;
|
||||
|
||||
/// {@template isFailedState}
|
||||
/// Whether the message has failed to be sent, updated, or deleted.
|
||||
@@ -973,7 +955,6 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
|
||||
borderSide: widget.borderSide,
|
||||
borderRadiusGeometry: widget.borderRadiusGeometry,
|
||||
textBuilder: widget.textBuilder,
|
||||
quotedMessageBuilder: widget.quotedMessageBuilder,
|
||||
onLinkTap: widget.onLinkTap,
|
||||
onMentionTap: widget.onMentionTap,
|
||||
onQuotedMessageTap: widget.onQuotedMessageTap,
|
||||
@@ -1090,14 +1071,12 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
|
||||
leading: StreamSvgIcon.iconSendMessage(),
|
||||
title: Text(
|
||||
context.translations.toggleResendOrResendEditedMessage(
|
||||
isUpdateFailed:
|
||||
widget.message.status == MessageSendingStatus.failed,
|
||||
isUpdateFailed: widget.message.state.isUpdatingFailed,
|
||||
),
|
||||
),
|
||||
onClick: () {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
final isUpdateFailed =
|
||||
widget.message.status == MessageSendingStatus.failed_update;
|
||||
final isUpdateFailed = widget.message.state.isUpdatingFailed;
|
||||
final channel = StreamChannel.of(context).channel;
|
||||
if (isUpdateFailed) {
|
||||
channel.updateMessage(widget.message);
|
||||
@@ -1115,21 +1094,16 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
|
||||
),
|
||||
onClick: () async {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
final deleted = await showDialog<bool?>(
|
||||
final deleted = await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => const DeleteMessageDialog(),
|
||||
);
|
||||
if (deleted == true) {
|
||||
if (deleted) {
|
||||
try {
|
||||
final onConfirmDeleteTap = widget.onConfirmDeleteTap;
|
||||
if (onConfirmDeleteTap != null) {
|
||||
await onConfirmDeleteTap(widget.message);
|
||||
} else {
|
||||
await StreamChannel.of(context)
|
||||
.channel
|
||||
.deleteMessage(widget.message);
|
||||
}
|
||||
await StreamChannel.of(context)
|
||||
.channel
|
||||
.deleteMessage(widget.message);
|
||||
} catch (e) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -1150,8 +1124,7 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
|
||||
}
|
||||
|
||||
void onLongPress(BuildContext context) {
|
||||
if (widget.message.isEphemeral ||
|
||||
widget.message.status == MessageSendingStatus.sending) {
|
||||
if (widget.message.isEphemeral || widget.message.state.isOutgoing) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1187,8 +1160,8 @@ class _StreamMessageWidgetState extends State<StreamMessageWidget>
|
||||
translateUserAvatar: false,
|
||||
showSendingIndicator: false,
|
||||
padding: EdgeInsets.zero,
|
||||
showReactionPickerIndicator: widget.showReactions &&
|
||||
(widget.message.status == MessageSendingStatus.sent),
|
||||
showReactionPickerIndicator:
|
||||
widget.showReactions && widget.message.state.isCompleted,
|
||||
showPinHighlight: false,
|
||||
showUserAvatar:
|
||||
widget.message.user!.id == channel.client.state.currentUser!.id
|
||||
|
||||
@@ -63,7 +63,6 @@ class MessageWidgetContent extends StatelessWidget {
|
||||
this.onMentionTap,
|
||||
this.onLinkTap,
|
||||
this.textBuilder,
|
||||
this.quotedMessageBuilder,
|
||||
@Deprecated('''
|
||||
Use [bottomRowBuilderWithDefaultWidget] instead.
|
||||
Will be removed in the next major version.
|
||||
@@ -171,9 +170,6 @@ class MessageWidgetContent extends StatelessWidget {
|
||||
/// {@macro textBuilder}
|
||||
final Widget Function(BuildContext, Message)? textBuilder;
|
||||
|
||||
/// {@macro quotedMessageBuilder}
|
||||
final Widget Function(BuildContext, Message)? quotedMessageBuilder;
|
||||
|
||||
/// {@macro showReactionPickerIndicator}
|
||||
final bool showReactionPickerIndicator;
|
||||
|
||||
@@ -355,8 +351,6 @@ class MessageWidgetContent extends StatelessWidget {
|
||||
onMentionTap: onMentionTap,
|
||||
onLinkTap: onLinkTap,
|
||||
textBuilder: textBuilder,
|
||||
quotedMessageBuilder:
|
||||
quotedMessageBuilder,
|
||||
borderRadiusGeometry:
|
||||
borderRadiusGeometry,
|
||||
borderSide: borderSide,
|
||||
@@ -458,7 +452,7 @@ class MessageWidgetContent extends StatelessWidget {
|
||||
showSendingIndicator: false,
|
||||
padding: EdgeInsets.zero,
|
||||
showReactionPickerIndicator:
|
||||
showReactions && (message.status == MessageSendingStatus.sent),
|
||||
showReactions && message.state.isCompleted,
|
||||
showPinHighlight: false,
|
||||
showUserAvatar:
|
||||
message.user!.id == channel.client.state.currentUser!.id
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class StreamMessageReactionsModal extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
if ((showReactions ?? hasReactionPermission) &&
|
||||
(message.status == MessageSendingStatus.sent))
|
||||
message.state.isCompleted)
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return Align(
|
||||
|
||||
+12
-16
@@ -42,25 +42,21 @@ class SendingIndicatorBuilder extends StatelessWidget {
|
||||
final channel = this.channel ?? StreamChannel.of(context).channel;
|
||||
final memberCount = channel.memberCount ?? 0;
|
||||
|
||||
if (hasNonUrlAttachments &&
|
||||
(message.status == MessageSendingStatus.sending ||
|
||||
message.status == MessageSendingStatus.updating)) {
|
||||
if (hasNonUrlAttachments && message.state.isOutgoing) {
|
||||
final totalAttachments = message.attachments.length;
|
||||
final uploadRemaining =
|
||||
message.attachments.where((it) => !it.uploadState.isSuccess).length;
|
||||
if (uploadRemaining == 0) {
|
||||
return StreamSvgIcon.check(
|
||||
size: style!.fontSize,
|
||||
color: IconTheme.of(context).color!.withOpacity(0.5),
|
||||
final attachmentsToUpload = message.attachments.where((it) {
|
||||
return !it.uploadState.isSuccess;
|
||||
});
|
||||
|
||||
if (attachmentsToUpload.isNotEmpty) {
|
||||
return Text(
|
||||
context.translations.attachmentsUploadProgressText(
|
||||
remaining: attachmentsToUpload.length,
|
||||
total: totalAttachments,
|
||||
),
|
||||
style: style,
|
||||
);
|
||||
}
|
||||
return Text(
|
||||
context.translations.attachmentsUploadProgressText(
|
||||
remaining: uploadRemaining,
|
||||
total: totalAttachments,
|
||||
),
|
||||
style: style,
|
||||
);
|
||||
}
|
||||
|
||||
return BetterStreamBuilder<List<Read>>(
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ class StreamChannelListTile extends StatelessWidget {
|
||||
/// The widget builder for the sending indicator.
|
||||
///
|
||||
/// `Message` is the last message in the channel, Use it to determine the
|
||||
/// status using [Message.status].
|
||||
/// status using [Message.state].
|
||||
final Widget Function(BuildContext, Message)? sendingIndicatorBuilder;
|
||||
|
||||
/// True if the tile is in a selected state.
|
||||
|
||||
+5
-5
@@ -40,7 +40,7 @@ void main() {
|
||||
user: User(
|
||||
id: 'user-id',
|
||||
),
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
),
|
||||
messageWidget: const Text(
|
||||
'test',
|
||||
@@ -211,7 +211,7 @@ void main() {
|
||||
user: User(
|
||||
id: 'user-id',
|
||||
),
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
),
|
||||
messageTheme: streamTheme.ownMessageTheme,
|
||||
),
|
||||
@@ -262,7 +262,7 @@ void main() {
|
||||
user: User(
|
||||
id: 'user-id',
|
||||
),
|
||||
status: MessageSendingStatus.sent,
|
||||
state: MessageState.sent,
|
||||
),
|
||||
messageTheme: streamTheme.ownMessageTheme,
|
||||
),
|
||||
@@ -460,7 +460,7 @@ void main() {
|
||||
child: MessageActionsModal(
|
||||
messageWidget: const Text('test'),
|
||||
message: Message(
|
||||
status: MessageSendingStatus.failed,
|
||||
state: MessageState.sendingFailed,
|
||||
text: 'test',
|
||||
user: User(
|
||||
id: 'user-id',
|
||||
@@ -510,7 +510,7 @@ void main() {
|
||||
child: MessageActionsModal(
|
||||
messageWidget: const Text('test'),
|
||||
message: Message(
|
||||
status: MessageSendingStatus.failed_update,
|
||||
state: MessageState.updatingFailed,
|
||||
text: 'test',
|
||||
user: User(
|
||||
id: 'user-id',
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
export 'list_converter.dart';
|
||||
export 'map_converter.dart';
|
||||
export 'message_sending_status_converter.dart';
|
||||
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
/// Maps a [MessageSendingStatus] into a [int] understood
|
||||
/// by the sqlite backend.
|
||||
class MessageSendingStatusConverter
|
||||
extends TypeConverter<MessageSendingStatus, int> {
|
||||
@override
|
||||
MessageSendingStatus fromSql(int fromDb) {
|
||||
switch (fromDb) {
|
||||
case 0:
|
||||
return MessageSendingStatus.sending;
|
||||
case 1:
|
||||
return MessageSendingStatus.sent;
|
||||
case 2:
|
||||
return MessageSendingStatus.failed;
|
||||
case 3:
|
||||
return MessageSendingStatus.updating;
|
||||
case 4:
|
||||
return MessageSendingStatus.failed_update;
|
||||
case 5:
|
||||
return MessageSendingStatus.deleting;
|
||||
case 6:
|
||||
return MessageSendingStatus.failed_delete;
|
||||
}
|
||||
return MessageSendingStatus.sending;
|
||||
}
|
||||
|
||||
@override
|
||||
int toSql(MessageSendingStatus value) {
|
||||
switch (value) {
|
||||
case MessageSendingStatus.sending:
|
||||
return 0;
|
||||
case MessageSendingStatus.sent:
|
||||
return 1;
|
||||
case MessageSendingStatus.failed:
|
||||
return 2;
|
||||
case MessageSendingStatus.updating:
|
||||
return 3;
|
||||
case MessageSendingStatus.failed_update:
|
||||
return 4;
|
||||
case MessageSendingStatus.deleting:
|
||||
return 5;
|
||||
case MessageSendingStatus.failed_delete:
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -667,14 +667,11 @@ class $MessagesTable extends Messages
|
||||
attachments = GeneratedColumn<String>('attachments', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true)
|
||||
.withConverter<List<String>>($MessagesTable.$converterattachments);
|
||||
static const VerificationMeta _statusMeta = const VerificationMeta('status');
|
||||
static const VerificationMeta _stateMeta = const VerificationMeta('state');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<MessageSendingStatus, int>
|
||||
status = GeneratedColumn<int>('status', aliasedName, false,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
defaultValue: const Constant(1))
|
||||
.withConverter<MessageSendingStatus>($MessagesTable.$converterstatus);
|
||||
late final GeneratedColumn<String> state = GeneratedColumn<String>(
|
||||
'state', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||
static const VerificationMeta _typeMeta = const VerificationMeta('type');
|
||||
@override
|
||||
late final GeneratedColumn<String> type = GeneratedColumn<String>(
|
||||
@@ -856,7 +853,7 @@ class $MessagesTable extends Messages
|
||||
id,
|
||||
messageText,
|
||||
attachments,
|
||||
status,
|
||||
state,
|
||||
type,
|
||||
mentionedUsers,
|
||||
reactionCounts,
|
||||
@@ -903,7 +900,12 @@ class $MessagesTable extends Messages
|
||||
data['message_text']!, _messageTextMeta));
|
||||
}
|
||||
context.handle(_attachmentsMeta, const VerificationResult.success());
|
||||
context.handle(_statusMeta, const VerificationResult.success());
|
||||
if (data.containsKey('state')) {
|
||||
context.handle(
|
||||
_stateMeta, state.isAcceptableOrUnknown(data['state']!, _stateMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_stateMeta);
|
||||
}
|
||||
if (data.containsKey('type')) {
|
||||
context.handle(
|
||||
_typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta));
|
||||
@@ -1027,9 +1029,8 @@ class $MessagesTable extends Messages
|
||||
attachments: $MessagesTable.$converterattachments.fromSql(attachedDatabase
|
||||
.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}attachments'])!),
|
||||
status: $MessagesTable.$converterstatus.fromSql(attachedDatabase
|
||||
.typeMapping
|
||||
.read(DriftSqlType.int, data['${effectivePrefix}status'])!),
|
||||
state: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}state'])!,
|
||||
type: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}type'])!,
|
||||
mentionedUsers: $MessagesTable.$convertermentionedUsers.fromSql(
|
||||
@@ -1092,8 +1093,6 @@ class $MessagesTable extends Messages
|
||||
|
||||
static TypeConverter<List<String>, String> $converterattachments =
|
||||
ListConverter();
|
||||
static TypeConverter<MessageSendingStatus, int> $converterstatus =
|
||||
MessageSendingStatusConverter();
|
||||
static TypeConverter<List<String>, String> $convertermentionedUsers =
|
||||
ListConverter();
|
||||
static TypeConverter<Map<String, int>, String> $converterreactionCounts =
|
||||
@@ -1123,8 +1122,8 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
/// or generated from a command or as a result of URL scraping.
|
||||
final List<String> attachments;
|
||||
|
||||
/// The status of a sending message
|
||||
final MessageSendingStatus status;
|
||||
/// The current state of the message.
|
||||
final String state;
|
||||
|
||||
/// The message type
|
||||
final String type;
|
||||
@@ -1201,7 +1200,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
{required this.id,
|
||||
this.messageText,
|
||||
required this.attachments,
|
||||
required this.status,
|
||||
required this.state,
|
||||
required this.type,
|
||||
required this.mentionedUsers,
|
||||
this.reactionCounts,
|
||||
@@ -1237,10 +1236,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
final converter = $MessagesTable.$converterattachments;
|
||||
map['attachments'] = Variable<String>(converter.toSql(attachments));
|
||||
}
|
||||
{
|
||||
final converter = $MessagesTable.$converterstatus;
|
||||
map['status'] = Variable<int>(converter.toSql(status));
|
||||
}
|
||||
map['state'] = Variable<String>(state);
|
||||
map['type'] = Variable<String>(type);
|
||||
{
|
||||
final converter = $MessagesTable.$convertermentionedUsers;
|
||||
@@ -1323,7 +1319,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
id: serializer.fromJson<String>(json['id']),
|
||||
messageText: serializer.fromJson<String?>(json['messageText']),
|
||||
attachments: serializer.fromJson<List<String>>(json['attachments']),
|
||||
status: serializer.fromJson<MessageSendingStatus>(json['status']),
|
||||
state: serializer.fromJson<String>(json['state']),
|
||||
type: serializer.fromJson<String>(json['type']),
|
||||
mentionedUsers: serializer.fromJson<List<String>>(json['mentionedUsers']),
|
||||
reactionCounts:
|
||||
@@ -1359,7 +1355,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
'id': serializer.toJson<String>(id),
|
||||
'messageText': serializer.toJson<String?>(messageText),
|
||||
'attachments': serializer.toJson<List<String>>(attachments),
|
||||
'status': serializer.toJson<MessageSendingStatus>(status),
|
||||
'state': serializer.toJson<String>(state),
|
||||
'type': serializer.toJson<String>(type),
|
||||
'mentionedUsers': serializer.toJson<List<String>>(mentionedUsers),
|
||||
'reactionCounts': serializer.toJson<Map<String, int>?>(reactionCounts),
|
||||
@@ -1391,7 +1387,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
{String? id,
|
||||
Value<String?> messageText = const Value.absent(),
|
||||
List<String>? attachments,
|
||||
MessageSendingStatus? status,
|
||||
String? state,
|
||||
String? type,
|
||||
List<String>? mentionedUsers,
|
||||
Value<Map<String, int>?> reactionCounts = const Value.absent(),
|
||||
@@ -1420,7 +1416,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
id: id ?? this.id,
|
||||
messageText: messageText.present ? messageText.value : this.messageText,
|
||||
attachments: attachments ?? this.attachments,
|
||||
status: status ?? this.status,
|
||||
state: state ?? this.state,
|
||||
type: type ?? this.type,
|
||||
mentionedUsers: mentionedUsers ?? this.mentionedUsers,
|
||||
reactionCounts:
|
||||
@@ -1467,7 +1463,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
..write('id: $id, ')
|
||||
..write('messageText: $messageText, ')
|
||||
..write('attachments: $attachments, ')
|
||||
..write('status: $status, ')
|
||||
..write('state: $state, ')
|
||||
..write('type: $type, ')
|
||||
..write('mentionedUsers: $mentionedUsers, ')
|
||||
..write('reactionCounts: $reactionCounts, ')
|
||||
@@ -1501,7 +1497,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
id,
|
||||
messageText,
|
||||
attachments,
|
||||
status,
|
||||
state,
|
||||
type,
|
||||
mentionedUsers,
|
||||
reactionCounts,
|
||||
@@ -1534,7 +1530,7 @@ class MessageEntity extends DataClass implements Insertable<MessageEntity> {
|
||||
other.id == this.id &&
|
||||
other.messageText == this.messageText &&
|
||||
other.attachments == this.attachments &&
|
||||
other.status == this.status &&
|
||||
other.state == this.state &&
|
||||
other.type == this.type &&
|
||||
other.mentionedUsers == this.mentionedUsers &&
|
||||
other.reactionCounts == this.reactionCounts &&
|
||||
@@ -1565,7 +1561,7 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
final Value<String> id;
|
||||
final Value<String?> messageText;
|
||||
final Value<List<String>> attachments;
|
||||
final Value<MessageSendingStatus> status;
|
||||
final Value<String> state;
|
||||
final Value<String> type;
|
||||
final Value<List<String>> mentionedUsers;
|
||||
final Value<Map<String, int>?> reactionCounts;
|
||||
@@ -1595,7 +1591,7 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
this.id = const Value.absent(),
|
||||
this.messageText = const Value.absent(),
|
||||
this.attachments = const Value.absent(),
|
||||
this.status = const Value.absent(),
|
||||
this.state = const Value.absent(),
|
||||
this.type = const Value.absent(),
|
||||
this.mentionedUsers = const Value.absent(),
|
||||
this.reactionCounts = const Value.absent(),
|
||||
@@ -1626,7 +1622,7 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
required String id,
|
||||
this.messageText = const Value.absent(),
|
||||
required List<String> attachments,
|
||||
this.status = const Value.absent(),
|
||||
required String state,
|
||||
this.type = const Value.absent(),
|
||||
required List<String> mentionedUsers,
|
||||
this.reactionCounts = const Value.absent(),
|
||||
@@ -1654,13 +1650,14 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
this.rowid = const Value.absent(),
|
||||
}) : id = Value(id),
|
||||
attachments = Value(attachments),
|
||||
state = Value(state),
|
||||
mentionedUsers = Value(mentionedUsers),
|
||||
channelCid = Value(channelCid);
|
||||
static Insertable<MessageEntity> custom({
|
||||
Expression<String>? id,
|
||||
Expression<String>? messageText,
|
||||
Expression<String>? attachments,
|
||||
Expression<int>? status,
|
||||
Expression<String>? state,
|
||||
Expression<String>? type,
|
||||
Expression<String>? mentionedUsers,
|
||||
Expression<String>? reactionCounts,
|
||||
@@ -1691,7 +1688,7 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
if (id != null) 'id': id,
|
||||
if (messageText != null) 'message_text': messageText,
|
||||
if (attachments != null) 'attachments': attachments,
|
||||
if (status != null) 'status': status,
|
||||
if (state != null) 'state': state,
|
||||
if (type != null) 'type': type,
|
||||
if (mentionedUsers != null) 'mentioned_users': mentionedUsers,
|
||||
if (reactionCounts != null) 'reaction_counts': reactionCounts,
|
||||
@@ -1724,7 +1721,7 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
{Value<String>? id,
|
||||
Value<String?>? messageText,
|
||||
Value<List<String>>? attachments,
|
||||
Value<MessageSendingStatus>? status,
|
||||
Value<String>? state,
|
||||
Value<String>? type,
|
||||
Value<List<String>>? mentionedUsers,
|
||||
Value<Map<String, int>?>? reactionCounts,
|
||||
@@ -1754,7 +1751,7 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
id: id ?? this.id,
|
||||
messageText: messageText ?? this.messageText,
|
||||
attachments: attachments ?? this.attachments,
|
||||
status: status ?? this.status,
|
||||
state: state ?? this.state,
|
||||
type: type ?? this.type,
|
||||
mentionedUsers: mentionedUsers ?? this.mentionedUsers,
|
||||
reactionCounts: reactionCounts ?? this.reactionCounts,
|
||||
@@ -1796,9 +1793,8 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
final converter = $MessagesTable.$converterattachments;
|
||||
map['attachments'] = Variable<String>(converter.toSql(attachments.value));
|
||||
}
|
||||
if (status.present) {
|
||||
final converter = $MessagesTable.$converterstatus;
|
||||
map['status'] = Variable<int>(converter.toSql(status.value));
|
||||
if (state.present) {
|
||||
map['state'] = Variable<String>(state.value);
|
||||
}
|
||||
if (type.present) {
|
||||
map['type'] = Variable<String>(type.value);
|
||||
@@ -1892,7 +1888,7 @@ class MessagesCompanion extends UpdateCompanion<MessageEntity> {
|
||||
..write('id: $id, ')
|
||||
..write('messageText: $messageText, ')
|
||||
..write('attachments: $attachments, ')
|
||||
..write('status: $status, ')
|
||||
..write('state: $state, ')
|
||||
..write('type: $type, ')
|
||||
..write('mentionedUsers: $mentionedUsers, ')
|
||||
..write('reactionCounts: $reactionCounts, ')
|
||||
@@ -1948,15 +1944,11 @@ class $PinnedMessagesTable extends PinnedMessages
|
||||
type: DriftSqlType.string, requiredDuringInsert: true)
|
||||
.withConverter<List<String>>(
|
||||
$PinnedMessagesTable.$converterattachments);
|
||||
static const VerificationMeta _statusMeta = const VerificationMeta('status');
|
||||
static const VerificationMeta _stateMeta = const VerificationMeta('state');
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<MessageSendingStatus, int>
|
||||
status = GeneratedColumn<int>('status', aliasedName, false,
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
defaultValue: const Constant(1))
|
||||
.withConverter<MessageSendingStatus>(
|
||||
$PinnedMessagesTable.$converterstatus);
|
||||
late final GeneratedColumn<String> state = GeneratedColumn<String>(
|
||||
'state', aliasedName, false,
|
||||
type: DriftSqlType.string, requiredDuringInsert: true);
|
||||
static const VerificationMeta _typeMeta = const VerificationMeta('type');
|
||||
@override
|
||||
late final GeneratedColumn<String> type = GeneratedColumn<String>(
|
||||
@@ -2140,7 +2132,7 @@ class $PinnedMessagesTable extends PinnedMessages
|
||||
id,
|
||||
messageText,
|
||||
attachments,
|
||||
status,
|
||||
state,
|
||||
type,
|
||||
mentionedUsers,
|
||||
reactionCounts,
|
||||
@@ -2188,7 +2180,12 @@ class $PinnedMessagesTable extends PinnedMessages
|
||||
data['message_text']!, _messageTextMeta));
|
||||
}
|
||||
context.handle(_attachmentsMeta, const VerificationResult.success());
|
||||
context.handle(_statusMeta, const VerificationResult.success());
|
||||
if (data.containsKey('state')) {
|
||||
context.handle(
|
||||
_stateMeta, state.isAcceptableOrUnknown(data['state']!, _stateMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_stateMeta);
|
||||
}
|
||||
if (data.containsKey('type')) {
|
||||
context.handle(
|
||||
_typeMeta, type.isAcceptableOrUnknown(data['type']!, _typeMeta));
|
||||
@@ -2312,9 +2309,8 @@ class $PinnedMessagesTable extends PinnedMessages
|
||||
attachments: $PinnedMessagesTable.$converterattachments.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string, data['${effectivePrefix}attachments'])!),
|
||||
status: $PinnedMessagesTable.$converterstatus.fromSql(attachedDatabase
|
||||
.typeMapping
|
||||
.read(DriftSqlType.int, data['${effectivePrefix}status'])!),
|
||||
state: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}state'])!,
|
||||
type: attachedDatabase.typeMapping
|
||||
.read(DriftSqlType.string, data['${effectivePrefix}type'])!,
|
||||
mentionedUsers: $PinnedMessagesTable.$convertermentionedUsers.fromSql(
|
||||
@@ -2378,8 +2374,6 @@ class $PinnedMessagesTable extends PinnedMessages
|
||||
|
||||
static TypeConverter<List<String>, String> $converterattachments =
|
||||
ListConverter();
|
||||
static TypeConverter<MessageSendingStatus, int> $converterstatus =
|
||||
MessageSendingStatusConverter();
|
||||
static TypeConverter<List<String>, String> $convertermentionedUsers =
|
||||
ListConverter();
|
||||
static TypeConverter<Map<String, int>, String> $converterreactionCounts =
|
||||
@@ -2410,8 +2404,8 @@ class PinnedMessageEntity extends DataClass
|
||||
/// or generated from a command or as a result of URL scraping.
|
||||
final List<String> attachments;
|
||||
|
||||
/// The status of a sending message
|
||||
final MessageSendingStatus status;
|
||||
/// The current state of the message.
|
||||
final String state;
|
||||
|
||||
/// The message type
|
||||
final String type;
|
||||
@@ -2488,7 +2482,7 @@ class PinnedMessageEntity extends DataClass
|
||||
{required this.id,
|
||||
this.messageText,
|
||||
required this.attachments,
|
||||
required this.status,
|
||||
required this.state,
|
||||
required this.type,
|
||||
required this.mentionedUsers,
|
||||
this.reactionCounts,
|
||||
@@ -2524,10 +2518,7 @@ class PinnedMessageEntity extends DataClass
|
||||
final converter = $PinnedMessagesTable.$converterattachments;
|
||||
map['attachments'] = Variable<String>(converter.toSql(attachments));
|
||||
}
|
||||
{
|
||||
final converter = $PinnedMessagesTable.$converterstatus;
|
||||
map['status'] = Variable<int>(converter.toSql(status));
|
||||
}
|
||||
map['state'] = Variable<String>(state);
|
||||
map['type'] = Variable<String>(type);
|
||||
{
|
||||
final converter = $PinnedMessagesTable.$convertermentionedUsers;
|
||||
@@ -2610,7 +2601,7 @@ class PinnedMessageEntity extends DataClass
|
||||
id: serializer.fromJson<String>(json['id']),
|
||||
messageText: serializer.fromJson<String?>(json['messageText']),
|
||||
attachments: serializer.fromJson<List<String>>(json['attachments']),
|
||||
status: serializer.fromJson<MessageSendingStatus>(json['status']),
|
||||
state: serializer.fromJson<String>(json['state']),
|
||||
type: serializer.fromJson<String>(json['type']),
|
||||
mentionedUsers: serializer.fromJson<List<String>>(json['mentionedUsers']),
|
||||
reactionCounts:
|
||||
@@ -2646,7 +2637,7 @@ class PinnedMessageEntity extends DataClass
|
||||
'id': serializer.toJson<String>(id),
|
||||
'messageText': serializer.toJson<String?>(messageText),
|
||||
'attachments': serializer.toJson<List<String>>(attachments),
|
||||
'status': serializer.toJson<MessageSendingStatus>(status),
|
||||
'state': serializer.toJson<String>(state),
|
||||
'type': serializer.toJson<String>(type),
|
||||
'mentionedUsers': serializer.toJson<List<String>>(mentionedUsers),
|
||||
'reactionCounts': serializer.toJson<Map<String, int>?>(reactionCounts),
|
||||
@@ -2678,7 +2669,7 @@ class PinnedMessageEntity extends DataClass
|
||||
{String? id,
|
||||
Value<String?> messageText = const Value.absent(),
|
||||
List<String>? attachments,
|
||||
MessageSendingStatus? status,
|
||||
String? state,
|
||||
String? type,
|
||||
List<String>? mentionedUsers,
|
||||
Value<Map<String, int>?> reactionCounts = const Value.absent(),
|
||||
@@ -2707,7 +2698,7 @@ class PinnedMessageEntity extends DataClass
|
||||
id: id ?? this.id,
|
||||
messageText: messageText.present ? messageText.value : this.messageText,
|
||||
attachments: attachments ?? this.attachments,
|
||||
status: status ?? this.status,
|
||||
state: state ?? this.state,
|
||||
type: type ?? this.type,
|
||||
mentionedUsers: mentionedUsers ?? this.mentionedUsers,
|
||||
reactionCounts:
|
||||
@@ -2754,7 +2745,7 @@ class PinnedMessageEntity extends DataClass
|
||||
..write('id: $id, ')
|
||||
..write('messageText: $messageText, ')
|
||||
..write('attachments: $attachments, ')
|
||||
..write('status: $status, ')
|
||||
..write('state: $state, ')
|
||||
..write('type: $type, ')
|
||||
..write('mentionedUsers: $mentionedUsers, ')
|
||||
..write('reactionCounts: $reactionCounts, ')
|
||||
@@ -2788,7 +2779,7 @@ class PinnedMessageEntity extends DataClass
|
||||
id,
|
||||
messageText,
|
||||
attachments,
|
||||
status,
|
||||
state,
|
||||
type,
|
||||
mentionedUsers,
|
||||
reactionCounts,
|
||||
@@ -2821,7 +2812,7 @@ class PinnedMessageEntity extends DataClass
|
||||
other.id == this.id &&
|
||||
other.messageText == this.messageText &&
|
||||
other.attachments == this.attachments &&
|
||||
other.status == this.status &&
|
||||
other.state == this.state &&
|
||||
other.type == this.type &&
|
||||
other.mentionedUsers == this.mentionedUsers &&
|
||||
other.reactionCounts == this.reactionCounts &&
|
||||
@@ -2852,7 +2843,7 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
final Value<String> id;
|
||||
final Value<String?> messageText;
|
||||
final Value<List<String>> attachments;
|
||||
final Value<MessageSendingStatus> status;
|
||||
final Value<String> state;
|
||||
final Value<String> type;
|
||||
final Value<List<String>> mentionedUsers;
|
||||
final Value<Map<String, int>?> reactionCounts;
|
||||
@@ -2882,7 +2873,7 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
this.id = const Value.absent(),
|
||||
this.messageText = const Value.absent(),
|
||||
this.attachments = const Value.absent(),
|
||||
this.status = const Value.absent(),
|
||||
this.state = const Value.absent(),
|
||||
this.type = const Value.absent(),
|
||||
this.mentionedUsers = const Value.absent(),
|
||||
this.reactionCounts = const Value.absent(),
|
||||
@@ -2913,7 +2904,7 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
required String id,
|
||||
this.messageText = const Value.absent(),
|
||||
required List<String> attachments,
|
||||
this.status = const Value.absent(),
|
||||
required String state,
|
||||
this.type = const Value.absent(),
|
||||
required List<String> mentionedUsers,
|
||||
this.reactionCounts = const Value.absent(),
|
||||
@@ -2941,13 +2932,14 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
this.rowid = const Value.absent(),
|
||||
}) : id = Value(id),
|
||||
attachments = Value(attachments),
|
||||
state = Value(state),
|
||||
mentionedUsers = Value(mentionedUsers),
|
||||
channelCid = Value(channelCid);
|
||||
static Insertable<PinnedMessageEntity> custom({
|
||||
Expression<String>? id,
|
||||
Expression<String>? messageText,
|
||||
Expression<String>? attachments,
|
||||
Expression<int>? status,
|
||||
Expression<String>? state,
|
||||
Expression<String>? type,
|
||||
Expression<String>? mentionedUsers,
|
||||
Expression<String>? reactionCounts,
|
||||
@@ -2978,7 +2970,7 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
if (id != null) 'id': id,
|
||||
if (messageText != null) 'message_text': messageText,
|
||||
if (attachments != null) 'attachments': attachments,
|
||||
if (status != null) 'status': status,
|
||||
if (state != null) 'state': state,
|
||||
if (type != null) 'type': type,
|
||||
if (mentionedUsers != null) 'mentioned_users': mentionedUsers,
|
||||
if (reactionCounts != null) 'reaction_counts': reactionCounts,
|
||||
@@ -3011,7 +3003,7 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
{Value<String>? id,
|
||||
Value<String?>? messageText,
|
||||
Value<List<String>>? attachments,
|
||||
Value<MessageSendingStatus>? status,
|
||||
Value<String>? state,
|
||||
Value<String>? type,
|
||||
Value<List<String>>? mentionedUsers,
|
||||
Value<Map<String, int>?>? reactionCounts,
|
||||
@@ -3041,7 +3033,7 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
id: id ?? this.id,
|
||||
messageText: messageText ?? this.messageText,
|
||||
attachments: attachments ?? this.attachments,
|
||||
status: status ?? this.status,
|
||||
state: state ?? this.state,
|
||||
type: type ?? this.type,
|
||||
mentionedUsers: mentionedUsers ?? this.mentionedUsers,
|
||||
reactionCounts: reactionCounts ?? this.reactionCounts,
|
||||
@@ -3083,9 +3075,8 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
final converter = $PinnedMessagesTable.$converterattachments;
|
||||
map['attachments'] = Variable<String>(converter.toSql(attachments.value));
|
||||
}
|
||||
if (status.present) {
|
||||
final converter = $PinnedMessagesTable.$converterstatus;
|
||||
map['status'] = Variable<int>(converter.toSql(status.value));
|
||||
if (state.present) {
|
||||
map['state'] = Variable<String>(state.value);
|
||||
}
|
||||
if (type.present) {
|
||||
map['type'] = Variable<String>(type.value);
|
||||
@@ -3179,7 +3170,7 @@ class PinnedMessagesCompanion extends UpdateCompanion<PinnedMessageEntity> {
|
||||
..write('id: $id, ')
|
||||
..write('messageText: $messageText, ')
|
||||
..write('attachments: $attachments, ')
|
||||
..write('status: $status, ')
|
||||
..write('state: $state, ')
|
||||
..write('type: $type, ')
|
||||
..write('mentionedUsers: $mentionedUsers, ')
|
||||
..write('reactionCounts: $reactionCounts, ')
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:stream_chat_persistence/src/converter/list_converter.dart';
|
||||
import 'package:stream_chat_persistence/src/converter/map_converter.dart';
|
||||
import 'package:stream_chat_persistence/src/converter/message_sending_status_converter.dart';
|
||||
import 'package:stream_chat_persistence/src/entity/channels.dart';
|
||||
|
||||
/// Represents a [Messages] table in [MoorChatDatabase].
|
||||
@@ -18,10 +17,8 @@ class Messages extends Table {
|
||||
/// or generated from a command or as a result of URL scraping.
|
||||
TextColumn get attachments => text().map(ListConverter<String>())();
|
||||
|
||||
/// The status of a sending message
|
||||
IntColumn get status => integer()
|
||||
.withDefault(const Constant(1))
|
||||
.map(MessageSendingStatusConverter())();
|
||||
/// The current state of the message.
|
||||
TextColumn get state => text()();
|
||||
|
||||
/// The message type
|
||||
TextColumn get type => text().withDefault(const Constant('regular'))();
|
||||
|
||||
@@ -30,7 +30,7 @@ extension MessageEntityX on MessageEntity {
|
||||
localDeletedAt: localDeletedAt,
|
||||
id: id,
|
||||
type: type,
|
||||
status: status,
|
||||
state: MessageState.fromJson(jsonDecode(state)),
|
||||
command: command,
|
||||
parentId: parentId,
|
||||
quotedMessageId: quotedMessageId,
|
||||
@@ -70,7 +70,7 @@ extension MessageX on Message {
|
||||
reactionScores: reactionScores,
|
||||
reactionCounts: reactionCounts,
|
||||
mentionedUsers: mentionedUsers.map(jsonEncode).toList(),
|
||||
status: status,
|
||||
state: jsonEncode(state),
|
||||
remoteUpdatedAt: remoteUpdatedAt,
|
||||
localUpdatedAt: localUpdatedAt,
|
||||
extraData: extraData,
|
||||
|
||||
@@ -30,7 +30,7 @@ extension PinnedMessageEntityX on PinnedMessageEntity {
|
||||
localDeletedAt: localDeletedAt,
|
||||
id: id,
|
||||
type: type,
|
||||
status: status,
|
||||
state: MessageState.fromJson(jsonDecode(state)),
|
||||
command: command,
|
||||
parentId: parentId,
|
||||
quotedMessageId: quotedMessageId,
|
||||
@@ -71,7 +71,7 @@ extension PMessageX on Message {
|
||||
reactionScores: reactionScores,
|
||||
reactionCounts: reactionCounts,
|
||||
mentionedUsers: mentionedUsers.map(jsonEncode).toList(),
|
||||
status: status,
|
||||
state: jsonEncode(state),
|
||||
remoteUpdatedAt: remoteUpdatedAt,
|
||||
localUpdatedAt: localUpdatedAt,
|
||||
extraData: extraData,
|
||||
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
import 'package:stream_chat_persistence/src/converter/message_sending_status_converter.dart';
|
||||
|
||||
void main() {
|
||||
group('fromSql', () {
|
||||
final statusConverter = MessageSendingStatusConverter();
|
||||
|
||||
test('should return expected status if status code is provided', () {
|
||||
final res = statusConverter.fromSql(6);
|
||||
expect(res, MessageSendingStatus.failed_delete);
|
||||
});
|
||||
});
|
||||
|
||||
group('toSql', () {
|
||||
final statusConverter = MessageSendingStatusConverter();
|
||||
|
||||
test('should return expected code if the status is provided', () {
|
||||
final res = statusConverter.toSql(MessageSendingStatus.failed_delete);
|
||||
expect(res, 6);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -52,7 +52,7 @@ void main() {
|
||||
mentionedUsers: [
|
||||
jsonEncode(User(id: 'testuser')),
|
||||
],
|
||||
status: MessageSendingStatus.sent,
|
||||
state: jsonEncode(MessageState.sent),
|
||||
localUpdatedAt: DateTime.now(),
|
||||
remoteUpdatedAt: DateTime.now().add(const Duration(seconds: 1)),
|
||||
extraData: {'extra_test_data': 'extraData'},
|
||||
@@ -96,7 +96,7 @@ void main() {
|
||||
expect(message.replyCount, entity.replyCount);
|
||||
expect(message.reactionScores, entity.reactionScores);
|
||||
expect(message.reactionCounts, entity.reactionCounts);
|
||||
expect(message.status, entity.status);
|
||||
expect(message.state, MessageState.fromJson(jsonDecode(entity.state)));
|
||||
expect(message.localUpdatedAt, isSameDateAs(entity.localUpdatedAt));
|
||||
expect(message.remoteUpdatedAt, isSameDateAs(entity.remoteUpdatedAt));
|
||||
expect(message.extraData, entity.extraData);
|
||||
@@ -197,7 +197,7 @@ void main() {
|
||||
entity.mentionedUsers, message.mentionedUsers.map(jsonEncode).toList());
|
||||
expect(entity.reactionScores, message.reactionScores);
|
||||
expect(entity.reactionCounts, message.reactionCounts);
|
||||
expect(entity.status, message.status);
|
||||
expect(entity.state, jsonEncode(message.state));
|
||||
expect(entity.localUpdatedAt, isSameDateAs(message.localUpdatedAt));
|
||||
expect(entity.remoteUpdatedAt, isSameDateAs(message.remoteUpdatedAt));
|
||||
expect(entity.extraData, message.extraData);
|
||||
|
||||
@@ -52,7 +52,7 @@ void main() {
|
||||
mentionedUsers: [
|
||||
jsonEncode(User(id: 'testuser')),
|
||||
],
|
||||
status: MessageSendingStatus.sent,
|
||||
state: jsonEncode(MessageState.sent),
|
||||
localUpdatedAt: DateTime.now(),
|
||||
remoteUpdatedAt: DateTime.now().add(const Duration(seconds: 1)),
|
||||
extraData: {'extra_test_data': 'extraData'},
|
||||
@@ -96,7 +96,7 @@ void main() {
|
||||
expect(message.replyCount, entity.replyCount);
|
||||
expect(message.reactionScores, entity.reactionScores);
|
||||
expect(message.reactionCounts, entity.reactionCounts);
|
||||
expect(message.status, entity.status);
|
||||
expect(message.state, MessageState.fromJson(jsonDecode(entity.state)));
|
||||
expect(message.localUpdatedAt, isSameDateAs(entity.localUpdatedAt));
|
||||
expect(message.remoteUpdatedAt, isSameDateAs(entity.remoteUpdatedAt));
|
||||
expect(message.extraData, entity.extraData);
|
||||
@@ -197,7 +197,7 @@ void main() {
|
||||
entity.mentionedUsers, message.mentionedUsers.map(jsonEncode).toList());
|
||||
expect(entity.reactionScores, message.reactionScores);
|
||||
expect(entity.reactionCounts, message.reactionCounts);
|
||||
expect(entity.status, message.status);
|
||||
expect(entity.state, jsonEncode(message.state));
|
||||
expect(entity.localUpdatedAt, isSameDateAs(message.localUpdatedAt));
|
||||
expect(entity.remoteUpdatedAt, isSameDateAs(message.remoteUpdatedAt));
|
||||
expect(entity.extraData, message.extraData);
|
||||
|
||||
Reference in New Issue
Block a user