Bug 1074666 - Part 2 Change the toolbar icon when participants join and leave. Updated by pkerr,r=Standard8
This commit is contained in:
@@ -84,6 +84,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PanelFrame", "resource:///modules/Panel
|
|||||||
state = "active";
|
state = "active";
|
||||||
} else if (MozLoopService.doNotDisturb) {
|
} else if (MozLoopService.doNotDisturb) {
|
||||||
state = "disabled";
|
state = "disabled";
|
||||||
|
} else if (MozLoopService.roomsParticipantsCount > 0) {
|
||||||
|
state = "active";
|
||||||
}
|
}
|
||||||
this.toolbarButton.node.setAttribute("state", state);
|
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.
|
* violated. You'll notice this as well in the documentation for each method.
|
||||||
*/
|
*/
|
||||||
let LoopRoomsInternal = {
|
let LoopRoomsInternal = {
|
||||||
|
/**
|
||||||
|
* @var {Map} rooms Collection of rooms currently in cache.
|
||||||
|
*/
|
||||||
rooms: new Map(),
|
rooms: new Map(),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var {String} sessionType The type of user session. May be 'FXA' or 'GUEST'.
|
||||||
|
*/
|
||||||
get sessionType() {
|
get sessionType() {
|
||||||
return MozLoopService.userProfile ? LOOP_SESSION_TYPE.FXA :
|
return MozLoopService.userProfile ? LOOP_SESSION_TYPE.FXA :
|
||||||
LOOP_SESSION_TYPE.GUEST;
|
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.
|
* 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.
|
* See the internal code for the API documentation.
|
||||||
*/
|
*/
|
||||||
this.LoopRooms = {
|
this.LoopRooms = {
|
||||||
|
get participantsCount() {
|
||||||
|
return LoopRoomsInternal.participantsCount;
|
||||||
|
},
|
||||||
|
|
||||||
getAll: function(version, callback) {
|
getAll: function(version, callback) {
|
||||||
return LoopRoomsInternal.getAll(version, callback);
|
return LoopRoomsInternal.getAll(version, callback);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -965,6 +965,10 @@ this.MozLoopService = {
|
|||||||
gInitializeTimerFunc = value;
|
gInitializeTimerFunc = value;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
get roomsParticipantsCount() {
|
||||||
|
return LoopRooms.participantsCount;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialized the loop service, and starts registration with the
|
* Initialized the loop service, and starts registration with the
|
||||||
* push and loop servers.
|
* 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
|
// If expiresTime is not in the future and the user hasn't
|
||||||
// previously authenticated then skip registration.
|
// previously authenticated then skip registration.
|
||||||
if (!MozLoopServiceInternal.urlExpiryTimeIsInFuture() &&
|
if (!MozLoopServiceInternal.urlExpiryTimeIsInFuture() &&
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/Promise.jsm", this);
|
Components.utils.import("resource://gre/modules/Promise.jsm", this);
|
||||||
|
const {LoopRoomsInternal} = Components.utils.import("resource:///modules/loop/LoopRooms.jsm", {});
|
||||||
|
|
||||||
registerCleanupFunction(function*() {
|
registerCleanupFunction(function*() {
|
||||||
MozLoopService.doNotDisturb = false;
|
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");
|
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");
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user