chat method

void chat(
  1. ChatId id, {
  2. RouteAs mode = RouteAs.replace,
  3. ChatItemId? itemId,
  4. ChatDirectLinkSlug? link,
  5. bool search = false,
})

Changes router location to the Routes.chats page.

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

Implementation

void chat(
  ChatId id, {
  RouteAs mode = RouteAs.replace,
  ChatItemId? itemId,
  ChatDirectLinkSlug? link,
  bool search = false,
}) {
  switch (mode) {
    case RouteAs.insteadOfLast:
      routes.removeLast();
      push('${Routes.chats}/$id');
      break;

    case RouteAs.replace:
      go('${Routes.chats}/$id');
      break;

    case RouteAs.push:
      push('${Routes.chats}/$id');
      break;
  }

  arguments = {'itemId': itemId, 'link': link, 'search': search};

  // TODO: Might not be the best thing to do it.
  if (search) {
    final List<ChatController> chats = Get.findAll<ChatController>();

    for (var e in chats) {
      if (e.id == id || (id.isLocal && e.user?.id == id.userId)) {
        e.toggleSearch();
      }
    }
  }
}