var User = require('./User')
var NATIVE_BRIDGE_NAME = "GetSocialCurrentUser";
var CurrentUser = function(serializedUser) {
User.call(this, serializedUser);
this.onErrorPlugin = function(err) {
console.log(err);
}
this.onSerializeDataReceive = function(data) {
this.deserialize(JSON.parse(data));
}
}
CurrentUser.prototype.resolveUserIdentityConflict = function(resolution, onSuccess, onFailure) {
cordova.exec(onSuccess, onFailure, NATIVE_BRIDGE_NAME, "resolveUserIdentityConflict", [resolution]);
}
CurrentUser.prototype.setDisplayName = function(displayName, onSuccess, onFailure) {
var scope = this;
cordova.exec(function(serializedUser) {
scope.onSerializeDataReceive(serializedUser);
onSuccess(scope.displayName());
}, onFailure, NATIVE_BRIDGE_NAME, "setDisplayName", [displayName]);
}
CurrentUser.prototype.setAvatarUrl = function(avatarUrl, onSuccess, onFailure) {
var scope = this;
cordova.exec(function(serializedUser) {
scope.onSerializeDataReceive(serializedUser);
onSuccess(scope.avatarUrl());
}, onFailure, NATIVE_BRIDGE_NAME, "setAvatarUrl", [avatarUrl]);
}
CurrentUser.prototype.addFbUserIdentity = function(token, onSuccess, onConflict, onFailure) {
var scope = this;
cordova.exec(function(data) {
if(data.isConflict) {
onConflict();
} else {
scope.onSerializeDataReceive(data.serializedUser);
onSuccess(scope, data.resolveStatus);
}
}, onFailure, NATIVE_BRIDGE_NAME, "addFbUserIdentity", [token]);
}
CurrentUser.prototype.addGooglePlusUserIdentity = function(token, onSuccess, onConflict, onFailure) {
var scope = this;
cordova.exec(function(data) {
if(data.isConflict) {
onConflict();
} else {
scope.onSerializeDataReceive(data.serializedUser);
onSuccess(scope, data.resolveStatus);
}
}, onFailure, NATIVE_BRIDGE_NAME, "addGooglePlusUserIdentity", [token]);
}
CurrentUser.prototype.addGooglePlayUserIdentity = function(token, onSuccess, onConflict, onFailure) {
var scope = this;
cordova.exec(function(data) {
if(data.isConflict) {
onConflict();
} else {
scope.onSerializeDataReceive(data.serializedUser);
onSuccess(scope, data.resolveStatus);
}
}, onFailure, NATIVE_BRIDGE_NAME, "addGooglePlayUserIdentity", [token]);
}
CurrentUser.prototype.addUserIdentity = function(userId, token, onSuccess, onConflict, onFailure) {
var scope = this;
cordova.exec(function(data) {
if(data.isConflict) {
onConflict();
} else {
scope.onSerializeDataReceive(data.serializedUser);
onSuccess(scope, data.resolveStatus);
}
}, onFailure, NATIVE_BRIDGE_NAME, "addUserIdentity", [userId, token]);
}
CurrentUser.prototype.removeFbUserIdentity = function(onSuccess, onFailure) {
var scope = this;
cordova.exec(function(serializedUser) {
scope.onSerializeDataReceive(serializedUser);
onSuccess(scope);
}, onFailure, NATIVE_BRIDGE_NAME, "removeFbUserIdentity", []);
}
CurrentUser.prototype.removeGooglePlusUserIdentity = function(onSuccess, onFailure) {
var scope = this;
cordova.exec(function(serializedUser) {
scope.onSerializeDataReceive(serializedUser);
onSuccess(scope);
}, onFailure, NATIVE_BRIDGE_NAME, "removeGooglePlusUserIdentity", []);
}
CurrentUser.prototype.removeGooglePlayUserIdentity = function(onSuccess, onFailure) {
var scope = this;
cordova.exec(function(serializedUser) {
scope.onSerializeDataReceive(serializedUser);
onSuccess(scope);
}, onFailure, NATIVE_BRIDGE_NAME, "removeGooglePlayUserIdentity", []);
}
CurrentUser.prototype.removeUserIdentity = function(providerId, onSuccess, onFailure) {
var scope = this;
cordova.exec(function(serializedUser) {
scope.onSerializeDataReceive(serializedUser);
onSuccess(scope);
}, onFailure, NATIVE_BRIDGE_NAME, "removeUserIdentity", [providerId]);
}
CurrentUser.prototype.reset = function(onSuccess, onFailure) {
var scope = this;
cordova.exec(function(serializedUser) {
scope.onSerializeDataReceive(serializedUser);
onSuccess(scope);
}, onFailure, NATIVE_BRIDGE_NAME, "reset", []);
}
CurrentUser.prototype.__proto__ = User.prototype;
CurrentUser.prototype.constructor = CurrentUser;
module.exports = CurrentUser;