copyWith method

Message copyWith({
  1. bool? isDeleted,
  2. bool? isDeletedForMe,
  3. bool? isEdited,
  4. bool? isForwarded,
  5. bool? isPinned,
  6. bool? isRemoved,
  7. bool clearReplyId = false,
  8. String? id,
  9. String? roomId,
  10. String? senderId,
  11. String? replyId,
  12. String? react,
  13. ChatValueTimestamp? createdAt,
  14. ChatValueTimestamp? editedAt,
  15. ChatValueTimestamp? updatedAt,
  16. MessageStatus? status,
  17. MessageExtra? extra,
})

Implementation

Message copyWith({
  bool? isDeleted,
  bool? isDeletedForMe,
  bool? isEdited,
  bool? isForwarded,
  bool? isPinned,
  bool? isRemoved,
  bool clearReplyId = false,
  String? id,
  String? roomId,
  String? senderId,
  String? replyId,
  String? react,
  ChatValueTimestamp? createdAt,
  ChatValueTimestamp? editedAt,
  ChatValueTimestamp? updatedAt,
  MessageStatus? status,
  MessageExtra? extra,
}) {
  final deletes = Map<String, bool>.from(this.deletes);
  if (isDeletedForMe == true) deletes[me] = true;

  final removes = Map<String, bool>.from(this.removes);
  if (isRemoved == true) removes[me] = true;

  final pins = Map<String, bool>.from(this.pins);
  if (isPinned != null) {
    if (isPinned) {
      pins[me] = true;
    } else {
      pins.remove(me);
    }
  }

  final reactions = Map<String, String>.from(this.reactions);
  if (react != null) {
    if (react.isNotEmpty) {
      reactions[me] = react;
    } else {
      reactions.remove(me);
    }
  }

  final statuses = Map<String, MessageStatus>.from(this.statuses);
  if (status != null) statuses[me] = status;

  return Message(
    id: id ?? this.id,
    roomId: roomId ?? this.roomId,
    senderId: senderId ?? this.senderId,
    createdAt: createdAt ?? this.createdAt,
    updatedAt: updatedAt ?? this.updatedAt,
    editedAt: editedAt ?? this.editedAt,
    replyId: clearReplyId ? null : (replyId ?? this.replyId),
    isDeleted: isDeleted ?? this.isDeleted,
    isEdited: isEdited ?? this.isEdited,
    isForwarded: isForwarded ?? this.isForwarded,
    extra: extra ?? this.extra,
    type: type,
    statuses: statuses,
    deletes: deletes,
    removes: removes,
    pins: pins,
    reactions: reactions,
  );
}