forked from vircadia/vircadia-native-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtablet-goto.js
138 lines (122 loc) · 4.44 KB
/
tablet-goto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
"use strict";
/* jslint vars:true, plusplus:true, forin:true */
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
/* global Window, Script, Tablet, HMD, Controller, Account, XMLHttpRequest, location, print */
//
// tablet-goto.js
// scripts/system/
//
// Created by Dante Ruiz on 8 February 2017
// Copyright 2016 High Fidelity, Inc.
// Copyright 2020 Project Athena contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function () { // BEGIN LOCAL_SCOPE
var AppUi = Script.require('appUi');
function gotoOpened() {
shouldShowDot = false;
ui.messagesWaiting(shouldShowDot);
}
function notificationDataProcessPage(data) {
return data.user_stories;
}
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 totalNewStories = 0;
var shouldNotifyIndividually = !ui.isOpen && ui.notificationInitialCallbackMade[0];
userStoriesArray.forEach(function (story) {
if (story.audience !== "for_connections" &&
story.audience !== "for_feed") {
return;
}
var stored = storedAnnouncements[story.id] || storedFeaturedStories[story.id];
var storedOrNew = stored || story;
storedOrNew.pingPong = pingPong;
if (stored) {
return;
}
totalNewStories++;
if (story.audience === "for_connections") {
storedAnnouncements[story.id] = story;
if (shouldNotifyIndividually) {
message = story.username + " says something is happening in " +
story.place_name + ". Open GOTO to join them.";
ui.notificationDisplayBanner(message);
}
} else if (story.audience === "for_feed") {
storedFeaturedStories[story.id] = story;
if (shouldNotifyIndividually) {
message = story.username + " invites you to an event in " +
story.place_name + ". Open GOTO to join them.";
ui.notificationDisplayBanner(message);
}
}
});
var key;
for (key in storedAnnouncements) {
if (storedAnnouncements[key].pingPong !== pingPong) {
delete storedAnnouncements[key];
}
}
for (key in storedFeaturedStories) {
if (storedFeaturedStories[key].pingPong !== pingPong) {
delete storedFeaturedStories[key];
}
}
//
// END logic for keeping track of new info
//
var totalStories = Object.keys(storedAnnouncements).length +
Object.keys(storedFeaturedStories).length;
shouldShowDot = totalNewStories > 0 || (totalStories > 0 && shouldShowDot);
ui.messagesWaiting(shouldShowDot && !ui.isOpen);
if (totalStories > 0 && !ui.isOpen && !ui.notificationInitialCallbackMade[0]) {
message = "There " + (totalStories === 1 ? "is " : "are ") + totalStories + " event" +
(totalStories === 1 ? "" : "s") + " to know about. " +
"Open GOTO to see " + (totalStories === 1 ? "it" : "them") + ".";
ui.notificationDisplayBanner(message);
}
}
function isReturnedDataEmpty(data) {
var storiesArray = data.user_stories;
return storiesArray.length === 0;
}
var ui;
var GOTO_QML_SOURCE = "hifi/tablet/TabletAddressDialog.qml";
var BUTTON_NAME = "OLD GOTO";
function startup() {
var options = [
'include_actions=announcement',
'restriction=open,hifi',
'require_online=true',
'protocol=' + encodeURIComponent(Window.protocolSignature()),
'per_page=10'
];
var endpoint = '/api/v1/user_stories?' + options.join('&');
ui = new AppUi({
buttonName: BUTTON_NAME,
normalButton: "icons/tablet-icons/goto-i.svg",
activeButton: "icons/tablet-icons/goto-a.svg",
sortOrder: 8,
onOpened: gotoOpened,
home: GOTO_QML_SOURCE,
notificationPollEndpoint: [endpoint],
notificationPollTimeoutMs: [60000],
notificationDataProcessPage: [notificationDataProcessPage],
notificationPollCallback: [notificationPollCallback],
notificationPollStopPaginatingConditionMet: [isReturnedDataEmpty],
notificationPollCaresAboutSince: [false]
});
}
startup();
}()); // END LOCAL_SCOPE