resolve method

Future<T> resolve(
  1. Snowflake id
)

Implementation

Future<T> resolve (Snowflake id) async {
  if(cache.containsKey(id)) {
    return cache.getOrFail(id);
  }

  final Response response = await ioc.use<DiscordApiHttpService>()
      .get(url: '/channels/$_channelId/messages/$id')
      .build();

  if(response.statusCode == 200) {
    dynamic payload = jsonDecode(response.body);

    if (_guildId != null) {
      final Guild guild = ioc.use<MineralClient>().guilds.cache.getOrFail(_guildId);
      Message message = Message.from(
          channel: guild.channels.cache.getOrFail(_channelId),
          payload: payload
      );

      cache.putIfAbsent(message.id, () => message as T);
      return message as T;
    } else {
      DmMessage message = DmMessage.from(
          channel: ioc.use<MineralClient>().dmChannels.cache.getOrFail(_channelId),
          payload: payload
      );

      cache.putIfAbsent(message.id, () => message as T);
      return message as T;
    }
  }

  throw ApiException('Unable to fetch message with id #$id');
}