ChannelModel constructor

ChannelModel({
  1. String? id,
  2. String? type,
  3. String? cid,
  4. List<String>? ownCapabilities,
  5. ChannelConfig? config,
  6. User? createdBy,
  7. bool frozen = false,
  8. DateTime? lastMessageAt,
  9. DateTime? createdAt,
  10. DateTime? updatedAt,
  11. DateTime? deletedAt,
  12. int memberCount = 0,
  13. Map<String, Object?> extraData = const {},
  14. String? team,
  15. int cooldown = 0,
  16. bool? disabled,
  17. bool? hidden,
  18. DateTime? truncatedAt,
})

Constructor used for json serialization

Implementation

ChannelModel({
  String? id,
  String? type,
  String? cid,
  this.ownCapabilities,
  ChannelConfig? config,
  this.createdBy,
  this.frozen = false,
  this.lastMessageAt,
  DateTime? createdAt,
  DateTime? updatedAt,
  this.deletedAt,
  this.memberCount = 0,
  Map<String, Object?> extraData = const {},
  this.team,
  this.cooldown = 0,
  bool? disabled,
  bool? hidden,
  DateTime? truncatedAt,
})  : assert(
        (cid != null && cid.contains(':')) || (id != null && type != null),
        'provide either a cid or an id and type',
      ),
      id = id ?? cid!.split(':')[1],
      type = type ?? cid!.split(':')[0],
      cid = cid ?? '$type:$id',
      config = config ?? ChannelConfig(),
      createdAt = createdAt ?? DateTime.now(),
      updatedAt = updatedAt ?? DateTime.now(),

      // For backwards compatibility, set 'disabled', 'hidden'
      // and 'truncated_at' in [extraData].
      extraData = {
        ...extraData,
        if (disabled != null) 'disabled': disabled,
        if (hidden != null) 'hidden': hidden,
        if (truncatedAt != null)
          'truncated_at': truncatedAt.toIso8601String(),
      };