Skip to content

Commit 9cbf9a2

Browse files
fix: 🐛 Rename updateAt to updatedAt in Message model for consistency
1 parent c7cd0ed commit 9cbf9a2

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [Unreleased]
2+
3+
* **Fix**: [26](https://github.com/SimformSolutionsPvtLtd/chatview_utils/pull/26) Renamed `updateAt` to `updatedAt` in `Message` model for
4+
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.
5+
16
## 3.0.0
27

38
* **Feat**: [18](https://github.com/SimformSolutionsPvtLtd/chatview_utils/pull/18) Added

lib/src/models/data_models/message.dart

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ class Message {
3636
this.replyMessage = const ReplyMessage(),
3737
this.messageType = MessageType.text,
3838
this.voiceMessageDuration,
39-
this.updateAt,
39+
DateTime? updatedAt,
40+
@Deprecated(
41+
'Use updatedAt instead.',
42+
)
43+
DateTime? updateAt,
4044
this.update,
4145
MessageStatus status = MessageStatus.pending,
4246
Reaction? reaction,
43-
}) : reaction = reaction ?? Reaction(reactions: [], reactedUserIds: []),
47+
}) : updatedAt = updatedAt ?? updateAt,
48+
reaction = reaction ?? Reaction(reactions: [], reactedUserIds: []),
4449
_status = ValueNotifier(status),
4550
assert(
4651
defaultTargetPlatform.isAudioWaveformsSupported ||
@@ -72,14 +77,24 @@ class Message {
7277
status: MessageStatus.tryParse(json['status']?.toString()) ??
7378
MessageStatus.pending,
7479
update: updateData is Map<String, dynamic> ? updateData : null,
75-
updateAt: DateTime.tryParse(json[_updateAt].toString()),
80+
updatedAt: () {
81+
final updatedAtStr = json[_updatedAt]?.toString();
82+
final updateAtStr = json[_updateAt]?.toString();
83+
return (updatedAtStr?.isNotEmpty ?? false
84+
? DateTime.tryParse(updatedAtStr!)
85+
: null) ??
86+
(updateAtStr?.isNotEmpty ?? false
87+
? DateTime.tryParse(updateAtStr!)
88+
: null);
89+
}(),
7690
);
7791
}
7892

7993
static const String _replyMessage = 'reply_message';
8094
static const String _reaction = 'reaction';
8195
static const String _voiceMessageDuration = 'voice_message_duration';
8296
static const String _updateAt = 'update_at';
97+
static const String _updatedAt = 'updated_at';
8398
static const String _update = 'update';
8499

85100
/// Unique identifier for the message.
@@ -106,7 +121,17 @@ class Message {
106121
/// {@macro chatview_utils.enumeration.MessageType}
107122
final MessageType messageType;
108123

109-
final DateTime? updateAt;
124+
/// The date and time when the message was last updated.
125+
final DateTime? updatedAt;
126+
127+
/// Deprecated. Use [updatedAt] instead.
128+
///
129+
/// This getter is kept for backward compatibility and will be removed
130+
/// in a future version.
131+
@Deprecated(
132+
'Use updatedAt instead.',
133+
)
134+
DateTime? get updateAt => updatedAt;
110135

111136
final Map<String, dynamic>? update;
112137

@@ -146,16 +171,18 @@ class Message {
146171
data[_replyMessage] = replyMessage.toJson();
147172
data[_reaction] = reaction.toJson();
148173
data[_voiceMessageDuration] = voiceMessageDuration?.inMicroseconds;
149-
data[_updateAt] = updateAt?.toIso8601String();
174+
data[_updatedAt] = updatedAt?.toIso8601String();
175+
data[_updateAt] = updatedAt?.toIso8601String();
150176
data[_update] = update;
151177
} else {
152178
if (!replyMessage.isEmpty) data[_replyMessage] = replyMessage.toJson();
153179
if (!reaction.isEmpty) data[_reaction] = reaction.toJson();
154180
if (voiceMessageDuration case final duration?) {
155181
data[_voiceMessageDuration] = duration.inMicroseconds;
156182
}
157-
if (updateAt case final updateAt?) {
158-
data[_updateAt] = updateAt.toIso8601String();
183+
if (updatedAt case final updatedAt?) {
184+
data[_updatedAt] = updatedAt.toIso8601String();
185+
data[_updateAt] = updatedAt.toIso8601String();
159186
}
160187
if (update?.isNotEmpty ?? false) data[_update] = update;
161188
}
@@ -173,10 +200,15 @@ class Message {
173200
MessageType? messageType,
174201
Duration? voiceMessageDuration,
175202
MessageStatus? status,
203+
DateTime? updatedAt,
204+
@Deprecated(
205+
'Use updatedAt instead.',
206+
)
176207
DateTime? updateAt,
177-
Map<String, String>? update,
208+
Map<String, dynamic>? update,
178209
bool forceNullValue = false,
179210
}) {
211+
final resolvedUpdatedAt = updatedAt ?? updateAt;
180212
return Message(
181213
id: id ?? this.id,
182214
message: message ?? this.message,
@@ -188,7 +220,9 @@ class Message {
188220
: voiceMessageDuration ?? this.voiceMessageDuration,
189221
reaction: reaction ?? this.reaction,
190222
replyMessage: replyMessage ?? this.replyMessage,
191-
updateAt: forceNullValue ? updateAt : updateAt ?? this.updateAt,
223+
updatedAt: forceNullValue
224+
? resolvedUpdatedAt
225+
: resolvedUpdatedAt ?? this.updatedAt,
192226
update: forceNullValue ? update : update ?? this.update,
193227
status: status ?? this.status,
194228
);
@@ -212,7 +246,7 @@ class Message {
212246
other.voiceMessageDuration == voiceMessageDuration &&
213247
other.status == status &&
214248
mapEquals(other.update, update) &&
215-
other.updateAt == updateAt;
249+
other.updatedAt == updatedAt;
216250
}
217251

218252
@override
@@ -227,6 +261,6 @@ class Message {
227261
voiceMessageDuration,
228262
status,
229263
update,
230-
updateAt,
264+
updatedAt,
231265
]);
232266
}

0 commit comments

Comments
 (0)