From 5a1b56d5730094ea889748bfc4f42dfecb997620 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Mon, 4 Jun 2018 13:11:06 -0700 Subject: [PATCH] checkpoint with goto feeds working (but without filtering) --- interface/resources/qml/hifi/Feed.qml | 52 ++++++++++++++----- .../qml/hifi/models/PSFListModel.qml | 7 ++- .../qml/hifi/tablet/TabletAddressDialog.qml | 40 +++----------- 3 files changed, 54 insertions(+), 45 deletions(-) diff --git a/interface/resources/qml/hifi/Feed.qml b/interface/resources/qml/hifi/Feed.qml index 3f3a47a297..98721ba2e0 100644 --- a/interface/resources/qml/hifi/Feed.qml +++ b/interface/resources/qml/hifi/Feed.qml @@ -16,10 +16,11 @@ import QtQuick 2.5 import QtGraphicalEffects 1.0 import "toolbars" import "../styles-uit" +import "models" as HifiModels Column { id: root; - visible: false; + visible: !!suggestions.count; property int cardWidth: 212; property int cardHeight: 152; @@ -32,18 +33,37 @@ Column { property int stackedCardShadowHeight: 4; property int labelSize: 20; - property string metaverseServerUrl: ''; + property string metaverseServerUrl: ''; // FIXME loose this? property string protocol: ''; property string actions: 'snapshot'; // sendToScript doesn't get wired until after everything gets created. So we have to queue fillDestinations on nextTick. property string labelText: actions; property string filter: ''; - onFilterChanged: filterChoicesByText(); + // FIXME onFilterChanged: filterChoicesByText(); property var goFunction: null; - property var rpc: null; + property var http: null; HifiConstants { id: hifi } - ListModel { id: suggestions; } + //FIXME ListModel { id: suggestions; } + Component.onCompleted: suggestions.getFirstPage(); + HifiModels.PSFListModel { + id: suggestions; + http: root.http; + property var options: [ + 'include_actions=' + actions, + 'restriction=' + (Account.isLoggedIn() ? 'open,hifi' : 'open'), + 'require_online=true', + 'protocol=' + Window.protocolSignature() + ]; + endpoint: '/api/v1/user_stories?' + options.join('&'); + itemsPerPage: 3; + processPage: function (data) { + console.log('FIXME processPage', suggestions.listModelName, JSON.stringify(data)); + return data.user_stories.map(makeModelData); + }; + listModelName: actions; + listView: scroll; + } function resolveUrl(url) { return (url.indexOf('/') === 0) ? (metaverseServerUrl + url) : url; @@ -60,11 +80,11 @@ Column { data.details.connections = 4; data.action = 'announcement'; } - return { + var fixme = { place_name: name, username: data.username || "", path: data.path || "", - created_at: data.created_at || "", + created_at: data.created_at || data.updated_at || "", // FIXME why aren't we getting created_at? action: data.action || "", thumbnail_url: resolveUrl(thumbnail_url), image_url: resolveUrl(data.details && data.details.image_url), @@ -77,8 +97,11 @@ Column { drillDownToPlace: false, searchText: [name].concat(tags, description || []).join(' ').toUpperCase() - } + }; + console.log('fixme makeModelData', JSON.stringify(fixme)); + return fixme; } + /* FIXME property var allStories: []; property var placeMap: ({}); // Used for making stacks. property int requestId: 0; @@ -108,7 +131,7 @@ Column { ]; var url = metaverseBase + 'user_stories?' + options.join('&'); var thisRequestId = ++requestId; - rpc('request', url, function (error, data) { + http.request(url, function (error, data) { if (thisRequestId !== requestId) { error = 'stale'; } @@ -126,8 +149,9 @@ Column { }); } function fillDestinations() { // Public - console.debug('Feed::fillDestinations()') - + console.debug('Feed::fillDestinations()'); + //suggestions.getFirstPage(); + } function report(label, error) { console.log(label, actions, error || 'ok', allStories.length, 'filtered to', suggestions.count); } @@ -193,6 +217,7 @@ Column { allStories.forEach(makeFilteredStoryProcessor()); root.visible = !!suggestions.count; } + */ RalewayBold { id: label; @@ -202,12 +227,13 @@ Column { } ListView { id: scroll; - model: suggestions; + model: suggestions.model; orientation: ListView.Horizontal; highlightFollowsCurrentItem: false highlightMoveDuration: -1; highlightMoveVelocity: -1; currentIndex: -1; + onAtXEndChanged: { console.log('FIXME onAtXEndChanged', actions, scroll.atXEnd, scroll.atXBeginning); if (scroll.atXEnd && !scroll.atXBeginning) { suggestions.getNextPage(); } } spacing: 12; width: parent.width; @@ -239,6 +265,7 @@ Column { unhoverThunk: function () { hovered = false } } } + /* WTF is this? NumberAnimation { id: anim; target: scroll; @@ -256,4 +283,5 @@ Column { scroll.currentIndex = index; anim.running = true; } + */ } diff --git a/interface/resources/qml/hifi/models/PSFListModel.qml b/interface/resources/qml/hifi/models/PSFListModel.qml index 9858d76d4a..6eff1cc073 100644 --- a/interface/resources/qml/hifi/models/PSFListModel.qml +++ b/interface/resources/qml/hifi/models/PSFListModel.qml @@ -63,7 +63,7 @@ Item { property bool delayedClear: false; function resetModel() { if (!delayedClear) { finalModel.clear(); } - currentPageToRetrieve = 1; + currentPageToRetrieve = 1; console.log('fixme resetModel set currentPageToRetrieve to 1', listModelName); retrievedAtLeastOnePage = false; copyOfItems = []; } @@ -80,6 +80,7 @@ Item { console.debug('handlePage', listModelName, error, JSON.stringify(response)); function fail(message) { console.warn("Warning", listModelName, JSON.stringify(message)); + console.log('FIXME fail setting currentPageToRetrieve to -1', listModelName); currentPageToRetrieve = -1; requestPending = false; delayedClear = false; @@ -96,6 +97,7 @@ Item { } processed = processPage(response.data || response); if (response.total_pages && (response.total_pages === currentPageToRetrieve)) { + console.log('fixme hanglePage set currentPageToRetrieve to -1', listModelName, 'response.total_pages:', response.total_pages, 'old currentPageToRetrieve:', currentPageToRetrieve); currentPageToRetrieve = -1; } if (searchItemTest) { @@ -122,6 +124,7 @@ Item { if (searchItemTest && searchFilter && listView && listView.atYEnd && (currentPageToRetrieve >= 0)) { getNextPage(); // too fancy?? } + if (listView) { console.debug('handlePage completed', listModelName, 'model:', model.count, 'view:', listView.count); } } function applySearchItemTest(items) { return items.filter(function (item) { @@ -140,6 +143,7 @@ Item { property var http; // An Item that has a request function. property var getPage: function () { // Any override MUST call handlePage(), above, even if results empty. if (!http) { return console.warn("Neither http nor getPage was set for", listModelName); } + // If it is a path starting with slash, add the metaverseServer domain. var url = /^\//.test(endpoint) ? (Account.metaverseServerURL + endpoint) : endpoint; var parameters = [ // FIXME: handle sort, search, tag parameters @@ -171,6 +175,7 @@ Item { // onAtYEndChanged: if (theList.atYEnd) { thisPSFListModelId.getNextPage(); } // ...} property var getNextPage: function () { + console.log('fixme getNextPage', listModelName, requestPending, currentPageToRetrieve); if (requestPending || currentPageToRetrieve < 0) { return; } diff --git a/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml b/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml index dc67494e27..104756967e 100644 --- a/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml +++ b/interface/resources/qml/hifi/tablet/TabletAddressDialog.qml @@ -37,38 +37,14 @@ StackView { 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; + RootHttpRequest { id: http; } signal sendToScript(var message); - function rpc(method, parameters, callback) { - console.debug('TabletAddressDialog: rpc: method = ', method, 'parameters = ', parameters, 'callback = ', callback) - - rpcCalls[rpcCounter] = callback; - var message = {method: method, params: parameters, id: rpcCounter++, jsonrpc: "2.0"}; - sendToScript(message); - } function fromScript(message) { - if (message.method === 'refreshFeeds') { - var feeds = [happeningNow, places, snapshots]; - console.debug('TabletAddressDialog::fromScript: refreshFeeds', 'feeds = ', feeds); - - feeds.forEach(function(feed) { - feed.protocol = encodeURIComponent(message.protocolSignature); - Qt.callLater(feed.fillDestinations); - }); - - return; + switch (message.method) { + case 'http.response': + http.handleHttpResponse(message); + break; } - - var callback = rpcCalls[message.id]; - if (!callback) { - // FIXME: We often recieve very long messages here, the logging of which is drastically slowing down the main thread - //console.log('No callback for message fromScript', JSON.stringify(message)); - return; - } - delete rpcCalls[message.id]; - callback(message.error, message.result); } Component { id: tabletWebView; TabletWebView {} } @@ -351,7 +327,7 @@ StackView { actions: 'announcement'; filter: addressLine.text; goFunction: goCard; - rpc: root.rpc; + http: http; } Feed { id: places; @@ -364,7 +340,7 @@ StackView { actions: 'concurrency'; filter: addressLine.text; goFunction: goCard; - rpc: root.rpc; + http: http; } Feed { id: snapshots; @@ -378,7 +354,7 @@ StackView { actions: 'snapshot'; filter: addressLine.text; goFunction: goCard; - rpc: root.rpc; + http: http; } } }