feat: add messageType to MessageModel

This commit is contained in:
Freek van de Ven 2025-01-31 09:59:59 +01:00 committed by FlutterJoey
parent 7457602afe
commit 3e03dd755e
6 changed files with 17 additions and 0 deletions

View file

@ -1,4 +1,5 @@
## 5.0.0 - WIP
- Added messageType to the ChatMessageModel to allow for different type of messages, it is nullable to remain backwards compatible
- Get the color for the imagepicker from the Theme's primaryColor
- Added chatMessageBuilder to the userstory configuration to customize the chat messages

View file

@ -74,6 +74,7 @@ abstract class ChatRepositoryInterface {
required String messageId,
String? text,
String? imageUrl,
String? messageType,
DateTime? timestamp,
});

View file

@ -50,6 +50,7 @@ class LocalChatRepository implements ChatRepositoryInterface {
chatId: chat.id,
senderId: message.senderId,
text: message.text,
messageType: message.messageType,
imageUrl: message.imageUrl,
timestamp: message.timestamp,
);
@ -182,6 +183,7 @@ class LocalChatRepository implements ChatRepositoryInterface {
required String messageId,
String? text,
String? imageUrl,
String? messageType,
DateTime? timestamp,
}) async {
var message = MessageModel(
@ -189,6 +191,7 @@ class LocalChatRepository implements ChatRepositoryInterface {
id: messageId,
timestamp: timestamp ?? DateTime.now(),
text: text,
messageType: messageType,
senderId: senderId,
imageUrl: imageUrl,
);

View file

@ -11,6 +11,7 @@ class MessageModel {
required this.chatId,
required this.id,
required this.text,
required this.messageType,
required this.imageUrl,
required this.timestamp,
required this.senderId,
@ -22,6 +23,7 @@ class MessageModel {
chatId: map["chatId"],
id: id,
text: map["text"],
messageType: map["messageType"],
imageUrl: map["imageUrl"],
timestamp: DateTime.fromMillisecondsSinceEpoch(map["timestamp"]),
senderId: map["senderId"],
@ -36,6 +38,9 @@ class MessageModel {
/// The message text
final String? text;
/// The type of message for instance (user, system, etc)
final String? messageType;
/// The message image url
final String? imageUrl;
@ -50,6 +55,7 @@ class MessageModel {
String? chatId,
String? id,
String? text,
String? messageType,
String? imageUrl,
DateTime? timestamp,
String? senderId,
@ -58,6 +64,7 @@ class MessageModel {
chatId: chatId ?? this.chatId,
id: id ?? this.id,
text: text ?? this.text,
messageType: messageType ?? this.messageType,
imageUrl: imageUrl ?? this.imageUrl,
timestamp: timestamp ?? this.timestamp,
senderId: senderId ?? this.senderId,
@ -67,6 +74,7 @@ class MessageModel {
Map<String, dynamic> toMap() => {
"chatId": chatId,
"text": text,
"messageType": messageType,
"imageUrl": imageUrl,
"timestamp": timestamp.millisecondsSinceEpoch,
"senderId": senderId,

View file

@ -155,12 +155,14 @@ class ChatService {
required String senderId,
required String messageId,
String? text,
String? messageType,
String? imageUrl,
}) =>
chatRepository.sendMessage(
chatId: chatId,
messageId: messageId,
text: text,
messageType: messageType,
senderId: senderId,
imageUrl: imageUrl,
);

View file

@ -150,6 +150,7 @@ class FirebaseChatRepository implements ChatRepositoryInterface {
required String messageId,
String? text,
String? imageUrl,
String? messageType,
DateTime? timestamp,
}) async {
var message = MessageModel(
@ -157,6 +158,7 @@ class FirebaseChatRepository implements ChatRepositoryInterface {
id: messageId,
text: text,
imageUrl: imageUrl,
messageType: messageType,
timestamp: timestamp ?? DateTime.now(),
senderId: senderId,
);