Bug 1012666 - Fix up checking if IRC topics are settable. r=aleth
authorPatrick Cloke <clokep@gmail.com>
Tue, 27 May 2014 15:46:59 -0400
changeset 16266 a9c18429042c
parent 16265 8b21e2011df4
child 16267 74c3004f6627
push id10164
push userclokep@gmail.com
push dateTue, 27 May 2014 19:47:25 +0000
treeherdercomm-central@a9c18429042c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth
bugs1012666
Bug 1012666 - Fix up checking if IRC topics are settable. r=aleth
chat/protocols/irc/irc.js
chat/protocols/irc/ircBase.jsm
--- a/chat/protocols/irc/irc.js
+++ b/chat/protocols/irc/irc.js
@@ -387,16 +387,19 @@ ircChannel.prototype = {
       stringNicknames.push(stringNickname);
     });
     this.notifyObservers(new nsSimpleEnumerator(stringNicknames),
                          "chat-buddy-remove");
     this._participants.clear();
   },
 
   setMode: function(aNewMode, aModeParams, aSetter) {
+    // Save this for a comparison after the new modes have been set.
+    let previousTopicSettable = this.topicSettable;
+
     const hostMaskExp = /^.+!.+@.+$/;
     function getNextParam() {
       // If there's no next parameter, throw a warning.
       if (!aModeParams.length) {
         this.WARN("Mode parameter expected!");
         return undefined;
       }
       return aModeParams.pop();
@@ -502,17 +505,21 @@ ircChannel.prototype = {
 
     // Store the channel modes.
     _setMode.call(this, addNewMode, channelModes);
 
     // Notify the UI of changes.
     msg = _("message.channelmode", aNewMode[0] + channelModes.join(""),
             aSetter);
     this.writeMessage(aSetter, msg, {system: true});
-    this.checkTopicSettable();
+
+    // If the topic can now be set (and it couldn't previously) or vice versa,
+    // notify the UI.
+    if (this.topicSettable != previousTopicSettable)
+      this.notifyObservers(this, "chat-update-topic");
 
     this._receivedInitialMode = true;
   },
 
   setModesFromRestriction: function(aRestriction) {
     // First remove all types from the list of modes.
     for each (let mode in this._account.channelRestrictionToModeMap)
       this._modes.delete(mode);
@@ -522,29 +529,23 @@ ircChannel.prototype = {
       let mode = this._account.channelRestrictionToModeMap[aRestriction];
       if (mode)
         this._modes.add(mode);
     }
   },
 
   get topic() this._topic, // can't add a setter without redefining the getter
   set topic(aTopic) {
+    // Note that the UI isn't updated here because the server will echo back the
+    // TOPIC to us and we'll set it on receive.
     this._account.sendMessage("TOPIC", [this.name, aTopic]);
   },
-  _previousTopicSettable: null,
-  checkTopicSettable: function() {
-    if (this.topicSettable == this._previousTopicSettable &&
-        this._previousTopicSettable != null)
-      return;
-
-    this.notifyObservers(this, "chat-update-topic");
-  },
   get topicSettable() {
-    // If we're not in the room yet, we don't exist.
-    if (!this._participants.has(this.nick))
+    // We must be in the room to set the topic.
+    if (!this.left)
       return false;
 
     // If the channel mode is +t, hops and ops can set the topic; otherwise
     // everyone can.
     let participant = this.getParticipant(this.nick);
     return !this._modes.has("t") || participant.op || participant.halfOp;
   }
 };
@@ -572,21 +573,16 @@ ircParticipant.prototype = {
   setMode: function(aAddNewMode, aNewModes, aSetter) {
     _setMode.call(this, aAddNewMode, aNewModes);
 
     // Notify the UI of changes.
     let msg = _("message.usermode", (aAddNewMode ? "+" : "-") + aNewModes.join(""),
                 this.name, aSetter);
     this._conv.writeMessage(aSetter, msg, {system: true});
     this._conv.notifyObservers(this, "chat-buddy-update");
-
-    // In case the new mode now lets us edit the topic.
-    if (this._account.normalize(this.name) ==
-        this._account.normalize(this._account._nickname))
-      this._conv.checkTopicSettable();
   },
 
   get voiced() this._modes.has("v"),
   get halfOp() this._modes.has("h"),
   get op() this._modes.has("o"),
   get founder() this._modes.has("O") || this._modes.has("q"),
   get typing() false
 };
--- a/chat/protocols/irc/ircBase.jsm
+++ b/chat/protocols/irc/ircBase.jsm
@@ -927,18 +927,16 @@ var ircBase = {
      */
     "366": function(aMessage) { // RPL_ENDOFNAMES
       // <target> <channel> :End of NAMES list
       // All participants have already been added by the 353 handler.
 
       // This assumes that this is the last message received when joining a
       // channel, so a few "clean up" tasks are done here.
       let conversation = this.getConversation(aMessage.params[1]);
-      // Update whether the topic is editable.
-      conversation.checkTopicSettable();
 
       // If we haven't received the MODE yet, request it.
       if (!conversation._receivedInitialMode)
         this.sendMessage("MODE", aMessage.params[1]);
 
       return true;
     },
     /*