mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 1074666 - Part 2 Change the toolbar icon when participants join and leave. Updated by pkerr,r=Standard8
This commit is contained in:
parent
fd89c946a4
commit
ad49c745df
@ -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);
|
||||
},
|
||||
|
@ -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);
|
||||
},
|
||||
|
@ -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() &&
|
||||
|
@ -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");
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user