Bug 1109511: listen for the 'delete' event to update the toolbar icon when a room is deleted. r=Niko
authorMike de Boer <mdeboer@mozilla.com>
Fri, 12 Dec 2014 16:39:17 +0100
changeset 219495 e4e65a1c0dd6ae9298cb0a72464ce584cfc09845
parent 219494 63205db3303e08cb13b1058a28a02339fa6d3b49
child 219496 4cdd32ea6f7daa37948020e468038a2242d94e6e
push idunknown
push userunknown
push dateunknown
reviewersNiko
bugs1109511
milestone37.0a1
Bug 1109511: listen for the 'delete' event to update the toolbar icon when a room is deleted. r=Niko
browser/components/loop/LoopRooms.jsm
browser/components/loop/MozLoopService.jsm
--- a/browser/components/loop/LoopRooms.jsm
+++ b/browser/components/loop/LoopRooms.jsm
@@ -130,17 +130,17 @@ let LoopRoomsInternal = {
 
   /**
    * @var {Number} participantsCount The total amount of participants currently
    *                                 inside all rooms.
    */
   get participantsCount() {
     let count = 0;
     for (let room of this.rooms.values()) {
-      if (!("participants" in room)) {
+      if (room.deleted || !("participants" in room)) {
         continue;
       }
       count += room.participants.length;
     }
     return count;
   },
 
   /**
--- a/browser/components/loop/MozLoopService.jsm
+++ b/browser/components/loop/MozLoopService.jsm
@@ -1068,21 +1068,23 @@ this.MozLoopService = {
       gFxAEnabled = Services.prefs.getBoolPref("loop.fxa.enabled");
       if (!gFxAEnabled) {
         yield this.logOutFromFxA();
       }
     }
 
     // The Loop toolbar button should change icon when the room participant count
     // changes from 0 to something.
-    const onRoomsChange = () => {
-      MozLoopServiceInternal.notifyStatusChanged();
+    const onRoomsChange = (e) => {
+      // Pass the event name as notification reason for better logging.
+      MozLoopServiceInternal.notifyStatusChanged("room-" + e);
     };
     LoopRooms.on("add", onRoomsChange);
     LoopRooms.on("update", onRoomsChange);
+    LoopRooms.on("delete", onRoomsChange);
     LoopRooms.on("joined", (e, room, participant) => {
       // Don't alert if we're in the doNotDisturb mode, or the participant
       // is the owner - the content code deals with the rest of the sounds.
       if (MozLoopServiceInternal.doNotDisturb || participant.owner) {
         return;
       }
 
       let window = gWM.getMostRecentWindow("navigator:browser");