Bug 1074666 - Part 2 Change the toolbar icon when participants join and leave. Updated by pkerr,r=Standard8

This commit is contained in:
Mike de Boer 2014-11-17 13:28:58 +00:00
parent f095505e39
commit f40716ae6e
4 changed files with 51 additions and 0 deletions

View File

@ -84,6 +84,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PanelFrame", "resource:///modules/Panel
state = "active";
} else if (MozLoopService.doNotDisturb) {
state = "disabled";
} else if (MozLoopService.roomsParticipantsCount > 0) {
state = "active";
}
this.toolbarButton.node.setAttribute("state", state);
},

View File

@ -107,13 +107,34 @@ const checkForParticipantsUpdate = function(room, updatedRoom) {
* violated. You'll notice this as well in the documentation for each method.
*/
let LoopRoomsInternal = {
/**
* @var {Map} rooms Collection of rooms currently in cache.
*/
rooms: new Map(),
/**
* @var {String} sessionType The type of user session. May be 'FXA' or 'GUEST'.
*/
get sessionType() {
return MozLoopService.userProfile ? LOOP_SESSION_TYPE.FXA :
LOOP_SESSION_TYPE.GUEST;
},
/**
* @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)) {
continue;
}
count += room.participants.length;
}
return count;
},
/**
* Fetch a list of rooms that the currently registered user is a member of.
*
@ -382,6 +403,10 @@ Object.freeze(LoopRoomsInternal);
* See the internal code for the API documentation.
*/
this.LoopRooms = {
get participantsCount() {
return LoopRoomsInternal.participantsCount;
},
getAll: function(version, callback) {
return LoopRoomsInternal.getAll(version, callback);
},

View File

@ -965,6 +965,10 @@ this.MozLoopService = {
gInitializeTimerFunc = value;
},
get roomsParticipantsCount() {
return LoopRooms.participantsCount;
},
/**
* Initialized the loop service, and starts registration with the
* push and loop servers.
@ -995,6 +999,14 @@ this.MozLoopService = {
}
}
// The Loop toolbar button should change icon when the room participant count
// changes from 0 to something.
const onRoomsChange = () => {
MozLoopServiceInternal.notifyStatusChanged();
};
LoopRooms.on("add", onRoomsChange);
LoopRooms.on("update", onRoomsChange);
// If expiresTime is not in the future and the user hasn't
// previously authenticated then skip registration.
if (!MozLoopServiceInternal.urlExpiryTimeIsInFuture() &&

View File

@ -8,6 +8,7 @@
"use strict";
Components.utils.import("resource://gre/modules/Promise.jsm", this);
const {LoopRoomsInternal} = Components.utils.import("resource:///modules/loop/LoopRooms.jsm", {});
registerCleanupFunction(function*() {
MozLoopService.doNotDisturb = false;
@ -79,3 +80,14 @@ add_task(function* test_active() {
Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "", "Check button is in default state");
});
add_task(function* test_room_participants() {
Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "", "Check button is in default state");
LoopRoomsInternal.rooms.set("test_room", {participants: [{displayName: "hugh", id: "008"}]});
MozLoopServiceInternal.notifyStatusChanged();
Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "active", "Check button is in active state");
LoopRoomsInternal.rooms.set("test_room", {participants: []});
MozLoopServiceInternal.notifyStatusChanged();
Assert.strictEqual(LoopUI.toolbarButton.node.getAttribute("state"), "", "Check button is in default state");
LoopRoomsInternal.rooms.delete("test_room");
});