getMessage static method

Future<bool> getMessage(
  1. TPChannel tpChannel,
  2. String messageId,
  3. dynamic successCallback(
    1. TPMessage
    ), {
  4. String translationLanguage = "",
  5. dynamic errorCallback(
    1. int? errorCode,
    2. String? errorMessage
    )?,
})

Implementation

static Future<bool> getMessage(
    TPChannel tpChannel,
    String messageId,
    Function(TPMessage) successCallback,
    {
      String translationLanguage = "",
      Function(int? errorCode, String? errorMessage)? errorCallback
    }) async
{
  if (!_isInitialized(errorCallback: errorCallback)) { return false; }
  if (!_checkAuthInfo(errorCallback: errorCallback)) { return false; }

  String url = "/channels/${tpChannel.getChannelId()}/messages/$messageId";
  // Appends query string
  if(translationLanguage.isNotEmpty){
    String queryString = _buildQueryString({"translationTargetLanguage" : translationLanguage});
    url += queryString;
  }

  try {
    Map<String, dynamic> response = await HttpUtil.get(url);
    successCallback(TPMessage(response["message"]));
    return true;
  } on TPException catch(e) {
    Logger.log("$e");
    if(errorCallback != null) { errorCallback(e.getCode(), e.getMessage()); }
  } catch(e){
    Logger.log("$e");
    if(errorCallback != null) { errorCallback(-1, e.toString()); }
  }
  return false;
}