Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Comment on lines +3 to +4

## 3.0.0

* **Feat**: [18](https://github.com/SimformSolutionsPvtLtd/chatview_utils/pull/18) Added
Expand Down
56 changes: 45 additions & 11 deletions lib/src/models/data_models/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down Expand Up @@ -72,14 +77,24 @@ class Message {
status: MessageStatus.tryParse(json['status']?.toString()) ??
MessageStatus.pending,
update: updateData is Map<String, dynamic> ? 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);
}(),
);
}

static const String _replyMessage = 'reply_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.
Expand All @@ -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<String, dynamic>? update;

Expand Down Expand Up @@ -146,16 +171,18 @@ 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();
if (!reaction.isEmpty) data[_reaction] = reaction.toJson();
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;
}
Expand All @@ -173,10 +200,15 @@ class Message {
MessageType? messageType,
Duration? voiceMessageDuration,
MessageStatus? status,
DateTime? updatedAt,
@Deprecated(
'Use updatedAt instead.',
)
DateTime? updateAt,
Map<String, String>? update,
Map<String, dynamic>? update,
bool forceNullValue = false,
}) {
final resolvedUpdatedAt = updatedAt ?? updateAt;
return Message(
id: id ?? this.id,
message: message ?? this.message,
Expand All @@ -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,
);
Expand All @@ -212,7 +246,7 @@ class Message {
other.voiceMessageDuration == voiceMessageDuration &&
other.status == status &&
mapEquals(other.update, update) &&
other.updateAt == updateAt;
other.updatedAt == updatedAt;
}

@override
Expand All @@ -227,6 +261,6 @@ class Message {
voiceMessageDuration,
status,
update,
updateAt,
updatedAt,
]);
}
Loading