mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 09:33:49 +02:00
Merge pull request #10374 from howard-stearns/notification-circumstances
Notification circumstances
This commit is contained in:
commit
fc9e9e1d28
3 changed files with 49 additions and 57 deletions
|
@ -156,10 +156,8 @@ Column {
|
|||
function makeFilteredStoryProcessor() { // answer a function(storyData) that adds it to suggestions if it matches
|
||||
var words = filter.toUpperCase().split(/\s+/).filter(identity);
|
||||
function suggestable(story) {
|
||||
if (story.action === 'snapshot') {
|
||||
return true;
|
||||
}
|
||||
return story.place_name !== AddressManager.placename; // Not our entry, but do show other entry points to current domain.
|
||||
// We could filter out places we don't want to suggest, such as those where (story.place_name === AddressManager.placename) or (story.username === Account.username).
|
||||
return true;
|
||||
}
|
||||
function matches(story) {
|
||||
if (!words.length) {
|
||||
|
|
|
@ -38,54 +38,7 @@ var METAVERSE_BASE = location.metaverseServerUrl;
|
|||
|
||||
// It's totally unnecessary to return to C++ to perform many of these requests, such as DELETEing an old story,
|
||||
// POSTING a new one, PUTTING a new audience, or GETTING story data. It's far more efficient to do all of that within JS
|
||||
function request(options, callback) { // cb(error, responseOfCorrectContentType) of url. A subset of npm request.
|
||||
var httpRequest = new XMLHttpRequest(), key;
|
||||
// QT bug: apparently doesn't handle onload. Workaround using readyState.
|
||||
httpRequest.onreadystatechange = function () {
|
||||
var READY_STATE_DONE = 4;
|
||||
var HTTP_OK = 200;
|
||||
if (httpRequest.readyState >= READY_STATE_DONE) {
|
||||
var error = (httpRequest.status !== HTTP_OK) && httpRequest.status.toString() + ':' + httpRequest.statusText,
|
||||
response = !error && httpRequest.responseText,
|
||||
contentType = !error && httpRequest.getResponseHeader('content-type');
|
||||
if (!error && contentType.indexOf('application/json') === 0) { // ignoring charset, etc.
|
||||
try {
|
||||
response = JSON.parse(response);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
callback(error, response);
|
||||
}
|
||||
};
|
||||
if (typeof options === 'string') {
|
||||
options = { uri: options };
|
||||
}
|
||||
if (options.url) {
|
||||
options.uri = options.url;
|
||||
}
|
||||
if (!options.method) {
|
||||
options.method = 'GET';
|
||||
}
|
||||
if (options.body && (options.method === 'GET')) { // add query parameters
|
||||
var params = [], appender = (-1 === options.uri.search('?')) ? '?' : '&';
|
||||
for (key in options.body) {
|
||||
params.push(key + '=' + options.body[key]);
|
||||
}
|
||||
options.uri += appender + params.join('&');
|
||||
delete options.body;
|
||||
}
|
||||
if (options.json) {
|
||||
options.headers = options.headers || {};
|
||||
options.headers["Content-type"] = "application/json";
|
||||
options.body = JSON.stringify(options.body);
|
||||
}
|
||||
for (key in options.headers || {}) {
|
||||
httpRequest.setRequestHeader(key, options.headers[key]);
|
||||
}
|
||||
httpRequest.open(options.method, options.uri, true);
|
||||
httpRequest.send(options.body);
|
||||
}
|
||||
var request = Script.require('request').request;
|
||||
|
||||
function openLoginWindow() {
|
||||
if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar", false))
|
||||
|
|
|
@ -16,6 +16,13 @@
|
|||
(function () { // BEGIN LOCAL_SCOPE
|
||||
|
||||
var request = Script.require('request').request;
|
||||
var DEBUG = false;
|
||||
function debug() {
|
||||
if (!DEBUG) {
|
||||
return;
|
||||
}
|
||||
print('tablet-goto.js:', [].map.call(arguments, JSON.stringify));
|
||||
}
|
||||
|
||||
var gotoQmlSource = "TabletAddressDialog.qml";
|
||||
var buttonName = "GOTO";
|
||||
|
@ -39,6 +46,7 @@
|
|||
switch (message.method) {
|
||||
case 'request':
|
||||
request(message.params, function (error, data) {
|
||||
debug('rpc', request, 'error:', error, 'data:', data);
|
||||
response.error = error;
|
||||
response.result = data;
|
||||
tablet.sendToQml(response);
|
||||
|
@ -100,10 +108,24 @@
|
|||
button.clicked.connect(onClicked);
|
||||
tablet.screenChanged.connect(onScreenChanged);
|
||||
|
||||
var stories = {};
|
||||
var DEBUG = false;
|
||||
var stories = {}, pingPong = false;
|
||||
function expire(id) {
|
||||
var options = {
|
||||
uri: location.metaverseServerUrl + '/api/v1/user_stories/' + id,
|
||||
method: 'PUT',
|
||||
json: true,
|
||||
body: {expire: "true"}
|
||||
};
|
||||
request(options, function (error, response) {
|
||||
debug('expired story', options, 'error:', error, 'response:', response);
|
||||
if (error || (response.status !== 'success')) {
|
||||
print("ERROR expiring story: ", error || response.status);
|
||||
}
|
||||
});
|
||||
}
|
||||
function pollForAnnouncements() {
|
||||
var actions = DEBUG ? 'snapshot' : 'announcement';
|
||||
// We could bail now if !Account.isLoggedIn(), but what if we someday have system-wide announcments?
|
||||
var actions = 'announcement';
|
||||
var count = DEBUG ? 10 : 100;
|
||||
var options = [
|
||||
'now=' + new Date().toISOString(),
|
||||
|
@ -117,13 +139,24 @@
|
|||
request({
|
||||
uri: url
|
||||
}, function (error, data) {
|
||||
debug(url, error, data);
|
||||
if (error || (data.status !== 'success')) {
|
||||
print("Error: unable to get", url, error || data.status);
|
||||
return;
|
||||
}
|
||||
var didNotify = false;
|
||||
var didNotify = false, key;
|
||||
pingPong = !pingPong;
|
||||
data.user_stories.forEach(function (story) {
|
||||
if (stories[story.id]) { // already seen
|
||||
var stored = stories[story.id], storedOrNew = stored || story;
|
||||
debug('story exists:', !!stored, storedOrNew);
|
||||
if ((storedOrNew.username === Account.username) && (storedOrNew.place_name !== location.placename)) {
|
||||
if (storedOrNew.audience == 'for_connections') { // Only expire if we haven't already done so.
|
||||
expire(story.id);
|
||||
}
|
||||
return; // before marking
|
||||
}
|
||||
storedOrNew.pingPong = pingPong;
|
||||
if (stored) { // already seen
|
||||
return;
|
||||
}
|
||||
stories[story.id] = story;
|
||||
|
@ -131,12 +164,20 @@
|
|||
Window.displayAnnouncement(message);
|
||||
didNotify = true;
|
||||
});
|
||||
for (key in stories) { // Any story we were tracking that was not marked, has expired.
|
||||
if (stories[key].pingPong !== pingPong) {
|
||||
debug('removing story', key);
|
||||
delete stories[key];
|
||||
}
|
||||
}
|
||||
if (didNotify) {
|
||||
messagesWaiting(true);
|
||||
if (HMD.isHandControllerAvailable()) {
|
||||
var STRENGTH = 1.0, DURATION_MS = 60, HAND = 2; // both hands
|
||||
Controller.triggerHapticPulse(STRENGTH, DURATION_MS, HAND);
|
||||
}
|
||||
} else if (!Object.keys(stories).length) { // If there's nothing being tracked, then any messageWaiting has expired.
|
||||
messagesWaiting(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue