copyWith method

Room copyWith({
  1. Iterable<String>? blocks,
  2. ChatValueTimestamp? createdAt,
  3. String? createdBy,
  4. RoomExtra? extra,
  5. String? id,
  6. bool? isAddMember,
  7. bool? isArchived,
  8. bool? isBlocked,
  9. bool? isBot,
  10. bool? isDeleted,
  11. bool? isGroup,
  12. bool? isLeaved,
  13. bool? isLocal,
  14. bool? isMuted,
  15. bool? isPinned,
  16. bool? isRemoved,
  17. bool? isRestricted,
  18. bool? isVerified,
  19. bool clearLastMessage = false,
  20. String? lastMessage,
  21. bool? lastMessageDeleted,
  22. String? lastMessageId,
  23. String? lastMessageSenderId,
  24. Map<String, MessageStatus>? lastMessageStatuses,
  25. Iterable<String>? participants,
  26. Iterable<String>? restricts,
  27. Map<String, int>? unseenCounts,
  28. ChatValueTimestamp? updatedAt,
})

Implementation

Room copyWith({
  Iterable<String>? blocks,
  ChatValueTimestamp? createdAt,
  String? createdBy,
  RoomExtra? extra,
  String? id,
  bool? isAddMember,
  bool? isArchived,
  bool? isBlocked,
  bool? isBot,
  bool? isDeleted,
  bool? isGroup,
  bool? isLeaved,
  bool? isLocal,
  bool? isMuted,
  bool? isPinned,
  bool? isRemoved,
  bool? isRestricted,
  bool? isVerified,
  bool clearLastMessage = false,
  String? lastMessage,
  bool? lastMessageDeleted,
  String? lastMessageId,
  String? lastMessageSenderId,
  Map<String, MessageStatus>? lastMessageStatuses,
  Iterable<String>? participants,
  Iterable<String>? restricts,
  Map<String, int>? unseenCounts,
  ChatValueTimestamp? updatedAt,
}) {
  final mArchives = {...archives};
  if (isArchived != null) {
    isArchived ? mArchives.add(me) : mArchives.remove(me);
  }

  final mBlocks = {...this.blocks};
  if (isBlocked != null && blocks != null && blocks.isNotEmpty) {
    isBlocked ? mBlocks.addAll(blocks) : mBlocks.removeAll(blocks);
  }

  final mLeaves = {...leaves};
  if (isLeaved != null) {
    isLeaved ? mLeaves.add(me) : mLeaves.remove(me);
  }

  final mMutes = {...mutes};
  if (isMuted != null) {
    isMuted ? mMutes.add(me) : mMutes.remove(me);
  }

  final mPins = {...pins};
  if (isPinned != null) {
    isPinned ? mPins.add(me) : mPins.remove(me);
  }

  final mParticipants = {...this.participants};
  if (isAddMember != null &&
      participants != null &&
      participants.isNotEmpty) {
    isAddMember
        ? mParticipants.addAll(participants)
        : mParticipants.removeAll(participants);
  }

  final mRemoves = {...removes};
  if (isRemoved != null &&
      lastMessageId != null &&
      lastMessageId.isNotEmpty) {
    isRemoved ? mRemoves[me] = lastMessageId : mRemoves.remove(me);
  }

  final mRestricts = {...this.restricts};
  if (isRestricted != null && restricts != null && restricts.isNotEmpty) {
    isRestricted
        ? mRestricts.addAll(restricts)
        : mRestricts.removeAll(restricts);
  }

  return Room(
    archives: mArchives,
    blocks: mBlocks,
    createdAt: createdAt ?? this.createdAt,
    createdBy: createdBy ?? this.createdBy,
    extra: extra ?? this.extra,
    id: id ?? this.id,
    isBot: isBot ?? this.isBot,
    isDeleted: isDeleted ?? this.isDeleted,
    isGroup: isGroup ?? this.isGroup,
    isLocal: isLocal ?? this.isLocal,
    isVerified: isVerified ?? this.isVerified,
    lastMessage: clearLastMessage ? null : (lastMessage ?? this.lastMessage),
    lastMessageDeleted: lastMessageDeleted ?? this.lastMessageDeleted,
    lastMessageId: lastMessageId ?? this.lastMessageId,
    lastMessageSenderId: lastMessageSenderId ?? this.lastMessageSenderId,
    lastMessageStatuses: lastMessageStatuses ?? this.lastMessageStatuses,
    leaves: mLeaves,
    mutes: mMutes,
    participants: mParticipants,
    pins: mPins,
    removes: mRemoves,
    restricts: mRestricts,
    unseenCounts: unseenCounts ?? _unseenCounts,
    updatedAt: updatedAt ?? this.updatedAt,
  );
}