mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Bugfixes and new algo for PAL notifs
This commit is contained in:
parent
4987164706
commit
9db11aeda7
2 changed files with 50 additions and 63 deletions
|
@ -823,46 +823,42 @@ function notificationDataProcessPage(data) {
|
|||
}
|
||||
|
||||
var shouldShowDot = false;
|
||||
var storedOnlineUsersArray = [];
|
||||
var pingPong = false;
|
||||
var storedOnlineUsers = {};
|
||||
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];
|
||||
pingPong = !pingPong;
|
||||
var newOnlineUsers = 0;
|
||||
var message;
|
||||
|
||||
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);
|
||||
connectionsArray.forEach(function (user) {
|
||||
var stored = storedOnlineUsers[user.username];
|
||||
var storedOrNew = stored || user;
|
||||
storedOrNew.pingPong = pingPong;
|
||||
if (stored) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.online) {
|
||||
newOnlineUsers++;
|
||||
storedOnlineUsers[user.username] = user;
|
||||
|
||||
if (!ui.isOpen && ui.notificationInitialCallbackMade) {
|
||||
message = user.username + " is available in " +
|
||||
user.location.root.name + "! Open PEOPLE to join them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
var key;
|
||||
for (key in storedOnlineUsers) {
|
||||
if (storedOnlineUsers[key].pingPong !== pingPong) {
|
||||
delete storedOnlineUsers[key];
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
shouldShowDot = newOnlineUsers > 0 || (Object.keys(storedOnlineUsers).length > 0 && shouldShowDot);
|
||||
//
|
||||
// END logic for handling online/offline user changes
|
||||
//
|
||||
|
@ -874,19 +870,10 @@ function notificationPollCallback(connectionsArray) {
|
|||
shouldShowDot: shouldShowDot
|
||||
});
|
||||
|
||||
if (newlyOnlineConnectionsArray.length > 0) {
|
||||
var message;
|
||||
if (!ui.notificationInitialCallbackMade) {
|
||||
message = newlyOnlineConnectionsArray.length + " of your connections " +
|
||||
(newlyOnlineConnectionsArray.length === 1 ? "is" : "are") + " online! Open PEOPLE to join them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (newOnlineUsers > 0 && !ui.notificationInitialCallbackMade) {
|
||||
message = newOnlineUsers + " of your connections " +
|
||||
(newOnlineUsers === 1 ? "is" : "are") + " online! Open PEOPLE to join them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,14 @@ var shouldShowDot = false;
|
|||
var pingPong = false;
|
||||
var storedAnnouncements = {};
|
||||
var storedFeaturedStories = {};
|
||||
var message;
|
||||
function notificationPollCallback(userStoriesArray) {
|
||||
//
|
||||
// START logic for keeping track of new info
|
||||
//
|
||||
pingPong = !pingPong;
|
||||
var totalCountedStories = 0;
|
||||
var shouldNotifyIndividually = !ui.isOpen && ui.notificationInitialCallbackMade;
|
||||
userStoriesArray.forEach(function (story) {
|
||||
if (story.audience !== "for_connections" &&
|
||||
story.audience !== "for_feed") {
|
||||
|
@ -52,8 +54,20 @@ function notificationPollCallback(userStoriesArray) {
|
|||
|
||||
if (story.audience === "for_connections") {
|
||||
storedAnnouncements[story.id] = story;
|
||||
|
||||
if (shouldNotifyIndividually) {
|
||||
message = storedAnnouncements[key].username + " says something is happening in " +
|
||||
storedAnnouncements[key].place_name + "! Open GOTO to join them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
} else if (story.audience === "for_feed") {
|
||||
storedFeaturedStories[story.id] = story;
|
||||
|
||||
if (shouldNotifyIndividually) {
|
||||
message = storedFeaturedStories[key].username + " has invited you to an event in " +
|
||||
storedFeaturedStories[key].place_name + "! Open GOTO to join them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
var key;
|
||||
|
@ -76,24 +90,10 @@ function notificationPollCallback(userStoriesArray) {
|
|||
shouldShowDot = totalCountedStories > 0 || (notificationCount > 0 && shouldShowDot);
|
||||
ui.messagesWaiting(shouldShowDot && !ui.isOpen);
|
||||
|
||||
if (notificationCount > 0 && !ui.isOpen) {
|
||||
var message;
|
||||
if (!ui.notificationInitialCallbackMade) {
|
||||
message = "You have " + userStoriesArray.length + "event invitations pending! " +
|
||||
"Open GOTO to see them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
} else {
|
||||
for (key in storedAnnouncements) {
|
||||
message = storedAnnouncements[key].username + " says something is happening in " +
|
||||
storedAnnouncements[key].place_name + "! Open GOTO to join them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
for (key in storedFeaturedStories) {
|
||||
message = storedFeaturedStories[key].username + " has invited you to an event in " +
|
||||
storedFeaturedStories[key].place_name + "! Open GOTO to join them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
}
|
||||
if (notificationCount > 0 && !ui.isOpen && !ui.notificationInitialCallbackMade) {
|
||||
message = "You have " + notificationCount + "event invitations pending! " +
|
||||
"Open GOTO to see them.";
|
||||
ui.notificationDisplayBanner(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue