dialog method

void dialog(
  1. Chat chat,
  2. UserId? me, {
  3. RouteAs mode = RouteAs.replace,
  4. ChatItemId? itemId,
  5. ChatDirectLinkSlug? 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,
  ChatDirectLinkSlug? link,
}) {
  ChatId chatId = chat.id;

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

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

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