Skip to content

Commit 7db0adb

Browse files
committed
Fix partial message constructors
1 parent 0a21999 commit 7db0adb

File tree

6 files changed

+114
-69
lines changed

6 files changed

+114
-69
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.4.2
2+
3+
- Fix partial message constructors
4+
15
## 3.4.1
26

37
- Downgrade meta to support flutter test

lib/src/messages/custom_message.dart

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,31 @@ abstract class CustomMessage extends Message {
4242
}) = _CustomMessage;
4343

4444
/// Creates a full custom message from a partial one.
45-
CustomMessage.fromPartial({
46-
required super.author,
47-
super.createdAt,
48-
required super.id,
45+
factory CustomMessage.fromPartial({
46+
required User author,
47+
int? createdAt,
48+
required String id,
4949
required PartialCustom partialCustom,
50-
super.remoteId,
51-
super.roomId,
52-
super.showStatus,
53-
super.status,
54-
super.updatedAt,
55-
}) : super(
56-
metadata: partialCustom.metadata,
57-
repliedMessage: partialCustom.repliedMessage,
58-
type: MessageType.custom,
59-
);
50+
String? remoteId,
51+
String? roomId,
52+
bool? showStatus,
53+
Status? status,
54+
int? updatedAt,
55+
}) {
56+
return _CustomMessage(
57+
author: author,
58+
createdAt: createdAt,
59+
id: id,
60+
metadata: partialCustom.metadata,
61+
remoteId: remoteId,
62+
repliedMessage: partialCustom.repliedMessage,
63+
roomId: roomId,
64+
showStatus: showStatus,
65+
status: status,
66+
type: MessageType.custom,
67+
updatedAt: updatedAt,
68+
);
69+
}
6070

6171
/// Creates a custom message from a map (decoded JSON).
6272
factory CustomMessage.fromJson(Map<String, dynamic> json) =>

lib/src/messages/file_message.dart

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,37 @@ abstract class FileMessage extends Message {
5151
}) = _FileMessage;
5252

5353
/// Creates a full file message from a partial one.
54-
FileMessage.fromPartial({
55-
required super.author,
56-
super.createdAt,
57-
required super.id,
58-
this.isLoading,
54+
factory FileMessage.fromPartial({
55+
required User author,
56+
int? createdAt,
57+
required String id,
58+
bool? isLoading,
5959
required PartialFile partialFile,
60-
super.remoteId,
61-
super.roomId,
62-
super.showStatus,
63-
super.status,
64-
super.updatedAt,
65-
}) : mimeType = partialFile.mimeType,
66-
name = partialFile.name,
67-
size = partialFile.size,
68-
uri = partialFile.uri,
69-
super(
70-
metadata: partialFile.metadata,
71-
repliedMessage: partialFile.repliedMessage,
72-
type: MessageType.file,
73-
);
60+
String? remoteId,
61+
String? roomId,
62+
bool? showStatus,
63+
Status? status,
64+
int? updatedAt,
65+
}) {
66+
return _FileMessage(
67+
author: author,
68+
createdAt: createdAt,
69+
id: id,
70+
isLoading: isLoading,
71+
metadata: partialFile.metadata,
72+
mimeType: partialFile.mimeType,
73+
name: partialFile.name,
74+
remoteId: remoteId,
75+
repliedMessage: partialFile.repliedMessage,
76+
roomId: roomId,
77+
showStatus: showStatus,
78+
size: partialFile.size,
79+
status: status,
80+
type: MessageType.file,
81+
updatedAt: updatedAt,
82+
uri: partialFile.uri,
83+
);
84+
}
7485

7586
/// Creates a file message from a map (decoded JSON).
7687
factory FileMessage.fromJson(Map<String, dynamic> json) =>

lib/src/messages/image_message.dart

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,36 @@ abstract class ImageMessage extends Message {
5151
}) = _ImageMessage;
5252

5353
/// Creates a full image message from a partial one.
54-
ImageMessage.fromPartial({
55-
required super.author,
56-
super.createdAt,
57-
required super.id,
54+
factory ImageMessage.fromPartial({
55+
required User author,
56+
int? createdAt,
57+
required String id,
5858
required PartialImage partialImage,
59-
super.remoteId,
60-
super.roomId,
61-
super.showStatus,
62-
super.status,
63-
super.updatedAt,
64-
}) : height = partialImage.height,
65-
name = partialImage.name,
66-
size = partialImage.size,
67-
uri = partialImage.uri,
68-
width = partialImage.width,
69-
super(
70-
metadata: partialImage.metadata,
71-
repliedMessage: partialImage.repliedMessage,
72-
type: MessageType.image,
73-
);
59+
String? remoteId,
60+
String? roomId,
61+
bool? showStatus,
62+
Status? status,
63+
int? updatedAt,
64+
}) {
65+
return _ImageMessage(
66+
author: author,
67+
createdAt: createdAt,
68+
height: partialImage.height,
69+
id: id,
70+
metadata: partialImage.metadata,
71+
name: partialImage.name,
72+
remoteId: remoteId,
73+
repliedMessage: partialImage.repliedMessage,
74+
roomId: roomId,
75+
showStatus: showStatus,
76+
size: partialImage.size,
77+
status: status,
78+
type: MessageType.image,
79+
updatedAt: updatedAt,
80+
uri: partialImage.uri,
81+
width: partialImage.width,
82+
);
83+
}
7484

7585
/// Creates an image message from a map (decoded JSON).
7686
factory ImageMessage.fromJson(Map<String, dynamic> json) =>

lib/src/messages/text_message.dart

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,33 @@ abstract class TextMessage extends Message {
4646
}) = _TextMessage;
4747

4848
/// Creates a full text message from a partial one.
49-
TextMessage.fromPartial({
50-
required super.author,
51-
super.createdAt,
52-
required super.id,
49+
factory TextMessage.fromPartial({
50+
required User author,
51+
int? createdAt,
52+
required String id,
5353
required PartialText partialText,
54-
super.remoteId,
55-
super.roomId,
56-
super.showStatus,
57-
super.status,
58-
super.updatedAt,
59-
}) : previewData = partialText.previewData,
60-
text = partialText.text,
61-
super(
62-
metadata: partialText.metadata,
63-
repliedMessage: partialText.repliedMessage,
64-
type: MessageType.text,
65-
);
54+
String? remoteId,
55+
String? roomId,
56+
bool? showStatus,
57+
Status? status,
58+
int? updatedAt,
59+
}) {
60+
return _TextMessage(
61+
author: author,
62+
createdAt: createdAt,
63+
id: id,
64+
metadata: partialText.metadata,
65+
previewData: partialText.previewData,
66+
remoteId: remoteId,
67+
repliedMessage: partialText.repliedMessage,
68+
roomId: roomId,
69+
showStatus: showStatus,
70+
status: status,
71+
text: partialText.text,
72+
type: MessageType.text,
73+
updatedAt: updatedAt,
74+
);
75+
}
6676

6777
/// Creates a text message from a map (decoded JSON).
6878
factory TextMessage.fromJson(Map<String, dynamic> json) =>

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: flutter_chat_types
22
description: >
33
Utility library for the flutter_chat_ui and flutter_firebase_chat_core libraries
44
which contains shared type declarations.
5-
version: 3.4.1
5+
version: 3.4.2
66
homepage: https://flyer.chat
77
repository: https://github.com/flyerhq/flutter_chat_types
88

0 commit comments

Comments
 (0)