getConversations method

  1. @override
Future<List<SquadweConversation>> getConversations()
override

Gets all conversation of current squadwe client instance

Implementation

@override
Future<List<SquadweConversation>> getConversations() async {
  try {
    final createResponse = await _dio.get(
        "/public/api/v1/inboxes/${SquadweClientApiInterceptor.INTERCEPTOR_INBOX_IDENTIFIER_PLACEHOLDER}/contacts/${SquadweClientApiInterceptor.INTERCEPTOR_CONTACT_IDENTIFIER_PLACEHOLDER}/conversations");
    if ((createResponse.statusCode ?? 0).isBetween(199, 300)) {
      return (createResponse.data as List<dynamic>)
          .map(((json) => SquadweConversation.fromJson(json)))
          .toList();
    } else {
      throw SquadweClientException(
          createResponse.statusMessage ?? "unknown error",
          SquadweClientExceptionType.GET_CONVERSATION_FAILED);
    }
  } on DioError catch (e) {
    throw SquadweClientException(
        e.message, SquadweClientExceptionType.GET_CONVERSATION_FAILED);
  }
}