1
0
mirror of https://github.com/moparisthebest/FireTray synced 2024-08-13 15:53:47 -04:00

* observe "account-added", "account-removed", at last ! (see 75636723 and 8d0917ab)

* auto-start InstantMessaging when needed
This commit is contained in:
foudfou 2012-08-04 14:02:42 +02:00
parent ee86eeed16
commit b3869630c2
2 changed files with 38 additions and 11 deletions

View File

@ -19,7 +19,8 @@ firetray.InstantMessaging = {
}
F.LOG("Enabling InstantMessaging");
firetray.Utils.addObservers(firetray.InstantMessaging, [ // "*" for debugging
firetray.Utils.addObservers(firetray.InstantMessaging, [
// "*" // debugging
"idle-time-changed", "new-directed-incoming-message", "new-text",
"new-ui-conversation", "status-changed", "unread-im-count-changed",
"visited-status-resolution"
@ -38,16 +39,13 @@ firetray.InstantMessaging = {
},
observe: function(subject, topic, data) {
F.WARN("RECEIVED InstantMessaging:");
F.LOG("RECEIVED InstantMessaging: "+topic+" subject="+subject+" data="+data);
switch (topic) {
case "unread-im-count-changed":
F.WARN("received unread-im-count-changed: "+subject+" "+data);
break;
case "new-directed-incoming-message": // when PM or cited in channel: new-directed-incoming-message: [xpconnect wrapped (nsISupports, nsIClassInfo, prplIMessage)] null
F.WARN("new-directed-incoming-message: "+subject+" "+data);
break;
case "visited-status-resolution":
F.WARN("visited-status-resolution: "+subject+" "+data);
break;
case "status-changed":
case "idle-time-changed":

View File

@ -27,6 +27,7 @@ firetray.Messaging = {
initialized: false,
cleaningTimer: null,
currentMsgCount: null,
observedTopics: {},
init: function() {
if (this.initialized) {
@ -35,16 +36,14 @@ firetray.Messaging = {
}
F.LOG("Enabling Messaging");
// there is no means to detect account-removed event
this.cleaningTimer = firetray.Utils.timer(firetray.Messaging.cleanExcludedAccounts,
FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS, Ci.nsITimer.TYPE_REPEATING_SLACK);
F.LOG(this.cleaningTimer+"="+FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS);
firetray.Utils.addObservers(firetray.Messaging, [ "account-added",
"account-removed"]);
let that = this;
MailServices.mailSession.AddFolderListener(that.mailSessionListener,
that.mailSessionListener.notificationFlags);
if (Services.prefs.getBoolPref("mail.chat.enabled"))
if (Services.prefs.getBoolPref("mail.chat.enabled") && this.existsIMAccount())
firetray.InstantMessaging.init();
this.initialized = true;
@ -54,14 +53,44 @@ firetray.Messaging = {
if (!this.initialized) return;
F.LOG("Disabling Messaging");
firetray.InstantMessaging.shutdown();
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
firetray.Handler.setIconImageDefault();
this.cleaningTimer.cancel();
Services.obs.removeAllObservers(firetray.Messaging);
this.initialized = false;
},
existsIMAccount: function() {
let accounts = new this.Accounts();
for (let accountServer in accounts)
if (accountServer.type === 'im') {
F.LOG("found im server: "+accountServer.prettyName);
return true;
}
return false;
},
observe: function(subject, topic, data) {
F.LOG("RECEIVED Messaging: "+topic+" subject="+subject+" data="+data);
switch (topic) {
case "account-removed":
this.cleanExcludedAccounts();
if (subject.QueryInterface(Ci.imIAccount) && !this.existsIMAccount())
firetray.InstantMessaging.shutdown();
break;
case "account-added":
if (subject.QueryInterface(Ci.imIAccount) && !firetray.InstantMessaging.initialized)
firetray.InstantMessaging.init();
break;
default:
F.WARN("unhandled topic: "+topic);
}
},
/* removes removed accounts from excludedAccounts pref. NOTE: Can't be called
at shutdown because MailServices.accounts no longer available */
cleanExcludedAccounts: function() {