feat: add messageType to MessageModel

This commit is contained in:
Freek van de Ven 2025-01-31 09:59:59 +01:00
parent d60917028a
commit e1860898dd
6 changed files with 17 additions and 0 deletions

View file

@ -1,4 +1,5 @@
## 5.0.0 - WIP ## 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 - Get the color for the imagepicker from the Theme's primaryColor
- Added chatMessageBuilder to the userstory configuration to customize the chat messages - Added chatMessageBuilder to the userstory configuration to customize the chat messages

View file

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

View file

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

View file

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

View file

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

View file

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