Skip to content

Commit

Permalink
Version 0.3
Browse files Browse the repository at this point in the history
Updated to work with the latest version of Instantbird. Now uses the "preparing-message" observer notification API to replace links.
  • Loading branch information
nhnt11 authored and clokep committed Apr 15, 2016
1 parent 965659b commit 09d534c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
52 changes: 30 additions & 22 deletions bootstrap.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

Components.utils.import("resource:///modules/imServices.jsm");
Components.utils.import("resource:///modules/imWindows.jsm");

var originalAddConversationFunction;

function replaceLogLinks (aString) {
if (!aString.contains("log.bezut.info"))
return aString;
function replaceLogLinks(aOutgoingMessage) {
let text = aOutgoingMessage.message;
if (!text.contains("log.bezut.info"))
return;

let rewriteDate = function (match, ...params) {
// params[1] is the second parenthesized submatch string here.
Expand All @@ -26,29 +26,37 @@ function replaceLogLinks (aString) {
return params[0] + twoChar(date.getUTCFullYear()) +
twoChar(date.getUTCMonth() + 1) + twoChar(date.getUTCDate());
};
aString = aString.replace(/(log\.bezut\.info\/instantbird\/)(today|yesterday)/,
text = text.replace(/(log\.bezut\.info\/instantbird\/)(today|yesterday)/,
rewriteDate, "gi" /* global, case-insensitive */);
return aString;
aOutgoingMessage.message = text;
}

var replaceObserver = {
observe: function(aSubject, aTopic, aData) {
if (aTopic != "preparing-message")
return;
// aSubject is an imIOutgoingMessage.
replaceLogLinks(aSubject);
}
}

var convObserver = {
observe: function(aSubject, aTopic, aData) {
aSubject.addObserver(replaceObserver);
}
}

function startup (data, reason) {
let cs = Services.conversations.wrappedJSObject;
originalAddConversationFunction = cs.addConversation;
cs.addConversation = function (aPurpleConversation) {
let wrapper = {
__proto__: aPurpleConversation,
_conv: aPurpleConversation,
sendMsg: function(aMsg) {
this._conv.sendMsg(replaceLogLinks(aMsg));
}
};
originalAddConversationFunction.call(cs, wrapper);
};
Conversations._conversations.forEach(aConv =>
aConv.conv.addObserver(replaceObserver));
Services.obs.addObserver(convObserver, "new-ui-conversation", false);
}

function shutdown (data, reason) {
let cs = Services.conversations.wrappedJSObject;
cs.addConversation = originalAddConversationFunction;
Conversations._conversations.forEach(aConv =>
aConv.conv.removeObserver(replaceObserver));
Services.obs.removeObserver(convObserver, "new-ui-conversation");
}

function install (data, reason) {}
function uninstall (data, reason) {}
function uninstall (data, reason) {}
6 changes: 3 additions & 3 deletions install.rdf
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description about="urn:mozilla:install-manifest">

<em:id>[email protected]</em:id>
<em:version>0.2</em:version>
<em:version>0.3</em:version>
<em:name>Not today!</em:name>
<em:description>What do we say in logs? Not today! - replaces any reference to log.bezut.info/instantbird/(today|yesterday) with the correct date before sending the message</em:description>
<em:type>2</em:type>
Expand All @@ -17,8 +17,8 @@
<em:targetApplication>
<Description>
<em:id>{33cb9019-c295-46dd-be21-8c4936574bee}</em:id>
<em:minVersion>1.4a1pre</em:minVersion>
<em:maxVersion>1.4a1pre</em:maxVersion>
<em:minVersion>1.6a1pre</em:minVersion>
<em:maxVersion>1.6a1pre</em:maxVersion>
</Description>
</em:targetApplication>

Expand Down

0 comments on commit 09d534c

Please sign in to comment.