|
|
|
@ -85,6 +85,12 @@ var _parseAddress = (address) => {
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function isPrivate (rating) {
|
|
|
|
|
// starting from `PEP_rating_reliable` in
|
|
|
|
|
// `_PEP_rating` in the engine `message_api.h`
|
|
|
|
|
return rating && rating > 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pEpComposer = {
|
|
|
|
|
|
|
|
|
|
init: function (window) {
|
|
|
|
@ -93,7 +99,7 @@ var pEpComposer = {
|
|
|
|
|
this.window = window;
|
|
|
|
|
const compat = compatFactory(this.window);
|
|
|
|
|
this.prefs = prefsFactory(compat);
|
|
|
|
|
this.initPrivacyWarning();
|
|
|
|
|
this.originalRatingPromise = this.getOriginalRating();
|
|
|
|
|
// we do not wait for the promises above to be
|
|
|
|
|
// resolved. pEpComposer init is run when the compose window
|
|
|
|
|
// is open and privacy will be checked when the message is
|
|
|
|
@ -103,7 +109,7 @@ var pEpComposer = {
|
|
|
|
|
TbAbstraction.getCurrentIdentity().setBoolAttribute("protectionDisabled", false);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initPrivacyWarning() {
|
|
|
|
|
getOriginalRating() {
|
|
|
|
|
let id = this.window.arguments[0].originalMsgURI;
|
|
|
|
|
if (id === '') {
|
|
|
|
|
// these windows have no original, users are starting a
|
|
|
|
@ -120,8 +126,7 @@ var pEpComposer = {
|
|
|
|
|
message.to,
|
|
|
|
|
message.cc,
|
|
|
|
|
message.bcc)
|
|
|
|
|
})
|
|
|
|
|
.then((rating) => this.originalRating = rating );
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -146,22 +151,34 @@ var pEpComposer = {
|
|
|
|
|
let cc = (msgCompFields.cc) ? _parseAddress(msgCompFields.cc) : undefined;
|
|
|
|
|
let bcc = (msgCompFields.bcc) ? _parseAddress(msgCompFields.bcc) : undefined;
|
|
|
|
|
|
|
|
|
|
pEpController.getOngoingRating(from, to, cc, bcc).then((rating) => {
|
|
|
|
|
let protectionDisabled = TbAbstraction.getCurrentIdentity().getBoolAttribute("protectionDisabled");
|
|
|
|
|
|
|
|
|
|
pEpController.getOngoingRating(from, to, cc, bcc).then((rating) => {
|
|
|
|
|
console.log("ONGOING RATING: ", rating);
|
|
|
|
|
if (typeof rating === "undefined") rating = -2;
|
|
|
|
|
|
|
|
|
|
updateMsgIdentity(rating);
|
|
|
|
|
pEpController.getPrivacyColorFromRating(rating).then((color) => {
|
|
|
|
|
createPrivacyNode(color, protectionDisabled);
|
|
|
|
|
});
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
pEpController.getPrivacyColorFromRating(-2).then((color) => {
|
|
|
|
|
createPrivacyNode(color);
|
|
|
|
|
this.originalRatingPromise
|
|
|
|
|
.then((originalRating) => {
|
|
|
|
|
if (helper.encryptForAccount(gCurrentIdentity, isPrivate(originalRating))) {
|
|
|
|
|
return pEpController.getOngoingRating(from, to, cc, bcc);
|
|
|
|
|
} else {
|
|
|
|
|
if (!protectionDisabled) {
|
|
|
|
|
this.toggleDisableProtectionButtonAction()
|
|
|
|
|
protectionDisabled = !protectionDisabled;
|
|
|
|
|
}
|
|
|
|
|
return Promise.resolve(-2);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then((rating) => {
|
|
|
|
|
console.log("ONGOING RATING: ", rating);
|
|
|
|
|
if (typeof rating === "undefined") rating = -2;
|
|
|
|
|
|
|
|
|
|
updateMsgIdentity(rating);
|
|
|
|
|
pEpController.getPrivacyColorFromRating(rating).then((color) => {
|
|
|
|
|
createPrivacyNode(color, protectionDisabled);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
pEpController.getPrivacyColorFromRating(-2).then((color) => {
|
|
|
|
|
createPrivacyNode(color);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initListener: function (event) {
|
|
|
|
@ -235,12 +252,7 @@ var pEpComposer = {
|
|
|
|
|
|
|
|
|
|
privacyLoss() {
|
|
|
|
|
let rating = getCurrentIdentity().getIntAttribute("pEpRating");
|
|
|
|
|
return private(this.originalRating) && !private(rating);
|
|
|
|
|
function private (rating) {
|
|
|
|
|
// starting from `PEP_rating_reliable` in
|
|
|
|
|
// `_PEP_rating` in the engine `message_api.h`
|
|
|
|
|
return rating > 5;
|
|
|
|
|
}
|
|
|
|
|
return isPrivate(this.originalRating) && !isPrivate(rating);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
pEp_onRecipientsChanged: function () {
|
|
|
|
@ -276,8 +288,6 @@ var pEpComposer = {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
toggleDisableProtectionButtonAction: function() {
|
|
|
|
|
//Placeholder
|
|
|
|
|
//TODO To be implemented
|
|
|
|
|
|
|
|
|
|
let previousValue = TbAbstraction.getCurrentIdentity().getBoolAttribute("protectionDisabled");
|
|
|
|
|
TbAbstraction.getCurrentIdentity().setBoolAttribute("protectionDisabled", !previousValue);
|
|
|
|
|