Skip to content

Commit

Permalink
listen to identity changes to rebuild address cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanto committed Jun 1, 2017
1 parent 9812757 commit cca4e03
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 11 deletions.
54 changes: 54 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": ["error", {"vars": "all", "args": "none"}],
"constructor-super": "warn",
"valid-typeof": "warn"
},
"globals": {
"atob": true,
"btoa": true,
"Components": true,
"CSSRule": true,
"clearInterval": true,
"clearTimeout": true,
"console": true,
"CSS": true,
"DocumentFragment": true,
"DOMParser": true,
"dump": true,
"Element": true,
"exports": true,
"gDBView": true,
"isWorker": true,
"indexedDB": true,
"loader": true,
"module": true,
"Node": true,
"reportError": true,
"require": true,
"setInterval": true,
"setTimeout": true,
"uneval": true,
"TextDecoder": true,
"TextEncoder": true,
"URL": true,
"WebSocket": true,
"XMLHttpRequest": true
}
}
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ Changelog
* v0.5 -- Bug fix release (#3: email address matching was case sensitive)
* v0.6 -- Bug fix release (#7: PLI shows wrong indicators in Thunderbird 24)
* v0.7 -- New Feature: Indicator style is now configurable. Besides the "Gmail style" there also the "triple style", which shows a single arrow (›) if a message is sent only to you, a double arrow (») if it is sent to a group and a triple arrow if it is sent to a mailing list.
* v0.8 -- More robustness, addon will now notice changes in indentities and does not require a restart anymore. Also the default settings are properly initialized when the plugin is installed.
35 changes: 24 additions & 11 deletions chrome/content/pli_column_overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var PLIOverlay = {
PLI_NOT_SET: 0,
PLI_ONLY: 1,
PLI_GROUP: 2,

init: function () {
this.initialized = true;

Expand All @@ -33,31 +33,44 @@ var PLIOverlay = {
// register observer
Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService).addObserver(this, "MsgCreateDBView", false);

// load preferences
// load addon preferences
this.prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("personallevelindicator.");
this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch);
this.prefs.addObserver("", this, false);
this.mode = this.prefs.getCharPref("mode");

// observe accounts
this.accountPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("mail.identity.");
this.accountPrefs.QueryInterface(Components.interfaces.nsIPrefBranch);
this.accountPrefs.addObserver("", this, false);

},

loadIdentities: function () {
// load and cache all identities from all accounts
this._identities = [];
let accounts = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager).accounts;
for (var i = 0; i < accounts.length; i++) {
var account = accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount);

for(var identCount = 0; identCount < account.identities.length; identCount++) {
var identity = account.identities.queryElementAt(identCount, Components.interfaces.nsIMsgIdentity);
this._identities.push(identity.email.toLowerCase());
}
let accounts = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager).accounts;
for (var i = 0; i < accounts.length; i++) {
var account = accounts.queryElementAt(i, Components.interfaces.nsIMsgAccount);

for(var identCount = 0; identCount < account.identities.length; identCount++) {
var identity = account.identities.queryElementAt(identCount, Components.interfaces.nsIMsgIdentity);
this._identities.push(identity.email.toLowerCase());
}
}
},

observe: function (subject, topic, data) {
if (topic == "nsPref:changed") {
this.mode = this.prefs.getCharPref("mode");
if (subject.root.match(/identity/)) {
// indentities changed -> reload
this.loadIdentities();
} else if (subject.root.match(/personallevelindicator/)) {
// settings changed
this.mode = this.prefs.getCharPref("mode");
}
} else {
// Mail view initialized -> register column handler
this.loadIdentities();
gDBView.addColumnHandler("PLICol", this);
}
Expand Down

0 comments on commit cca4e03

Please sign in to comment.