Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
add posibility to notify for messages from multi-user chats, small no…
Browse files Browse the repository at this point in the history
…tifications refactor
  • Loading branch information
forrest79 committed Mar 16, 2014
1 parent 29dad64 commit 5a422a8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/chrome/content/options.xul
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<preference id="tbchatnotificationPlaySound" name="extensions.tbchatnotification.playsound" type="bool" />
<preference id="tbchatnotificationSoundFile" name="extensions.tbchatnotification.soundfile" type="string" />
<preference id="tbchatnotificationFlashIcon" name="extensions.tbchatnotification.flashicon" type="bool" />
<preference id="tbchatnotificationMUCNotify" name="extensions.tbchatnotification.mucnotify" type="bool" />
</preferences>
<checkbox preference="tbchatnotificationShowBody" label="&showbody.label;" accesskey="&showbody.accesskey;" />
<checkbox preference="tbchatnotificationPlaySound" label="&playsound.label;" accesskey="&playsound.accesskey;" />
Expand All @@ -29,6 +30,7 @@
<button label="..." oncommand="tbchatnotification.options.getFile('SoundFile');" />
</hbox>
<checkbox preference="tbchatnotificationFlashIcon" label="&flashicon.label;" accesskey="&flashicon.accesskey;" />
<checkbox preference="tbchatnotificationMUCNotify" label="&mucnotify.label;" accesskey="&mucnotify.accesskey;" />
</prefpane>

</prefwindow>
43 changes: 33 additions & 10 deletions src/chrome/content/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ var TbChatNotifier = {

prefs : null,
observer : null,
observerTopics : {
newDirectedIncomingMessage : 'new-directed-incoming-message',
newText : 'new-text'
},
audio : null,

options : {
showbody : false,
playsound : false,
soundfile : '',
flashicon : false
flashicon : false,
mucnotify : false
},

/**
Expand All @@ -29,6 +34,7 @@ var TbChatNotifier = {
.getService(Ci.nsIPrefService)
.getBranch('extensions.tbchatnotification.');
prefs.QueryInterface(Ci.nsIPrefBranch);

var options = this.options;
options.observe = function(subject, topic, data) {
if (topic != 'nsPref:changed') {
Expand All @@ -48,14 +54,18 @@ var TbChatNotifier = {
case 'flashicon' :
this.flashicon = prefs.getBoolPref('flashicon');
break;
case 'mucnotify' :
this.mucnotify = prefs.getBoolPref('mucnotify');
break;
}
}
prefs.addObserver('', options, false);

options.showbody = prefs.getBoolPref('showbody');
options.playsound = prefs.getBoolPref('playsound');
options.soundfile = prefs.getCharPref('soundfile');
options.flashicon = prefs.getBoolPref('flashicon');
options.mucnotify = prefs.getBoolPref('mucnotify');

// Audio
this.audio = new Audio();
Expand All @@ -64,29 +74,41 @@ var TbChatNotifier = {
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.jsm');

var OBSERVER_TOPIC = 'new-directed-incoming-message';
var imServices = {};
Cu.import("resource:///modules/imServices.jsm", imServices);
imServices = imServices.Services;

var observerTopics = this.observerTopics;

var notifier = this;
var observer = this.observer = {
observe: function(subject, topic, data) {
if (topic == OBSERVER_TOPIC) {
if (subject.incoming && (((topic == observerTopics.newDirectedIncomingMessage) && !options.mucnotify) || ((topic == observerTopics.newText) && options.mucnotify))) {
notifier.play();
notifier.notify(subject.alias, subject.originalMessage);
notifier.notify(subject.alias, subject.originalMessage, imServices.conversations.getUIConversation(subject.conversation).title);
}
},

QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver, Ci.nsISupportsWeakReference])
};

Services.obs.addObserver(observer, OBSERVER_TOPIC, true);
for (var topic in observerTopics) {
Services.obs.addObserver(observer, observerTopics[topic], true);
}
},

/**
* Unload chat notifier.
*/
unload : function() {
this.prefs.addObserver('', this.options);
Services.obs.removeObserver(this.observer, OBSERVER_TOPIC);
this.prefs.removeObserver('', this.options);

var observer = this.observer,
observerTopics = this.observerTopics;

for (var topic in observerTopics) {
Services.obs.removeObserver(observer, observerTopics[topic]);
}
},

/**
Expand All @@ -106,8 +128,9 @@ var TbChatNotifier = {
* Show non-modal alert message.
* @param from string
* @param message string
* @param conversation string
*/
notify : function(from, message) {
notify : function(from, message, conversation) {
var options = this.options;

try {
Expand Down Expand Up @@ -148,7 +171,7 @@ var TbChatNotifier = {

Cc['@mozilla.org/alerts-service;1']
.getService(Ci.nsIAlertsService)
.showAlertNotification('chrome://TbChatNotification/skin/icon32.png', title, text, true, from, listener);
.showAlertNotification('chrome://TbChatNotification/skin/icon32.png', title, text, true, conversation, listener);

if (options.flashicon) {
window.getAttention();
Expand Down
2 changes: 2 additions & 0 deletions src/chrome/locale/cs-CZ/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
<!ENTITY soundfile.label "Vlastní zvuk">
<!ENTITY flashicon.label "Rozblikat ikonu Thunderbirdu">
<!ENTITY flashicon.accesskey "B">
<!ENTITY mucnotify.label "Zobrazovat upozornění z více-uživatelských chatů">
<!ENTITY mucnotify.accesskey "V">
2 changes: 2 additions & 0 deletions src/chrome/locale/en-EN/options.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
<!ENTITY soundfile.label "Custom sound">
<!ENTITY flashicon.label "Flash Thunderbird icon">
<!ENTITY flashicon.accesskey "F">
<!ENTITY mucnotify.label "Show notifications from multi-user chats">
<!ENTITY mucnotify.accesskey "M">
1 change: 1 addition & 0 deletions src/defaults/preferences/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pref('extensions.tbchatnotification.showbody', false);
pref('extensions.tbchatnotification.playsound', false);
pref('extensions.tbchatnotification.soundfile', '');
pref('extensions.tbchatnotification.flashicon', false);
pref('extensions.tbchatnotification.mucnotify', false);
2 changes: 1 addition & 1 deletion src/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<em:id>[email protected]</em:id>
<em:type>2</em:type>
<em:version>1.0.1</em:version>
<em:version>1.1.0</em:version>
<em:name>Thunderbird Chat Notification</em:name>
<em:iconURL>chrome://TbChatNotification/skin/icon32.png</em:iconURL>
<em:optionsURL>chrome://TbChatNotification/content/options.xul</em:optionsURL>
Expand Down

0 comments on commit 5a422a8

Please sign in to comment.