Bug 1138689 - /me and /action should fire a sending-message notification before actually sending the action. r=clokep

This commit is contained in:
Arlo Breault 2015-03-13 13:04:26 -07:00
Родитель c17ab6c596
Коммит 631a4702a1
4 изменённых файлов: 26 добавлений и 10 удалений

Просмотреть файл

@ -30,6 +30,7 @@ Anirvana Mishra <anidps@gmail.com>
Annie Sullivan <annie.sullivan@gmail.com>
Archaeopteryx <archaeopteryx@coole-files.de>
ArentJan Banck <ajbanck@planet.nl>
Arlo Breault <arlolra@gmail.com>
Arthur Wiebe <artooro@gmail.com>
Asaf Romano <mano@mozilla.com>
Atul Varma <atul@mozilla.com>

Просмотреть файл

@ -78,10 +78,12 @@ interface imIConversationsService: nsISupports {
// the conversation service notifies observers of `preparing-message` and
// `sending-message` (typically add-ons) of an outgoing message, which can be
// transformed or cancelled.
[scriptable, uuid(4391ba5c-9566-41a9-bb9b-fd0a0a490c2c)]
[scriptable, uuid(f88535b1-0b99-433b-a6de-c1a4bf8b43ea)]
interface imIOutgoingMessage: nsISupports {
attribute AUTF8String message;
attribute boolean cancelled;
// Outgoing message is an action command.
readonly attribute boolean action;
readonly attribute prplIConversation conversation;
};

Просмотреть файл

@ -21,7 +21,8 @@ function OutgoingMessage(aMsg, aConversation) {
}
OutgoingMessage.prototype = {
__proto__: ClassInfo("imIOutgoingMessage", "Outgoing Message"),
cancelled: false
cancelled: false,
action: false
};
function imMessage(aPrplMessage) {

Просмотреть файл

@ -20,6 +20,16 @@ function getAccount(aConv) getConv(aConv)._account;
// Trim leading and trailing spaces and split a string by any type of space.
function splitInput(aString) aString.trim().split(/\s+/);
function OutgoingMessage(aMsg, aConversation, aAction) {
this.message = aMsg;
this.conversation = aConversation;
this.action = !!aAction;
}
OutgoingMessage.prototype = {
__proto__: ClassInfo("imIOutgoingMessage", "Outgoing Message"),
cancelled: false
};
// Kick a user from a channel
// aMsg is <user> [comment]
function kickCommand(aMsg, aConv) {
@ -65,12 +75,7 @@ function messageCommand(aMsg, aConv, aReturnedConv, aIsNotice = false) {
return true;
// Give add-ons an opportunity to tweak or cancel the message.
let om = {
__proto__: ClassInfo("imIOutgoingMessage", "Outgoing Message"),
message: message,
conversation: conv,
cancelled: false
};
let om = new OutgoingMessage(message, conv);
conv.notifyObservers(om, "sending-message");
// If a NOTICE is cancelled and resent, it will end up being sent as PRIVMSG.
if (om.cancelled)
@ -96,15 +101,22 @@ function actionCommand(aMsg, aConv) {
return false;
let conv = getConv(aConv);
// Give add-ons an opportunity to tweak or cancel the action.
let om = new OutgoingMessage(aMsg, aConv, true);
conv.notifyObservers(om, "sending-message");
if (om.cancelled)
return true;
let account = getAccount(aConv);
if (!ctcpCommand(aConv, aConv.name, "ACTION", aMsg)) {
if (!ctcpCommand(aConv, aConv.name, "ACTION", om.message)) {
conv.writeMessage(account._currentServerName, _("error.sendMessageFailed"),
{error: true, system: true});
return true;
}
// Show the action on our conversation.
conv.writeMessage(account._nickname, "/me " + aMsg, {outgoing: true});
conv.writeMessage(account._nickname, "/me " + om.message, {outgoing: true});
return true;
}