chore: migrate and update tests.

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