diff --git a/CHANGELOG.md b/CHANGELOG.md index ee1edfa..5a0a205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [Unreleased] + +* **Fix**: [26](https://github.com/SimformSolutionsPvtLtd/chatview_utils/pull/26) Renamed `updateAt` to `updatedAt` in `Message` model for + consistency. The deprecated `updateAt` getter is still available for backward compatibility but will be removed in a future version. `fromJson()` now reads from `updated_at` key and falls back to `update_at` key if not found. + ## 3.0.0 * **Feat**: [18](https://github.com/SimformSolutionsPvtLtd/chatview_utils/pull/18) Added diff --git a/lib/src/models/data_models/message.dart b/lib/src/models/data_models/message.dart index 2553440..8e25d5f 100644 --- a/lib/src/models/data_models/message.dart +++ b/lib/src/models/data_models/message.dart @@ -36,11 +36,16 @@ class Message { this.replyMessage = const ReplyMessage(), this.messageType = MessageType.text, this.voiceMessageDuration, - this.updateAt, + DateTime? updatedAt, + @Deprecated( + 'Use updatedAt instead.', + ) + DateTime? updateAt, this.update, MessageStatus status = MessageStatus.pending, Reaction? reaction, - }) : reaction = reaction ?? Reaction(reactions: [], reactedUserIds: []), + }) : updatedAt = updatedAt ?? updateAt, + reaction = reaction ?? Reaction(reactions: [], reactedUserIds: []), _status = ValueNotifier(status), assert( defaultTargetPlatform.isAudioWaveformsSupported || @@ -72,7 +77,16 @@ class Message { status: MessageStatus.tryParse(json['status']?.toString()) ?? MessageStatus.pending, update: updateData is Map ? updateData : null, - updateAt: DateTime.tryParse(json[_updateAt].toString()), + updatedAt: () { + final updatedAtStr = json[_updatedAt]?.toString(); + final updateAtStr = json[_updateAt]?.toString(); + return (updatedAtStr?.isNotEmpty ?? false + ? DateTime.tryParse(updatedAtStr!) + : null) ?? + (updateAtStr?.isNotEmpty ?? false + ? DateTime.tryParse(updateAtStr!) + : null); + }(), ); } @@ -80,6 +94,7 @@ class Message { static const String _reaction = 'reaction'; static const String _voiceMessageDuration = 'voice_message_duration'; static const String _updateAt = 'update_at'; + static const String _updatedAt = 'updated_at'; static const String _update = 'update'; /// Unique identifier for the message. @@ -106,7 +121,17 @@ class Message { /// {@macro chatview_utils.enumeration.MessageType} final MessageType messageType; - final DateTime? updateAt; + /// The date and time when the message was last updated. + final DateTime? updatedAt; + + /// Deprecated. Use [updatedAt] instead. + /// + /// This getter is kept for backward compatibility and will be removed + /// in a future version. + @Deprecated( + 'Use updatedAt instead.', + ) + DateTime? get updateAt => updatedAt; final Map? update; @@ -146,7 +171,8 @@ class Message { data[_replyMessage] = replyMessage.toJson(); data[_reaction] = reaction.toJson(); data[_voiceMessageDuration] = voiceMessageDuration?.inMicroseconds; - data[_updateAt] = updateAt?.toIso8601String(); + data[_updatedAt] = updatedAt?.toIso8601String(); + data[_updateAt] = updatedAt?.toIso8601String(); data[_update] = update; } else { if (!replyMessage.isEmpty) data[_replyMessage] = replyMessage.toJson(); @@ -154,8 +180,9 @@ class Message { if (voiceMessageDuration case final duration?) { data[_voiceMessageDuration] = duration.inMicroseconds; } - if (updateAt case final updateAt?) { - data[_updateAt] = updateAt.toIso8601String(); + if (updatedAt case final updatedAt?) { + data[_updatedAt] = updatedAt.toIso8601String(); + data[_updateAt] = updatedAt.toIso8601String(); } if (update?.isNotEmpty ?? false) data[_update] = update; } @@ -173,10 +200,15 @@ class Message { MessageType? messageType, Duration? voiceMessageDuration, MessageStatus? status, + DateTime? updatedAt, + @Deprecated( + 'Use updatedAt instead.', + ) DateTime? updateAt, - Map? update, + Map? update, bool forceNullValue = false, }) { + final resolvedUpdatedAt = updatedAt ?? updateAt; return Message( id: id ?? this.id, message: message ?? this.message, @@ -188,7 +220,9 @@ class Message { : voiceMessageDuration ?? this.voiceMessageDuration, reaction: reaction ?? this.reaction, replyMessage: replyMessage ?? this.replyMessage, - updateAt: forceNullValue ? updateAt : updateAt ?? this.updateAt, + updatedAt: forceNullValue + ? resolvedUpdatedAt + : resolvedUpdatedAt ?? this.updatedAt, update: forceNullValue ? update : update ?? this.update, status: status ?? this.status, ); @@ -212,7 +246,7 @@ class Message { other.voiceMessageDuration == voiceMessageDuration && other.status == status && mapEquals(other.update, update) && - other.updateAt == updateAt; + other.updatedAt == updatedAt; } @override @@ -227,6 +261,6 @@ class Message { voiceMessageDuration, status, update, - updateAt, + updatedAt, ]); }