mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
checkpoint
This commit is contained in:
parent
2a0fc5b34c
commit
f9debf1388
4 changed files with 150 additions and 88 deletions
|
@ -34,12 +34,12 @@ Column {
|
|||
|
||||
property string metaverseServerUrl: '';
|
||||
property string actions: 'snapshot';
|
||||
onActionsChanged: fillDestinations();
|
||||
Component.onCompleted: fillDestinations();
|
||||
property string labelText: actions;
|
||||
property string filter: '';
|
||||
onFilterChanged: filterChoicesByText();
|
||||
property var goFunction: null;
|
||||
property var rpc: null;
|
||||
|
||||
HifiConstants { id: hifi }
|
||||
ListModel { id: suggestions; }
|
||||
|
@ -81,10 +81,24 @@ Column {
|
|||
property var allStories: [];
|
||||
property var placeMap: ({}); // Used for making stacks.
|
||||
property int requestId: 0;
|
||||
function handleError(url, error, data, cb) { // cb(error) and answer truthy if needed, else falsey
|
||||
if (!error && (data.status === 'success')) {
|
||||
return;
|
||||
}
|
||||
if (!error) { // Create a message from the data
|
||||
error = data.status + ': ' + data.error;
|
||||
}
|
||||
if (typeof(error) === 'string') { // Make a proper Error object
|
||||
error = new Error(error);
|
||||
}
|
||||
error.message += ' in ' + url; // Include the url.
|
||||
cb(error);
|
||||
return true;
|
||||
}
|
||||
function getUserStoryPage(pageNumber, cb, cb1) { // cb(error) after all pages of domain data have been added to model
|
||||
// If supplied, cb1 will be run after the first page IFF it is not the last, for responsiveness.
|
||||
var options = [
|
||||
'now=' + new Date().toISOString(),
|
||||
//'now=' + new Date().toISOString(),
|
||||
'include_actions=' + actions,
|
||||
'restriction=' + (Account.isLoggedIn() ? 'open,hifi' : 'open'),
|
||||
'require_online=true',
|
||||
|
@ -93,8 +107,17 @@ Column {
|
|||
];
|
||||
var url = metaverseBase + 'user_stories?' + options.join('&');
|
||||
var thisRequestId = ++requestId;
|
||||
getRequest(url, function (error, data) {
|
||||
if ((thisRequestId !== requestId) || handleError(url, error, data, cb)) {
|
||||
rpc('request', {
|
||||
uri: url
|
||||
}, function (error, data) {
|
||||
console.log('fixme response', url, JSON.stringify(error), JSON.stringify(data));
|
||||
data.total_pages = 1; // fixme remove after testing
|
||||
if (thisRequestId !== requestId) {
|
||||
error = 'stale';
|
||||
}
|
||||
//console.log('fixme', actions, pageNumber, thisRequestId, requestId, url, error)
|
||||
//console.log('fixme data', actions, pageNumber, JSON.stringify(data));
|
||||
if (handleError(url, error, data, cb)) {
|
||||
return; // abandon stale requests
|
||||
}
|
||||
allStories = allStories.concat(data.user_stories.map(makeModelData));
|
||||
|
@ -108,21 +131,28 @@ Column {
|
|||
});
|
||||
}
|
||||
function fillDestinations() { // Public
|
||||
function report(label, error) {
|
||||
console.log(label, actions, error || 'ok', allStories.length, 'filtered to', suggestions.count);
|
||||
}
|
||||
var filter = makeFilteredStoryProcessor(), counter = 0;
|
||||
allStories = [];
|
||||
suggestions.clear();
|
||||
placeMap = {};
|
||||
getUserStoryPage(1, function (error) {
|
||||
allStories.slice(counter).forEach(filter);
|
||||
console.log('user stories query', actions, error || 'ok', allStories.length, 'filtered to', suggestions.count);
|
||||
report('user stories update', error);
|
||||
root.visible = !!suggestions.count;
|
||||
}, function () { // If there's more than a page, put what we have in the model right away, keeping track of how many are processed.
|
||||
}/*, function () { // If there's more than a page, put what we have in the model right away, keeping track of how many are processed.
|
||||
allStories.forEach(function (story) {
|
||||
counter++;
|
||||
filter(story);
|
||||
root.visible = !!suggestions.count;
|
||||
});
|
||||
});
|
||||
report('user stories');
|
||||
}*/);
|
||||
}
|
||||
function identity(x) {
|
||||
return x;
|
||||
}
|
||||
function makeFilteredStoryProcessor() { // answer a function(storyData) that adds it to suggestions if it matches
|
||||
var words = filter.toUpperCase().split(/\s+/).filter(identity);
|
||||
|
@ -130,7 +160,7 @@ Column {
|
|||
if (story.action === 'snapshot') {
|
||||
return true;
|
||||
}
|
||||
return (story.place_name !== AddressManager.placename); // Not our entry, but do show other entry points to current domain.
|
||||
return true; // fixme restore (story.place_name !== AddressManager.placename); // Not our entry, but do show other entry points to current domain.
|
||||
}
|
||||
function matches(story) {
|
||||
if (!words.length) {
|
||||
|
|
|
@ -33,9 +33,33 @@ StackView {
|
|||
property int cardWidth: 212;
|
||||
property int cardHeight: 152;
|
||||
property string metaverseBase: addressBarDialog.metaverseServerUrl + "/api/v1/";
|
||||
|
||||
property var tablet: null;
|
||||
|
||||
// This version only implements rpc(method, parameters, callback(error, result)) calls initiated from here, not initiated from .js, nor "notifications".
|
||||
property var rpcCalls: ({});
|
||||
property var rpcCounter: 0;
|
||||
signal sendToScript(var message);
|
||||
function rpc(method, parameters, callback) {
|
||||
console.log('fixme rpc', method);
|
||||
sendToScript('foo');
|
||||
console.log('fixme sent to script');
|
||||
/*rpcCalls[rpcCounter] = callback;
|
||||
var message = {method: method, params: parameters, id: rpcCounter++, jsonrpc: "2.0"};
|
||||
console.log('fixme sending rpc', JSON.stringify(message));
|
||||
sendToScript(message);
|
||||
console.log('fixme sent rpc', message.id);*/
|
||||
}
|
||||
function fromScript(message) {
|
||||
console.log('fixme got message from script:', JSON.stringify(message));
|
||||
var callback = rpcCalls[message.id];
|
||||
if (!callback) {
|
||||
console.log('No callback for message fromScript', JSON.stringify(message));
|
||||
return;
|
||||
}
|
||||
delete rpcCalls[message.id];
|
||||
callback(message.error, message.result);
|
||||
}
|
||||
|
||||
Component { id: tabletWebView; TabletWebView {} }
|
||||
Component.onCompleted: {
|
||||
updateLocationText(false);
|
||||
|
@ -266,6 +290,7 @@ StackView {
|
|||
actions: 'announcement';
|
||||
filter: addressLine.text;
|
||||
goFunction: goCard;
|
||||
rpc: root.rpc;
|
||||
}
|
||||
Feed {
|
||||
id: places;
|
||||
|
@ -278,6 +303,7 @@ StackView {
|
|||
actions: 'concurrency';
|
||||
filter: addressLine.text;
|
||||
goFunction: goCard;
|
||||
rpc: root.rpc;
|
||||
}
|
||||
Feed {
|
||||
id: snapshots;
|
||||
|
@ -291,6 +317,7 @@ StackView {
|
|||
actions: 'snapshot';
|
||||
filter: addressLine.text;
|
||||
goFunction: goCard;
|
||||
rpc: root.rpc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -330,50 +357,6 @@ StackView {
|
|||
|
||||
}
|
||||
|
||||
function getRequest(url, cb) { // cb(error, responseOfCorrectContentType) of url. General for 'get' text/html/json, but without redirects.
|
||||
// TODO: make available to other .qml.
|
||||
var request = new XMLHttpRequest();
|
||||
// QT bug: apparently doesn't handle onload. Workaround using readyState.
|
||||
request.onreadystatechange = function () {
|
||||
var READY_STATE_DONE = 4;
|
||||
var HTTP_OK = 200;
|
||||
if (request.readyState >= READY_STATE_DONE) {
|
||||
var error = (request.status !== HTTP_OK) && request.status.toString() + ':' + request.statusText,
|
||||
response = !error && request.responseText,
|
||||
contentType = !error && request.getResponseHeader('content-type');
|
||||
if (!error && contentType.indexOf('application/json') === 0) {
|
||||
try {
|
||||
response = JSON.parse(response);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
}
|
||||
cb(error, response);
|
||||
}
|
||||
};
|
||||
request.open("GET", url, true);
|
||||
request.send();
|
||||
}
|
||||
|
||||
function identity(x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
function handleError(url, error, data, cb) { // cb(error) and answer truthy if needed, else falsey
|
||||
if (!error && (data.status === 'success')) {
|
||||
return;
|
||||
}
|
||||
if (!error) { // Create a message from the data
|
||||
error = data.status + ': ' + data.error;
|
||||
}
|
||||
if (typeof(error) === 'string') { // Make a proper Error object
|
||||
error = new Error(error);
|
||||
}
|
||||
error.message += ' in ' + url; // Include the url.
|
||||
cb(error);
|
||||
return true;
|
||||
}
|
||||
|
||||
function updateLocationText(enteringAddress) {
|
||||
if (enteringAddress) {
|
||||
notice.text = "Go To a place, @user, path, or network address:";
|
||||
|
|
|
@ -723,7 +723,6 @@ function startup() {
|
|||
activeIcon: "icons/tablet-icons/people-a.svg",
|
||||
sortOrder: 7
|
||||
});
|
||||
tablet.fromQml.connect(fromQml);
|
||||
button.clicked.connect(onTabletButtonClicked);
|
||||
tablet.screenChanged.connect(onTabletScreenChanged);
|
||||
Users.usernameFromIDReply.connect(usernameFromIDReply);
|
||||
|
@ -789,8 +788,23 @@ function onTabletButtonClicked() {
|
|||
audioTimer = createAudioInterval(conserveResources ? AUDIO_LEVEL_CONSERVED_UPDATE_INTERVAL_MS : AUDIO_LEVEL_UPDATE_INTERVAL_MS);
|
||||
}
|
||||
}
|
||||
var hasEventBridge = false;
|
||||
function wireEventBridge(on) {
|
||||
if (on) {
|
||||
if (!hasEventBridge) {
|
||||
tablet.fromQml.connect(fromQml);
|
||||
hasEventBridge = true;
|
||||
}
|
||||
} else {
|
||||
if (hasEventBridge) {
|
||||
tablet.fromQml.disconnect(fromQml);
|
||||
hasEventBridge = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function onTabletScreenChanged(type, url) {
|
||||
wireEventBridge(shouldActivateButton);
|
||||
// for toolbar mode: change button to active when window is first openend, false otherwise.
|
||||
button.editProperties({isActive: shouldActivateButton});
|
||||
shouldActivateButton = false;
|
||||
|
|
|
@ -30,40 +30,6 @@
|
|||
text: buttonName,
|
||||
sortOrder: 8
|
||||
});
|
||||
function messagesWaiting(isWaiting) {
|
||||
button.editProperties({
|
||||
icon: isWaiting ? WAITING_ICON : NORMAL_ICON
|
||||
// No need for a different activeIcon, because we issue messagesWaiting(false) when the button goes active anyway.
|
||||
});
|
||||
}
|
||||
|
||||
function onClicked() {
|
||||
if (onGotoScreen) {
|
||||
// for toolbar-mode: go back to home screen, this will close the window.
|
||||
tablet.gotoHomeScreen();
|
||||
} else {
|
||||
shouldActivateButton = true;
|
||||
tablet.loadQMLSource(gotoQmlSource);
|
||||
onGotoScreen = true;
|
||||
}
|
||||
}
|
||||
|
||||
function onScreenChanged(type, url) {
|
||||
ignore(type);
|
||||
if (url === gotoQmlSource) {
|
||||
onGotoScreen = true;
|
||||
shouldActivateButton = true;
|
||||
button.editProperties({isActive: shouldActivateButton});
|
||||
messagesWaiting(false);
|
||||
} else {
|
||||
shouldActivateButton = false;
|
||||
onGotoScreen = false;
|
||||
button.editProperties({isActive: shouldActivateButton});
|
||||
}
|
||||
}
|
||||
button.clicked.connect(onClicked);
|
||||
tablet.screenChanged.connect(onScreenChanged);
|
||||
|
||||
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.
|
||||
|
@ -112,6 +78,74 @@
|
|||
httpRequest.open(options.method, options.uri, true);
|
||||
httpRequest.send(options.body);
|
||||
}
|
||||
function fromQmlXX(message) {
|
||||
print('fixme got fromQml', JSON.stringify(message));
|
||||
/*var response = {id: message.id, jsonrpc: "2.0"};
|
||||
switch (message.method) {
|
||||
case 'request':
|
||||
request(message.params, function (error, data) {
|
||||
response.error = error;
|
||||
response.result = data;
|
||||
tablet.sendToQml(response);
|
||||
});
|
||||
return;
|
||||
default:
|
||||
response.error = {message: 'Unrecognized message', data: message};
|
||||
}
|
||||
tablet.sendToQml(response);*/
|
||||
}
|
||||
function messagesWaiting(isWaiting) {
|
||||
button.editProperties({
|
||||
icon: isWaiting ? WAITING_ICON : NORMAL_ICON
|
||||
// No need for a different activeIcon, because we issue messagesWaiting(false) when the button goes active anyway.
|
||||
});
|
||||
}
|
||||
var hasEventBridge = false;
|
||||
function wireEventBridge(on) {
|
||||
print('fixme wireEventBridge', on, hasEventBridge);
|
||||
if (on) {
|
||||
if (!hasEventBridge) {
|
||||
tablet.fromQml.connect(fromQmlXX);
|
||||
print('fixme wired', tablet);
|
||||
hasEventBridge = true;
|
||||
}
|
||||
} else {
|
||||
if (hasEventBridge) {
|
||||
tablet.fromQml.disconnect(fromQmlXX);
|
||||
hasEventBridge = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
wireEventBridge(true);
|
||||
|
||||
function onClicked() {
|
||||
if (onGotoScreen) {
|
||||
// for toolbar-mode: go back to home screen, this will close the window.
|
||||
tablet.gotoHomeScreen();
|
||||
} else {
|
||||
shouldActivateButton = true;
|
||||
tablet.loadQMLSource(gotoQmlSource);
|
||||
onGotoScreen = true;
|
||||
}
|
||||
}
|
||||
|
||||
function onScreenChanged(type, url) {
|
||||
ignore(type);
|
||||
if (url === gotoQmlSource) {
|
||||
onGotoScreen = true;
|
||||
shouldActivateButton = true;
|
||||
button.editProperties({isActive: shouldActivateButton});
|
||||
wireEventBridge(true);
|
||||
messagesWaiting(false);
|
||||
} else {
|
||||
shouldActivateButton = false;
|
||||
onGotoScreen = false;
|
||||
button.editProperties({isActive: shouldActivateButton});
|
||||
wireEventBridge(false);
|
||||
}
|
||||
}
|
||||
button.clicked.connect(onClicked);
|
||||
tablet.screenChanged.connect(onScreenChanged);
|
||||
|
||||
var stories = {};
|
||||
var DEBUG = false;
|
||||
|
@ -135,6 +169,7 @@
|
|||
return;
|
||||
}
|
||||
var didNotify = false;
|
||||
print('fixme poll', url, JSON.stringify(data.user_stories));
|
||||
data.user_stories.forEach(function (story) {
|
||||
if (stories[story.id]) { // already seen
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue