Skip to content

Commit

Permalink
Fix partial message constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
demchenkoalex committed Jun 14, 2022
1 parent 0a21999 commit 7db0adb
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 69 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.4.2

- Fix partial message constructors

## 3.4.1

- Downgrade meta to support flutter test
Expand Down
38 changes: 24 additions & 14 deletions lib/src/messages/custom_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,31 @@ abstract class CustomMessage extends Message {
}) = _CustomMessage;

/// Creates a full custom message from a partial one.
CustomMessage.fromPartial({
required super.author,
super.createdAt,
required super.id,
factory CustomMessage.fromPartial({
required User author,
int? createdAt,
required String id,
required PartialCustom partialCustom,
super.remoteId,
super.roomId,
super.showStatus,
super.status,
super.updatedAt,
}) : super(
metadata: partialCustom.metadata,
repliedMessage: partialCustom.repliedMessage,
type: MessageType.custom,
);
String? remoteId,
String? roomId,
bool? showStatus,
Status? status,
int? updatedAt,
}) {
return _CustomMessage(
author: author,
createdAt: createdAt,
id: id,
metadata: partialCustom.metadata,
remoteId: remoteId,
repliedMessage: partialCustom.repliedMessage,
roomId: roomId,
showStatus: showStatus,
status: status,
type: MessageType.custom,
updatedAt: updatedAt,
);
}

/// Creates a custom message from a map (decoded JSON).
factory CustomMessage.fromJson(Map<String, dynamic> json) =>
Expand Down
49 changes: 30 additions & 19 deletions lib/src/messages/file_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,37 @@ abstract class FileMessage extends Message {
}) = _FileMessage;

/// Creates a full file message from a partial one.
FileMessage.fromPartial({
required super.author,
super.createdAt,
required super.id,
this.isLoading,
factory FileMessage.fromPartial({
required User author,
int? createdAt,
required String id,
bool? isLoading,
required PartialFile partialFile,
super.remoteId,
super.roomId,
super.showStatus,
super.status,
super.updatedAt,
}) : mimeType = partialFile.mimeType,
name = partialFile.name,
size = partialFile.size,
uri = partialFile.uri,
super(
metadata: partialFile.metadata,
repliedMessage: partialFile.repliedMessage,
type: MessageType.file,
);
String? remoteId,
String? roomId,
bool? showStatus,
Status? status,
int? updatedAt,
}) {
return _FileMessage(
author: author,
createdAt: createdAt,
id: id,
isLoading: isLoading,
metadata: partialFile.metadata,
mimeType: partialFile.mimeType,
name: partialFile.name,
remoteId: remoteId,
repliedMessage: partialFile.repliedMessage,
roomId: roomId,
showStatus: showStatus,
size: partialFile.size,
status: status,
type: MessageType.file,
updatedAt: updatedAt,
uri: partialFile.uri,
);
}

/// Creates a file message from a map (decoded JSON).
factory FileMessage.fromJson(Map<String, dynamic> json) =>
Expand Down
48 changes: 29 additions & 19 deletions lib/src/messages/image_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,36 @@ abstract class ImageMessage extends Message {
}) = _ImageMessage;

/// Creates a full image message from a partial one.
ImageMessage.fromPartial({
required super.author,
super.createdAt,
required super.id,
factory ImageMessage.fromPartial({
required User author,
int? createdAt,
required String id,
required PartialImage partialImage,
super.remoteId,
super.roomId,
super.showStatus,
super.status,
super.updatedAt,
}) : height = partialImage.height,
name = partialImage.name,
size = partialImage.size,
uri = partialImage.uri,
width = partialImage.width,
super(
metadata: partialImage.metadata,
repliedMessage: partialImage.repliedMessage,
type: MessageType.image,
);
String? remoteId,
String? roomId,
bool? showStatus,
Status? status,
int? updatedAt,
}) {
return _ImageMessage(
author: author,
createdAt: createdAt,
height: partialImage.height,
id: id,
metadata: partialImage.metadata,
name: partialImage.name,
remoteId: remoteId,
repliedMessage: partialImage.repliedMessage,
roomId: roomId,
showStatus: showStatus,
size: partialImage.size,
status: status,
type: MessageType.image,
updatedAt: updatedAt,
uri: partialImage.uri,
width: partialImage.width,
);
}

/// Creates an image message from a map (decoded JSON).
factory ImageMessage.fromJson(Map<String, dynamic> json) =>
Expand Down
42 changes: 26 additions & 16 deletions lib/src/messages/text_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,33 @@ abstract class TextMessage extends Message {
}) = _TextMessage;

/// Creates a full text message from a partial one.
TextMessage.fromPartial({
required super.author,
super.createdAt,
required super.id,
factory TextMessage.fromPartial({
required User author,
int? createdAt,
required String id,
required PartialText partialText,
super.remoteId,
super.roomId,
super.showStatus,
super.status,
super.updatedAt,
}) : previewData = partialText.previewData,
text = partialText.text,
super(
metadata: partialText.metadata,
repliedMessage: partialText.repliedMessage,
type: MessageType.text,
);
String? remoteId,
String? roomId,
bool? showStatus,
Status? status,
int? updatedAt,
}) {
return _TextMessage(
author: author,
createdAt: createdAt,
id: id,
metadata: partialText.metadata,
previewData: partialText.previewData,
remoteId: remoteId,
repliedMessage: partialText.repliedMessage,
roomId: roomId,
showStatus: showStatus,
status: status,
text: partialText.text,
type: MessageType.text,
updatedAt: updatedAt,
);
}

/// Creates a text message from a map (decoded JSON).
factory TextMessage.fromJson(Map<String, dynamic> json) =>
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flutter_chat_types
description: >
Utility library for the flutter_chat_ui and flutter_firebase_chat_core libraries
which contains shared type declarations.
version: 3.4.1
version: 3.4.2
homepage: https://flyer.chat
repository: https://github.com/flyerhq/flutter_chat_types

Expand Down

0 comments on commit 7db0adb

Please sign in to comment.