onSelectedKnown method

void onSelectedKnown(
  1. dynamic context,
  2. dynamic ref,
  3. dynamic spaceSearchResult,
  4. String? searchServer,
)

Implementation

void onSelectedKnown(
  BuildContext context,
  WidgetRef ref,
  PublicSearchResultItem spaceSearchResult,
  String? searchServer,
) async {
  final roomId = spaceSearchResult.roomIdStr();
  if ((await ref.read(roomMembershipProvider(roomId).future)) != null) {
    // we know the space, user just wants to enter it
    if (spaceSearchResult.roomTypeStr() == 'Space') {
      // ignore: use_build_context_synchronously
      context.pushNamed(
        Routes.space.name,
        pathParameters: {'spaceId': roomId},
      );
    } else {
      // ignore: use_build_context_synchronously
      context.pushNamed(
        Routes.chatroom.name,
        pathParameters: {'roomId': roomId},
      );
    }
    return;
  }

  // we don’t know the space yet, the user wants to join.
  final joinRule = spaceSearchResult.joinRuleStr();
  if (joinRule != 'Public') {
    // ignore: use_build_context_synchronously
    EasyLoading.showToast(L10n.of(context).joinRuleNotSupportedYet(joinRule));
    return;
  }
  await joinRoom(
    // ignore: use_build_context_synchronously
    context,
    ref,
    // ignore: use_build_context_synchronously
    L10n.of(context).tryingToJoin(spaceSearchResult.name().toString()),
    roomId,
    searchServer,
    (roomId) => context.pushNamed(
      Routes.space.name,
      pathParameters: {'spaceId': roomId},
    ),
  );
}