Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [Unreleased]

* **Fix**: [26](https://github.com/SimformSolutionsPvtLtd/chatview_utils/pull/26) Rename `updateAt` to `updatedAt` in `Message` model for consistency

## 3.0.0

* **Feat**: [18](https://github.com/SimformSolutionsPvtLtd/chatview_utils/pull/18) Added
Expand Down
50 changes: 39 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,16 @@ 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: DateTime.tryParse(json[_updatedAt].toString()) ??
DateTime.tryParse(json[_updateAt].toString()),
);
}

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 +113,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 +163,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 +192,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 +212,11 @@ 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,
// this.updateAt is stored in the local updatedAt variable
// so no need to pass this.updateAt
update: forceNullValue ? update : update ?? this.update,
status: status ?? this.status,
);
Expand All @@ -212,7 +240,7 @@ class Message {
other.voiceMessageDuration == voiceMessageDuration &&
other.status == status &&
mapEquals(other.update, update) &&
other.updateAt == updateAt;
other.updatedAt == updatedAt;
}

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