dialog method

void dialog(
  1. Chat chat,
  2. UserId? me, {
  3. RouteAs mode = RouteAs.replace,
  4. ChatItemId? itemId,
  5. DirectLinkSlug? link,
})

Changes router location to the Routes.chats page respecting the possible chat being a dialog.

If push is true, then location is pushed to the router location stack.

Implementation

void dialog(
  Chat chat,
  UserId? me, {
  RouteAs mode = RouteAs.replace,
  ChatItemId? itemId,
  DirectLinkSlug? link,
}) {
  ChatId chatId = chat.id;

  if (chat.isDialog) {
    ChatMember? member = chat.members.firstWhereOrNull(
      (e) => e.user.id != me,
    );

    if (member != null) {
      chatId = ChatId.local(member.user.id);
    }
  } else if (chat.isMonolog) {
    if (me != null) {
      chatId = ChatId.local(me);
    } else {
      ChatMember? member = chat.members.firstWhereOrNull(
        (e) => !e.user.id.isLocal,
      );
      member ??= chat.members.firstOrNull;

      if (member != null) {
        chatId = ChatId.local(member.user.id);
      }
    }
  }

  router.chat(chatId, itemId: itemId, link: link, mode: mode);
}