loginAnonymousWithFile static method
Implementation
static Future<TPUser?> loginAnonymousWithFile(String userId,
String? username,
File? profileImageFile,
Map<String, String>? metaData,
{
String translationLanguage = "",
Function(int? errorCode, String? errorMessage)? errorCallback
}) async
{
if (!_isInitialized(errorCallback: errorCallback)) { return null; }
String? deviceId = await getDeviceUuid();
Map<String, dynamic> body = Map.from(
{"userId": userId, "deviceId": deviceId, "sdkVersion": VERSION_NAME});
if (Platform.isAndroid) {
body["deviceType"] = "aos";
} else if (Platform.isIOS) {
body["deviceType"] = "ios";
} else {
body["deviceType"] = "unknown";
}
if (username != null) { body["username"] = username; }
if (metaData != null) { body["data"] = metaData; }
if (translationLanguage.isNotEmpty) { body["translationTargetLanguage"] = translationLanguage; }
try {
String url = "/users/login/anonymous";
Map<String, dynamic> response =
await HttpUtil.postMultipart(url, body, profileImageFile);
String sessionId = response["sessionId"];
String sessionToken = response["sessionToken"];
await HttpUtil.setSessionData(userId ?? "", sessionToken ?? "", sessionId ?? "");
Map<String, dynamic> user = response["user"];
_mUser = TPUser(user);
_mTimestampInMillis = 0;
_startNotificationWebSocket();
return _mUser;
} 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;
}