directChatSDNID property

String? get directChatSDNID

If this room is a direct chat, this is the sdn ID of the user. Returns null otherwise.

Implementation

String? get directChatSDNID {
  if (membership == Membership.invite) {
    final userID = client.userID;
    if (userID == null) return null;
    final invitation = getState(EventTypes.RoomMember, userID);
    if (invitation != null && invitation.content['is_direct'] == true) {
      return invitation.senderId;
    }
  }

  final mxId = client.directChats.entries
      .firstWhereOrNull((MapEntry<String, dynamic> e) {
    final roomIds = e.value;
    return roomIds is List<dynamic> && roomIds.contains(id);
  })?.key;
  if (mxId?.isValidSDNId == true) return mxId;
  return null;
}