Skip to content

Commit 2703ff7

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

2 files changed

Lines changed: 39 additions & 10 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: 34 additions & 10 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,16 @@ 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: DateTime.tryParse(json[_updatedAt]?.toString() ?? '') ??
81+
DateTime.tryParse(json[_updateAt].toString()),
7682
);
7783
}
7884

7985
static const String _replyMessage = 'reply_message';
8086
static const String _reaction = 'reaction';
8187
static const String _voiceMessageDuration = 'voice_message_duration';
8288
static const String _updateAt = 'update_at';
89+
static const String _updatedAt = 'updated_at';
8390
static const String _update = 'update';
8491

8592
/// Unique identifier for the message.
@@ -106,7 +113,17 @@ class Message {
106113
/// {@macro chatview_utils.enumeration.MessageType}
107114
final MessageType messageType;
108115

109-
final DateTime? updateAt;
116+
/// The date and time when the message was last updated.
117+
final DateTime? updatedAt;
118+
119+
/// Deprecated. Use [updatedAt] instead.
120+
///
121+
/// This getter is kept for backward compatibility and will be removed
122+
/// in a future version.
123+
@Deprecated(
124+
'Use updatedAt instead.',
125+
)
126+
DateTime? get updateAt => updatedAt;
110127

111128
final Map<String, dynamic>? update;
112129

@@ -146,16 +163,16 @@ class Message {
146163
data[_replyMessage] = replyMessage.toJson();
147164
data[_reaction] = reaction.toJson();
148165
data[_voiceMessageDuration] = voiceMessageDuration?.inMicroseconds;
149-
data[_updateAt] = updateAt?.toIso8601String();
166+
data[_updatedAt] = updatedAt?.toIso8601String();
150167
data[_update] = update;
151168
} else {
152169
if (!replyMessage.isEmpty) data[_replyMessage] = replyMessage.toJson();
153170
if (!reaction.isEmpty) data[_reaction] = reaction.toJson();
154171
if (voiceMessageDuration case final duration?) {
155172
data[_voiceMessageDuration] = duration.inMicroseconds;
156173
}
157-
if (updateAt case final updateAt?) {
158-
data[_updateAt] = updateAt.toIso8601String();
174+
if (updatedAt case final updatedAt?) {
175+
data[_updatedAt] = updatedAt.toIso8601String();
159176
}
160177
if (update?.isNotEmpty ?? false) data[_update] = update;
161178
}
@@ -173,10 +190,15 @@ class Message {
173190
MessageType? messageType,
174191
Duration? voiceMessageDuration,
175192
MessageStatus? status,
193+
DateTime? updatedAt,
194+
@Deprecated(
195+
'Use updatedAt instead.',
196+
)
176197
DateTime? updateAt,
177198
Map<String, String>? update,
178199
bool forceNullValue = false,
179200
}) {
201+
final resolvedUpdatedAt = updatedAt ?? updateAt;
180202
return Message(
181203
id: id ?? this.id,
182204
message: message ?? this.message,
@@ -188,7 +210,9 @@ class Message {
188210
: voiceMessageDuration ?? this.voiceMessageDuration,
189211
reaction: reaction ?? this.reaction,
190212
replyMessage: replyMessage ?? this.replyMessage,
191-
updateAt: forceNullValue ? updateAt : updateAt ?? this.updateAt,
213+
updatedAt: forceNullValue
214+
? resolvedUpdatedAt
215+
: resolvedUpdatedAt ?? this.updatedAt,
192216
update: forceNullValue ? update : update ?? this.update,
193217
status: status ?? this.status,
194218
);
@@ -212,7 +236,7 @@ class Message {
212236
other.voiceMessageDuration == voiceMessageDuration &&
213237
other.status == status &&
214238
mapEquals(other.update, update) &&
215-
other.updateAt == updateAt;
239+
other.updatedAt == updatedAt;
216240
}
217241

218242
@override
@@ -227,6 +251,6 @@ class Message {
227251
voiceMessageDuration,
228252
status,
229253
update,
230-
updateAt,
254+
updatedAt,
231255
]);
232256
}

0 commit comments

Comments
 (0)