From 58a2229f7d26675cc5ba776fbc877b5e40a43007 Mon Sep 17 00:00:00 2001 From: Alex Demchenko Date: Sat, 24 Apr 2021 19:57:58 +0200 Subject: [PATCH] Add metadata to message and user --- CHANGELOG.md | 4 ++++ lib/src/message.dart | 29 +++++++++++++++++++++++------ lib/src/user.dart | 4 ++++ pubspec.yaml | 2 +- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 263a468..2b1165f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.0.9 + +- Add custom metadata to message and user classes + ## 2.0.8 - Add custom metadata to the room class. Thanks @alihen for the PR! diff --git a/lib/src/message.dart b/lib/src/message.dart index 84ae7d0..7d99b52 100644 --- a/lib/src/message.dart +++ b/lib/src/message.dart @@ -15,6 +15,7 @@ abstract class Message { const Message( this.authorId, this.id, + this.metadata, this.status, this.timestamp, this.type, @@ -46,6 +47,9 @@ abstract class Message { /// Unique ID of the message final String id; + /// Additional custom metadata or attributes related to the message + final Map? metadata; + /// Message [Status] final Status? status; @@ -106,17 +110,19 @@ class FileMessage extends Message { required String authorId, required this.fileName, required String id, + Map? metadata, this.mimeType, required this.size, Status? status, int? timestamp, required this.uri, - }) : super(authorId, id, status, timestamp, MessageType.file); + }) : super(authorId, id, metadata, status, timestamp, MessageType.file); /// Creates a full file message from a partial one. FileMessage.fromPartial({ required String authorId, required String id, + Map? metadata, required PartialFile partialFile, Status? status, int? timestamp, @@ -124,7 +130,7 @@ class FileMessage extends Message { mimeType = partialFile.mimeType, size = partialFile.size, uri = partialFile.uri, - super(authorId, id, status, timestamp, MessageType.file); + super(authorId, id, metadata, status, timestamp, MessageType.file); /// Creates a file message from a map (decoded JSON). FileMessage.fromJson(Map json) @@ -135,6 +141,7 @@ class FileMessage extends Message { super( json['authorId'] as String, json['id'] as String, + json['metadata'] as Map?, getStatusFromString(json['status'] as String?), json['timestamp'] as int?, MessageType.file, @@ -146,6 +153,7 @@ class FileMessage extends Message { 'authorId': authorId, 'fileName': fileName, 'id': id, + 'metadata': metadata, 'mimeType': mimeType, 'size': size, 'status': status, @@ -224,17 +232,19 @@ class ImageMessage extends Message { this.height, required String id, required this.imageName, + Map? metadata, required this.size, Status? status, int? timestamp, required this.uri, this.width, - }) : super(authorId, id, status, timestamp, MessageType.image); + }) : super(authorId, id, metadata, status, timestamp, MessageType.image); /// Creates a full image message from a partial one. ImageMessage.fromPartial({ required String authorId, required String id, + Map? metadata, required PartialImage partialImage, Status? status, int? timestamp, @@ -243,7 +253,7 @@ class ImageMessage extends Message { size = partialImage.size, uri = partialImage.uri, width = partialImage.width, - super(authorId, id, status, timestamp, MessageType.image); + super(authorId, id, metadata, status, timestamp, MessageType.image); /// Creates an image message from a map (decoded JSON). ImageMessage.fromJson(Map json) @@ -255,6 +265,7 @@ class ImageMessage extends Message { super( json['authorId'] as String, json['id'] as String, + json['metadata'] as Map?, getStatusFromString(json['status'] as String?), json['timestamp'] as int?, MessageType.image, @@ -267,6 +278,7 @@ class ImageMessage extends Message { 'height': height, 'id': id, 'imageName': imageName, + 'metadata': metadata, 'size': size, 'status': status, 'timestamp': timestamp, @@ -322,22 +334,24 @@ class TextMessage extends Message { const TextMessage({ required String authorId, required String id, + Map? metadata, this.previewData, Status? status, required this.text, int? timestamp, - }) : super(authorId, id, status, timestamp, MessageType.text); + }) : super(authorId, id, metadata, status, timestamp, MessageType.text); /// Creates a full text message from a partial one. TextMessage.fromPartial({ required String authorId, required String id, + Map? metadata, required PartialText partialText, Status? status, int? timestamp, }) : previewData = null, text = partialText.text, - super(authorId, id, status, timestamp, MessageType.text); + super(authorId, id, metadata, status, timestamp, MessageType.text); /// Creates a text message from a map (decoded JSON). TextMessage.fromJson(Map json) @@ -348,6 +362,7 @@ class TextMessage extends Message { super( json['authorId'] as String, json['id'] as String, + json['metadata'] as Map?, getStatusFromString(json['status'] as String?), json['timestamp'] as int?, MessageType.text, @@ -358,6 +373,7 @@ class TextMessage extends Message { Map toJson() => { 'authorId': authorId, 'id': id, + 'metadata': metadata, 'previewData': previewData?.toJson(), 'status': status, 'text': text, @@ -370,6 +386,7 @@ class TextMessage extends Message { return TextMessage( authorId: authorId, id: id, + metadata: metadata, previewData: previewData, status: status, text: text, diff --git a/lib/src/user.dart b/lib/src/user.dart index eca3d61..2dd6dda 100644 --- a/lib/src/user.dart +++ b/lib/src/user.dart @@ -9,6 +9,7 @@ class User { this.firstName, required this.id, this.lastName, + this.metadata, }); /// Remote image URL representing user's avatar @@ -22,4 +23,7 @@ class User { /// Last name of the user final String? lastName; + + /// Additional custom metadata or attributes related to the user + final Map? metadata; } diff --git a/pubspec.yaml b/pubspec.yaml index 733cf36..e51fc4d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: 2.0.8 +version: 2.0.9 homepage: https://flyer.chat environment: