mirror of
https://github.com/moparisthebest/FireTray
synced 2024-08-13 15:53:47 -04:00
* auto-start InstantMessaging when needed
This commit is contained in:
parent
ee86eeed16
commit
b3869630c2
@ -19,7 +19,8 @@ firetray.InstantMessaging = {
|
|||||||
}
|
}
|
||||||
F.LOG("Enabling 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",
|
"idle-time-changed", "new-directed-incoming-message", "new-text",
|
||||||
"new-ui-conversation", "status-changed", "unread-im-count-changed",
|
"new-ui-conversation", "status-changed", "unread-im-count-changed",
|
||||||
"visited-status-resolution"
|
"visited-status-resolution"
|
||||||
@ -38,16 +39,13 @@ firetray.InstantMessaging = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
observe: function(subject, topic, data) {
|
observe: function(subject, topic, data) {
|
||||||
F.WARN("RECEIVED InstantMessaging:");
|
F.LOG("RECEIVED InstantMessaging: "+topic+" subject="+subject+" data="+data);
|
||||||
switch (topic) {
|
switch (topic) {
|
||||||
case "unread-im-count-changed":
|
case "unread-im-count-changed":
|
||||||
F.WARN("received unread-im-count-changed: "+subject+" "+data);
|
|
||||||
break;
|
break;
|
||||||
case "new-directed-incoming-message": // when PM or cited in channel: new-directed-incoming-message: [xpconnect wrapped (nsISupports, nsIClassInfo, prplIMessage)] null
|
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;
|
break;
|
||||||
case "visited-status-resolution":
|
case "visited-status-resolution":
|
||||||
F.WARN("visited-status-resolution: "+subject+" "+data);
|
|
||||||
break;
|
break;
|
||||||
case "status-changed":
|
case "status-changed":
|
||||||
case "idle-time-changed":
|
case "idle-time-changed":
|
||||||
|
@ -27,6 +27,7 @@ firetray.Messaging = {
|
|||||||
initialized: false,
|
initialized: false,
|
||||||
cleaningTimer: null,
|
cleaningTimer: null,
|
||||||
currentMsgCount: null,
|
currentMsgCount: null,
|
||||||
|
observedTopics: {},
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
if (this.initialized) {
|
if (this.initialized) {
|
||||||
@ -35,16 +36,14 @@ firetray.Messaging = {
|
|||||||
}
|
}
|
||||||
F.LOG("Enabling Messaging");
|
F.LOG("Enabling Messaging");
|
||||||
|
|
||||||
// there is no means to detect account-removed event
|
firetray.Utils.addObservers(firetray.Messaging, [ "account-added",
|
||||||
this.cleaningTimer = firetray.Utils.timer(firetray.Messaging.cleanExcludedAccounts,
|
"account-removed"]);
|
||||||
FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS, Ci.nsITimer.TYPE_REPEATING_SLACK);
|
|
||||||
F.LOG(this.cleaningTimer+"="+FIRETRAY_DELAY_PREF_CLEANING_MILLISECONDS);
|
|
||||||
|
|
||||||
let that = this;
|
let that = this;
|
||||||
MailServices.mailSession.AddFolderListener(that.mailSessionListener,
|
MailServices.mailSession.AddFolderListener(that.mailSessionListener,
|
||||||
that.mailSessionListener.notificationFlags);
|
that.mailSessionListener.notificationFlags);
|
||||||
|
|
||||||
if (Services.prefs.getBoolPref("mail.chat.enabled"))
|
if (Services.prefs.getBoolPref("mail.chat.enabled") && this.existsIMAccount())
|
||||||
firetray.InstantMessaging.init();
|
firetray.InstantMessaging.init();
|
||||||
|
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
@ -54,14 +53,44 @@ firetray.Messaging = {
|
|||||||
if (!this.initialized) return;
|
if (!this.initialized) return;
|
||||||
F.LOG("Disabling Messaging");
|
F.LOG("Disabling Messaging");
|
||||||
|
|
||||||
|
firetray.InstantMessaging.shutdown();
|
||||||
|
|
||||||
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
|
MailServices.mailSession.RemoveFolderListener(this.mailSessionListener);
|
||||||
firetray.Handler.setIconImageDefault();
|
firetray.Handler.setIconImageDefault();
|
||||||
|
|
||||||
this.cleaningTimer.cancel();
|
Services.obs.removeAllObservers(firetray.Messaging);
|
||||||
|
|
||||||
this.initialized = false;
|
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
|
/* removes removed accounts from excludedAccounts pref. NOTE: Can't be called
|
||||||
at shutdown because MailServices.accounts no longer available */
|
at shutdown because MailServices.accounts no longer available */
|
||||||
cleanExcludedAccounts: function() {
|
cleanExcludedAccounts: function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user