pal refresh that remembers your place

This commit is contained in:
howard-stearns 2018-07-23 15:25:06 -07:00
parent db8846796f
commit f87db26cad
3 changed files with 43 additions and 19 deletions

View file

@ -145,6 +145,22 @@ Rectangle {
} }
pal.sendToScript({method: 'refreshNearby', params: params}); pal.sendToScript({method: 'refreshNearby', params: params});
} }
function refreshConnections() {
var flickable = connectionsUserModel.flickable;
connectionsRefreshScrollTimer.oldY = flickable.contentY;
flickable.contentY = 0;
connectionsUserModel.getFirstPage('delayRefresh', function () {
connectionsRefreshScrollTimer.start();
});
}
Timer {
id: connectionsRefreshScrollTimer;
interval: 500;
property real oldY: 0;
onTriggered: {
connectionsUserModel.flickable.contentY = oldY;
}
}
Rectangle { Rectangle {
id: palTabContainer; id: palTabContainer;
@ -276,7 +292,10 @@ Rectangle {
id: reloadConnections; id: reloadConnections;
width: reloadConnections.height; width: reloadConnections.height;
glyph: hifi.glyphs.reload; glyph: hifi.glyphs.reload;
onClicked: connectionsUserModel.getFirstPage('delayRefresh'); onClicked: {
pal.sendToScript({method: 'refreshConnections'});
refreshConnections();
}
} }
} }
// "CONNECTIONS" text // "CONNECTIONS" text
@ -1209,6 +1228,9 @@ Rectangle {
case 'clearLocalQMLData': case 'clearLocalQMLData':
ignored = {}; ignored = {};
break; break;
case 'refreshConnections':
refreshConnections();
break;
case 'avatarDisconnected': case 'avatarDisconnected':
var sessionID = message.params[0]; var sessionID = message.params[0];
delete ignored[sessionID]; delete ignored[sessionID];

View file

@ -93,7 +93,7 @@ ListModel {
property int totalPages: 0; property int totalPages: 0;
property int totalEntries: 0; property int totalEntries: 0;
// Check consistency and call processPage. // Check consistency and call processPage.
function handlePage(error, response) { function handlePage(error, response, cb) {
var processed; var processed;
console.debug('handlePage', listModelName, additionalFirstPageRequested, error, JSON.stringify(response)); console.debug('handlePage', listModelName, additionalFirstPageRequested, error, JSON.stringify(response));
function fail(message) { function fail(message) {
@ -134,7 +134,9 @@ ListModel {
if (additionalFirstPageRequested) { if (additionalFirstPageRequested) {
console.debug('deferred getFirstPage', listModelName); console.debug('deferred getFirstPage', listModelName);
additionalFirstPageRequested = false; additionalFirstPageRequested = false;
getFirstPage('delayedClear'); getFirstPage('delayedClear', cb);
} else if (cb) {
cb();
} }
} }
function debugView(label) { function debugView(label) {
@ -147,7 +149,7 @@ ListModel {
// Override either http or getPage. // Override either http or getPage.
property var http; // An Item that has a request function. property var http; // An Item that has a request function.
property var getPage: function () { // Any override MUST call handlePage(), above, even if results empty. property var getPage: function (cb) { // Any override MUST call handlePage(), above, even if results empty.
if (!http) { return console.warn("Neither http nor getPage was set for", listModelName); } 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. // If it is a path starting with slash, add the metaverseServer domain.
var url = /^\//.test(endpoint) ? (Account.metaverseServerURL + endpoint) : endpoint; var url = /^\//.test(endpoint) ? (Account.metaverseServerURL + endpoint) : endpoint;
@ -165,12 +167,12 @@ ListModel {
var parametersSeparator = /\?/.test(url) ? '&' : '?'; var parametersSeparator = /\?/.test(url) ? '&' : '?';
url = url + parametersSeparator + parameters.join('&'); url = url + parametersSeparator + parameters.join('&');
console.debug('getPage', listModelName, currentPageToRetrieve); console.debug('getPage', listModelName, currentPageToRetrieve);
http.request({uri: url}, handlePage); http.request({uri: url}, cb ? function (error, result) { handlePage(error, result, cb); } : handlePage);
} }
// Start the show by retrieving data according to `getPage()`. // Start the show by retrieving data according to `getPage()`.
// It can be custom-defined by this item's Parent. // It can be custom-defined by this item's Parent.
property var getFirstPage: function (delayClear) { property var getFirstPage: function (delayClear, cb) {
if (requestPending) { if (requestPending) {
console.debug('deferring getFirstPage', listModelName); console.debug('deferring getFirstPage', listModelName);
additionalFirstPageRequested = true; additionalFirstPageRequested = true;
@ -180,7 +182,7 @@ ListModel {
resetModel(); resetModel();
requestPending = true; requestPending = true;
console.debug("getFirstPage", listModelName, currentPageToRetrieve); console.debug("getFirstPage", listModelName, currentPageToRetrieve);
getPage(); getPage(cb);
} }
property bool additionalFirstPageRequested: false; property bool additionalFirstPageRequested: false;
property bool requestPending: false; // For de-bouncing getNextPage. property bool requestPending: false; // For de-bouncing getNextPage.

View file

@ -268,7 +268,6 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
break; break;
case 'refreshConnections': case 'refreshConnections':
print('Refreshing Connections...'); print('Refreshing Connections...');
getConnectionData(false);
UserActivityLogger.palAction("refresh_connections", ""); UserActivityLogger.palAction("refresh_connections", "");
break; break;
case 'removeConnection': case 'removeConnection':
@ -281,7 +280,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
print("Error: unable to remove connection", connectionUserName, error || response.status); print("Error: unable to remove connection", connectionUserName, error || response.status);
return; return;
} }
getConnectionData(false); sendToQml({ method: 'refreshConnections' });
}); });
break; break;
@ -361,8 +360,9 @@ function getProfilePicture(username, callback) { // callback(url) if successfull
callback(matched[1]); callback(matched[1]);
}); });
} }
var SAFETY_LIMIT = 600;
function getAvailableConnections(domain, callback) { // callback([{usename, location}...]) if successfull. (Logs otherwise) function getAvailableConnections(domain, callback) { // callback([{usename, location}...]) if successfull. (Logs otherwise)
var url = METAVERSE_BASE + '/api/v1/users?per_page=400&'; var url = METAVERSE_BASE + '/api/v1/users?per_page=' + SAFETY_LIMIT + '&';
if (domain) { if (domain) {
url += 'status=' + domain.slice(1, -1); // without curly braces url += 'status=' + domain.slice(1, -1); // without curly braces
} else { } else {
@ -373,8 +373,10 @@ function getAvailableConnections(domain, callback) { // callback([{usename, loca
}); });
} }
function getInfoAboutUser(specificUsername, callback) { function getInfoAboutUser(specificUsername, callback) {
var url = METAVERSE_BASE + '/api/v1/users?filter=connections'; var url = METAVERSE_BASE + '/api/v1/users?filter=connections&per_page=' + SAFETY_LIMIT + '&search=' + encodeURIComponent(specificUsername);
requestJSON(url, function (connectionsData) { requestJSON(url, function (connectionsData) {
// You could have (up to SAFETY_LIMIT connections whose usernames contain the specificUsername.
// Search returns all such matches.
for (user in connectionsData.users) { for (user in connectionsData.users) {
if (connectionsData.users[user].username === specificUsername) { if (connectionsData.users[user].username === specificUsername) {
callback(connectionsData.users[user]); callback(connectionsData.users[user]);
@ -406,16 +408,14 @@ function getConnectionData(specificUsername, domain) { // Update all the usernam
print('Error: Unable to find information about ' + specificUsername + ' in connectionsData!'); print('Error: Unable to find information about ' + specificUsername + ' in connectionsData!');
} }
}); });
} else { } else if (domain) {
getAvailableConnections(domain, function (users) { getAvailableConnections(domain, function (users) {
if (domain) { users.forEach(function (user) {
users.forEach(function (user) { pdateUser(frob(user));
updateUser(frob(user)); });
});
} else {
sendToQml({ method: 'connections', params: users.map(frob) });
}
}); });
} else {
print("Error: unrecognized getConnectionData()");
} }
} }