Bug 1011226 - Implement setting the topic in XMPP MUCs. r=aleth
This commit is contained in:
Родитель
52b5869f05
Коммит
ecc5d4a37d
|
@ -54,6 +54,7 @@ conversation.error.creationFailedNotAllowed=Access restricted: You are not allow
|
||||||
# is not found.
|
# is not found.
|
||||||
# %S is the name of MUC room.
|
# %S is the name of MUC room.
|
||||||
conversation.error.joinFailedRemoteServerNotFound=Could not join the room %S as the server the room is hosted on could not be reached.
|
conversation.error.joinFailedRemoteServerNotFound=Could not join the room %S as the server the room is hosted on could not be reached.
|
||||||
|
conversation.error.changeTopicFailedNotAuthorized=You are not authorized to set the topic of this room.
|
||||||
# This is displayed in a conversation as an error message when the user sends
|
# This is displayed in a conversation as an error message when the user sends
|
||||||
# a message to a room that he is not in.
|
# a message to a room that he is not in.
|
||||||
# %1$S is the name of MUC room.
|
# %1$S is the name of MUC room.
|
||||||
|
@ -127,3 +128,4 @@ odnoklassniki.usernameHint=Profile ID
|
||||||
# These are the help messages for each command.
|
# These are the help messages for each command.
|
||||||
command.join=join [<room@server>][/<nick>] [<password>]: Join a room, optionally providing a different nickname, or the room password.
|
command.join=join [<room@server>][/<nick>] [<password>]: Join a room, optionally providing a different nickname, or the room password.
|
||||||
command.part=part [<message>]: Leave the current room with an optional message.
|
command.part=part [<message>]: Leave the current room with an optional message.
|
||||||
|
command.topic=%S [<new topic>]: Set this room's topic.
|
||||||
|
|
|
@ -62,5 +62,16 @@ var commands = [
|
||||||
conv.part(aMsg);
|
conv.part(aMsg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "topic",
|
||||||
|
get helpString() _("command.topic", "topic"),
|
||||||
|
usageContext: Ci.imICommand.CMD_CONTEXT_CHAT,
|
||||||
|
run: function(aMsg, aConv) {
|
||||||
|
let conv = getConv(aConv);
|
||||||
|
if (!conv.left)
|
||||||
|
conv.topic = aMsg;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -106,6 +106,25 @@ const XMPPMUCConversationPrototype = {
|
||||||
|
|
||||||
_targetResource: "",
|
_targetResource: "",
|
||||||
|
|
||||||
|
get topic() this._topic,
|
||||||
|
set topic(aTopic) {
|
||||||
|
let notAuthorized = (aError) => {
|
||||||
|
// XEP-0045 (8.1): Unauthorized subject change.
|
||||||
|
let message = _("conversation.error.changeTopicFailedNotAuthorized");
|
||||||
|
this.writeMessage(this.name, message, {system: true, error: true});
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
let errorHandler = this._account.handleErrors({forbidden: notAuthorized,
|
||||||
|
notAcceptable: notAuthorized,
|
||||||
|
itemNotFound: notAuthorized});
|
||||||
|
|
||||||
|
// XEP-0045 (8.1): Modifying the room subject.
|
||||||
|
let subject = Stanza.node("subject", null, null, aTopic.trim());
|
||||||
|
let s = Stanza.message(this.name, null, null,{type: "groupchat"}, subject);
|
||||||
|
this._account.sendStanza(s, errorHandler);
|
||||||
|
},
|
||||||
|
get topicSettable() true,
|
||||||
|
|
||||||
/* Called when the user enters a chat message */
|
/* Called when the user enters a chat message */
|
||||||
sendMsg: function (aMsg) {
|
sendMsg: function (aMsg) {
|
||||||
let notInRoom = (aError) => {
|
let notInRoom = (aError) => {
|
||||||
|
@ -228,6 +247,8 @@ const XMPPMUCConversationPrototype = {
|
||||||
// XEP-0045: Room exists and joined successfully.
|
// XEP-0045: Room exists and joined successfully.
|
||||||
this.left = false;
|
this.left = false;
|
||||||
this.joining = false;
|
this.joining = false;
|
||||||
|
// TODO (Bug 1172350): Implement Service Discovery Extensions (XEP-0128) to obtain
|
||||||
|
// configuration of this room.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this._participants.get(nick)) {
|
if (!this._participants.get(nick)) {
|
||||||
|
@ -1218,7 +1239,8 @@ const XMPPAccountPrototype = {
|
||||||
|
|
||||||
/* Called when a message stanza is received */
|
/* Called when a message stanza is received */
|
||||||
onMessageStanza: function(aStanza) {
|
onMessageStanza: function(aStanza) {
|
||||||
let norm = this.normalize(aStanza.attributes["from"]);
|
let from = aStanza.attributes["from"];
|
||||||
|
let norm = this.normalize(from);
|
||||||
|
|
||||||
let type = aStanza.attributes["type"];
|
let type = aStanza.attributes["type"];
|
||||||
let body;
|
let body;
|
||||||
|
@ -1236,6 +1258,22 @@ const XMPPAccountPrototype = {
|
||||||
body = TXTToHTML(b.innerText);
|
body = TXTToHTML(b.innerText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let subject = aStanza.getElement(["subject"]);
|
||||||
|
if (subject) {
|
||||||
|
// XEP-0045 (7.2.16): Check for a subject element in the stanza and update
|
||||||
|
// the topic if it exists.
|
||||||
|
// We are breaking the spec because only a message that contains a
|
||||||
|
// <subject/> but no <body/> element shall be considered a subject change
|
||||||
|
// for MUC, but we ignore that to be compatible with ejabberd versions
|
||||||
|
// before 15.06.
|
||||||
|
let muc = this._mucs.get(norm);
|
||||||
|
let nick = this._parseJID(from).resource;
|
||||||
|
// TODO There can be multiple subject elements with different xml:lang
|
||||||
|
// attributes.
|
||||||
|
muc.setTopic(subject.innerText, nick);
|
||||||
|
}
|
||||||
|
|
||||||
if (body) {
|
if (body) {
|
||||||
let date;
|
let date;
|
||||||
let delay = aStanza.getElement(["delay"]);
|
let delay = aStanza.getElement(["delay"]);
|
||||||
|
@ -1252,15 +1290,6 @@ const XMPPAccountPrototype = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let muc = this._mucs.get(norm);
|
let muc = this._mucs.get(norm);
|
||||||
|
|
||||||
// Check for a subject element in the stanza and update the topic if
|
|
||||||
// it exists.
|
|
||||||
let s = aStanza.getElement(["subject"]);
|
|
||||||
// TODO There can be multiple subject elements with different xml:lang
|
|
||||||
// attributes.
|
|
||||||
if (s)
|
|
||||||
muc.setTopic(s.innerText);
|
|
||||||
|
|
||||||
muc.incomingMessage(body, aStanza, date);
|
muc.incomingMessage(body, aStanza, date);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче