joinChannelInvitation static method

Future<TPChannel?> joinChannelInvitation(
  1. String channelId,
  2. String invitationCode, {
  3. dynamic errorCallback(
    1. int? errorCode,
    2. String? errorMessage
    )?,
})

Implementation

static Future<TPChannel?> joinChannelInvitation(
    String channelId,
    String invitationCode,
    {
      Function(int? errorCode, String? errorMessage)? errorCallback
    }) async
{
  if (!_isInitialized(errorCallback: errorCallback)) { return null; }
  if (!_checkAuthInfo(errorCallback: errorCallback)) { return null; }
  try {
    Map<String, dynamic> body = Map.from({"invitationCode": invitationCode});
    String url = "/channels/$channelId/join/invitation";
    Map<String, dynamic> response = await HttpUtil.postJson(url, body);
    Map<String, dynamic> channel = response["channel"];
    return TPChannel(channel);
  } 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 null;
}