addMember method

void addMember(
  1. Member? newMember
)

Implementation

void addMember(Member? newMember) {
  if (newMember == null) return;

  removeMember(newMember.userId);
  members.add(newMember);
  members.sort((a, b) => a.nickname.compareTo(b.nickname));

  final ts = DateTime.now().millisecondsSinceEpoch;
  final delivery = DeliveryStatus(
    channelUrl: channelUrl,
    updatedDeliveryStatus: {newMember.userId: ts},
  );
  final read = ReadStatus(
    channelType: channelType,
    channelUrl: channelUrl,
    timestamp: ts,
    userId: newMember.userId,
  );

  delivery.saveToCache(chat);
  read.saveToCache(chat);

  _refreshMemberCounts();
}