Fix for getIdentityService - Issue 227

This commit is contained in:
baku 2017-02-21 22:49:10 +01:00
parent 2dbddca36a
commit be7baa5430

View file

@ -112,7 +112,7 @@ const ContainerService = {
// need to implement a migration in the future. // need to implement a migration in the future.
if (installation) { if (installation) {
let preInstalledIdentities = []; // eslint-disable-line prefer-const let preInstalledIdentities = []; // eslint-disable-line prefer-const
ContextualIdentityService.getIdentities().forEach(identity => { ContextualIdentityProxy.getIdentities().forEach(identity => {
preInstalledIdentities.push(identity.userContextId); preInstalledIdentities.push(identity.userContextId);
}); });
@ -131,9 +131,9 @@ const ContainerService = {
// Maybe rename the Banking container. // Maybe rename the Banking container.
if (prefService.get("privacy.userContext.enabled") !== true) { if (prefService.get("privacy.userContext.enabled") !== true) {
const identity = ContextualIdentityService.getIdentityFromId(3); const identity = ContextualIdentityProxy.getIdentityFromId(3);
if (identity && identity.l10nID === "userContextBanking.label") { if (identity && identity.l10nID === "userContextBanking.label") {
ContextualIdentityService.update(identity.userContextId, ContextualIdentityProxy.update(identity.userContextId,
"Finance", "Finance",
identity.icon, identity.icon,
identity.color); identity.color);
@ -238,7 +238,7 @@ const ContainerService = {
}).sendEvent; }).sendEvent;
// Begin-Of-Hack // Begin-Of-Hack
function workaroundForCookieManager(method, userContextId) { ContextualIdentityService.workaroundForCookieManager = function(method, userContextId) {
let identity = method.call(ContextualIdentityService, userContextId); let identity = method.call(ContextualIdentityService, userContextId);
if (!identity && userContextId) { if (!identity && userContextId) {
identity = { identity = {
@ -253,15 +253,15 @@ const ContainerService = {
return identity; return identity;
} }
const oldGetIdentityFromId = ContextualIdentityService.getIdentityFromId; this._oldGetIdentityFromId = ContextualIdentityService.getIdentityFromId;
ContextualIdentityService.getIdentityFromId = function(userContextId) { ContextualIdentityService.getIdentityFromId = function(userContextId) {
return workaroundForCookieManager(oldGetIdentityFromId, userContextId); return this.workaroundForCookieManager(ContainerService._oldGetIdentityFromId, userContextId);
}; };
if ("getPublicIdentityFromId" in ContextualIdentityService) { if ("getPublicIdentityFromId" in ContextualIdentityService) {
const oldGetPublicIdentityFromId = ContextualIdentityService.getIdentityFromId; this._oldGetPublicIdentityFromId = ContextualIdentityService.getPublicIdentityFromId;
ContextualIdentityService.getIdentityFromId = function(userContextId) { ContextualIdentityService.getPublicIdentityFromId = function(userContextId) {
return workaroundForCookieManager(oldGetPublicIdentityFromId, userContextId); return this.workaroundForCookieManager(ContainerService._oldGetPublicIdentityFromId, userContextId);
}; };
} }
// End-Of-Hack // End-Of-Hack
@ -987,14 +987,24 @@ const ContainerService = {
this._forgetIdentity(); this._forgetIdentity();
const preInstalledIdentities = data.preInstalledIdentities; const preInstalledIdentities = data.preInstalledIdentities;
ContextualIdentityService.getIdentities().forEach(identity => { ContextualIdentityProxy.getIdentities().forEach(identity => {
if (!preInstalledIdentities.includes(identity.userContextId)) { if (!preInstalledIdentities.includes(identity.userContextId)) {
ContextualIdentityService.remove(identity.userContextId); ContextualIdentityProxy.remove(identity.userContextId);
} }
}); });
// Let's delete the configuration. // Let's delete the configuration.
delete ss.storage.savedConfiguration; delete ss.storage.savedConfiguration;
// Begin-Of-Hack
if (this._oldGetIdentityFromId) {
ContextualIdentityService.getIdentityFromId = this._oldGetIdentityFromId;
}
if (this._oldGetPublicIdentityFromId) {
ContextualIdentityService.getPublicIdentityFromId = this._oldGetPublicIdentityFromId;
}
// End-Of-Hack
}, },
_forgetIdentity(userContextId = 0) { _forgetIdentity(userContextId = 0) {