mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 20:22:27 +02:00
Overhaul notification logic for PAL
This commit is contained in:
parent
143a059b16
commit
c453594eb7
1 changed files with 50 additions and 9 deletions
|
@ -823,8 +823,49 @@ function notificationDataProcessPage(data) {
|
|||
}
|
||||
|
||||
var shouldShowDot = false;
|
||||
function notificationPollCallback(onlineUsersArray) {
|
||||
shouldShowDot = onlineUsersArray.length > 0;
|
||||
var storedOnlineUsersArray = [];
|
||||
function notificationPollCallback(connectionsArray) {
|
||||
//
|
||||
// START logic for handling online/offline user changes
|
||||
//
|
||||
var i, j;
|
||||
var newlyOnlineConnectionsArray = [];
|
||||
for (i = 0; i < connectionsArray.length; i++) {
|
||||
var currentUser = connectionsArray[i];
|
||||
|
||||
if (connectionsArray[i].online) {
|
||||
var indexOfStoredOnlineUser = -1;
|
||||
for (j = 0; j < storedOnlineUsersArray.length; j++) {
|
||||
if (currentUser.username === storedOnlineUsersArray[j].username) {
|
||||
indexOfStoredOnlineUser = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If the user record isn't already presesnt inside `storedOnlineUsersArray`...
|
||||
if (indexOfStoredOnlineUser < 0) {
|
||||
storedOnlineUsersArray.push(currentUser);
|
||||
newlyOnlineConnectionsArray.push(currentUser);
|
||||
}
|
||||
} else {
|
||||
var indexOfOfflineUser = -1;
|
||||
for (j = 0; j < storedOnlineUsersArray.length; j++) {
|
||||
if (currentUser.username === storedOnlineUsersArray[j].username) {
|
||||
indexOfOfflineUser = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (indexOfOfflineUser >= 0) {
|
||||
storedOnlineUsersArray.splice(indexOfOfflineUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If there's new data, the light should turn on.
|
||||
// If the light is already on and you have connections online, the light should stay on.
|
||||
// In all other cases, the light should turn off or stay off.
|
||||
shouldShowDot = newlyOnlineConnectionsArray.length > 0 || (storedOnlineUsersArray.length > 0 && shouldShowDot);
|
||||
//
|
||||
// END logic for handling online/offline user changes
|
||||
//
|
||||
|
||||
if (!ui.isOpen) {
|
||||
ui.messagesWaiting(shouldShowDot);
|
||||
|
@ -835,13 +876,13 @@ function notificationPollCallback(onlineUsersArray) {
|
|||
|
||||
var message;
|
||||
if (!ui.notificationInitialCallbackMade) {
|
||||
message = onlineUsersArray.length + " of your connections " +
|
||||
(onlineUsersArray.length === 1 ? "is" : "are") + " online. Open PEOPLE to join them!";
|
||||
message = newlyOnlineConnectionsArray.length + " of your connections " +
|
||||
(newlyOnlineConnectionsArray.length === 1 ? "is" : "are") + " online. Open PEOPLE to join them!";
|
||||
ui.notificationDisplayBanner(message);
|
||||
} else {
|
||||
for (var i = 0; i < onlineUsersArray.length; i++) {
|
||||
message = onlineUsersArray[i].username + " is available in " +
|
||||
onlineUsersArray[i].location.root.name + ". Open PEOPLE to join them!";
|
||||
for (i = 0; i < newlyOnlineConnectionsArray.length; i++) {
|
||||
message = newlyOnlineConnectionsArray[i].username + " is available in " +
|
||||
newlyOnlineConnectionsArray[i].location.root.name + ". Open PEOPLE to join them!";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
}
|
||||
|
@ -861,12 +902,12 @@ function startup() {
|
|||
onOpened: palOpened,
|
||||
onClosed: off,
|
||||
onMessage: fromQml,
|
||||
notificationPollEndpoint: "/api/v1/users?filter=connections&status=online&per_page=10",
|
||||
notificationPollEndpoint: "/api/v1/users?filter=connections&per_page=10",
|
||||
notificationPollTimeoutMs: 60000,
|
||||
notificationDataProcessPage: notificationDataProcessPage,
|
||||
notificationPollCallback: notificationPollCallback,
|
||||
notificationPollStopPaginatingConditionMet: isReturnedDataEmpty,
|
||||
notificationPollCaresAboutSince: true
|
||||
notificationPollCaresAboutSince: false
|
||||
});
|
||||
Window.domainChanged.connect(clearLocalQMLDataAndClosePAL);
|
||||
Window.domainConnectionRefused.connect(clearLocalQMLDataAndClosePAL);
|
||||
|
|
Loading…
Reference in a new issue