From b8b60b0cad8802dadb40b7c685daa091e05b65fb Mon Sep 17 00:00:00 2001 From: Abdelrhman Ahmed Date: Tue, 11 Aug 2015 17:05:00 +0200 Subject: [PATCH] Bug 1172355 - Add system messages when someone joins or leaves an XMPP MUC. r=aleth --- chat/locales/en-US/xmpp.properties | 14 +++++++++++ chat/protocols/xmpp/xmpp.jsm | 38 +++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/chat/locales/en-US/xmpp.properties b/chat/locales/en-US/xmpp.properties index 6f676cfc31..665ee8b229 100644 --- a/chat/locales/en-US/xmpp.properties +++ b/chat/locales/en-US/xmpp.properties @@ -108,11 +108,25 @@ chatRoomField.password=_Password conversation.muc.invitationWithReason=%1$S has invited you to join %2$S: %3$S conversation.muc.invitationWithoutReason=%1$S has invited you to join %2$S +# LOCALIZATION NOTE (conversation.muc.join): +# This is displayed as a system message when a participant joins room. +# %S is the nick of the participant. +conversation.message.join=%S entered the room. + +# LOCALIZATION NOTE (conversation.muc.rejoined): +# This is displayed as a system message when a participant rejoins room after +# parting it. +conversation.message.rejoined=You have rejoined the room. + # LOCALIZATION NOTE (conversation.message.parted.*): # These are displayed as a system message when a participant parts a room. # %S is the part message supplied by the user. conversation.message.parted.you=You have left the room. conversation.message.parted.you.reason=You have left the room: %S +# %1$S is the participant that is leaving. +# %2$S is the part message supplied by the participant. +conversation.message.parted=%1$S has left the room. +conversation.message.parted.reason=%1$S has left the room: %2$S # LOCALIZATION NOTE (conversation.message.banned.*): # These are displayed as a system message when a participant is banned from diff --git a/chat/protocols/xmpp/xmpp.jsm b/chat/protocols/xmpp/xmpp.jsm index 53ac86d0d2..4ff9864fbe 100644 --- a/chat/protocols/xmpp/xmpp.jsm +++ b/chat/protocols/xmpp/xmpp.jsm @@ -165,6 +165,9 @@ const XMPPMUCConversationPrototype = { _targetResource: "", + // True while we are rejoining a room previously parted by the user. + _rejoined: false, + get topic() this._topic, set topic(aTopic) { let notAuthorized = (aError) => { @@ -284,17 +287,7 @@ const XMPPMUCConversationPrototype = { this.left = true; let message; - if (codes.indexOf("110") != -1) { - // XEP-0045 7.14: Self-presence. - // Received when the user parts a room. - message = "conversation.message.parted"; - - // The reason is in a status element in this case. - reasonNode = aStanza.getElement(["status"]); - reason = reasonNode ? reasonNode.innerText : ""; - isReason = reason ? ".reason" : ""; - } - else if (codes.indexOf("301") != -1) { + if (codes.indexOf("301") != -1) { // XEP-0045 (9.1): Banning a User. message = "conversation.message.banned"; } @@ -316,6 +309,16 @@ const XMPPMUCConversationPrototype = { // The reason here just duplicates what's in the system message. reason = isReason = ""; } + else { + // XEP-0045 (7.14): Received when the user parts a room. + message = "conversation.message.parted"; + + // The reason is in a status element in this case. + reasonNode = aStanza.getElement(["status"]); + reason = reasonNode ? reasonNode.innerText : ""; + isReason = reason ? ".reason" : ""; + } + if (message) { let messageID = message + isYou + isActor + isReason; let params = [actorNick, affectedNick, reason].filter(s => s); @@ -360,6 +363,15 @@ const XMPPMUCConversationPrototype = { this._participants.set(nick, participant); this.notifyObservers(new nsSimpleEnumerator([participant]), "chat-buddy-add"); + if (this.nick != nick && !this.joining) { + this.writeMessage(this.name, _("conversation.message.join", nick), + {system: true}); + } + else if (this.nick == nick && this._rejoined) { + this.writeMessage(this.name, _("conversation.message.rejoined"), + {system: true}); + this._rejoined = false; + } } else { this._participants.get(nick).onPresenceStanza(aStanza); @@ -1020,6 +1032,10 @@ const XMPPAccountPrototype = { if (muc) { if (!muc.left) return muc; // We are already in this conversation. + else if (!muc.chatRoomFields) { + // We are rejoining a room that was parted by the user. + muc._rejoined = true; + } } else { muc = new this._MUCConversationConstructor(this, jid, nick);