Checkpoint

This commit is contained in:
Zach Fox 2017-04-21 15:42:41 -07:00
parent c08b40b950
commit 880bcf3b1e
4 changed files with 133 additions and 53 deletions

View file

@ -74,7 +74,7 @@ signals:
void svoImportRequested(const QString& url); void svoImportRequested(const QString& url);
void domainConnectionRefused(const QString& reasonMessage, int reasonCode, const QString& extraInfo); void domainConnectionRefused(const QString& reasonMessage, int reasonCode, const QString& extraInfo);
void stillSnapshotTaken(const QString& pathStillSnapshot, bool notify); void stillSnapshotTaken(const QString& pathStillSnapshot, bool notify);
void snapshotShared(const QString& error); void snapshotShared(bool isError, const QString& reply);
void processingGifStarted(const QString& pathStillSnapshot); void processingGifStarted(const QString& pathStillSnapshot);
void processingGifCompleted(const QString& pathAnimatedSnapshot); void processingGifCompleted(const QString& pathAnimatedSnapshot);

View file

@ -49,6 +49,7 @@ void SnapshotUploader::uploadSuccess(QNetworkReply& reply) {
userStoryObject.insert("place_name", placeName); userStoryObject.insert("place_name", placeName);
userStoryObject.insert("path", currentPath); userStoryObject.insert("path", currentPath);
userStoryObject.insert("action", "snapshot"); userStoryObject.insert("action", "snapshot");
userStoryObject.insert("audience", "for_url");
rootObject.insert("user_story", userStoryObject); rootObject.insert("user_story", userStoryObject);
auto accountManager = DependencyManager::get<AccountManager>(); auto accountManager = DependencyManager::get<AccountManager>();
@ -61,7 +62,7 @@ void SnapshotUploader::uploadSuccess(QNetworkReply& reply) {
QJsonDocument(rootObject).toJson()); QJsonDocument(rootObject).toJson());
} else { } else {
emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(contents); emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(true, contents);
delete this; delete this;
} }
} }
@ -72,12 +73,18 @@ void SnapshotUploader::uploadFailure(QNetworkReply& reply) {
if (replyString.size() == 0) { if (replyString.size() == 0) {
replyString = reply.errorString(); replyString = reply.errorString();
} }
emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(replyString); // maybe someday include _inWorldLocation, _filename? emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(true, replyString); // maybe someday include _inWorldLocation, _filename?
delete this; delete this;
} }
void SnapshotUploader::createStorySuccess(QNetworkReply& reply) { void SnapshotUploader::createStorySuccess(QNetworkReply& reply) {
emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(QString()); QString replyString = reply.readAll();
// oh no QT pls
// let's write our own JSON parser???
QJsonDocument jsonResponse = QJsonDocument::fromJson(replyString.toUtf8());
QJsonObject object = jsonResponse.object()["user_story"].toObject();
QString storyId = QString::number(object["id"].toInt());
emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(false, storyId);
delete this; delete this;
} }
@ -87,7 +94,7 @@ void SnapshotUploader::createStoryFailure(QNetworkReply& reply) {
if (replyString.size() == 0) { if (replyString.size() == 0) {
replyString = reply.errorString(); replyString = reply.errorString();
} }
emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(replyString); emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(true, replyString);
delete this; delete this;
} }

View file

@ -11,7 +11,7 @@
// //
var paths = [], idCounter = 0, imageCount = 1; var paths = [], idCounter = 0, imageCount = 1;
function addImage(data) { function addImage(data, isGifLoading) {
if (!data.localPath) { if (!data.localPath) {
return; return;
} }
@ -38,12 +38,14 @@ function addImage(data) {
img.onload = function () { img.onload = function () {
var shareBar = document.getElementById(id + "shareBar"); var shareBar = document.getElementById(id + "shareBar");
shareBar.style.width = img.clientWidth; shareBar.style.width = img.clientWidth;
shareBar.style.display = "inline";
document.getElementById(id).style.height = img.clientHeight; document.getElementById(id).style.height = img.clientHeight;
} }
} }
paths.push(data.localPath); paths.push(data.localPath);
if (!isGifLoading) {
shareForUrl(id);
}
} }
function createShareOverlay(parentID, isGif) { function createShareOverlay(parentID, isGif) {
var shareOverlayContainer = document.createElement("DIV"); var shareOverlayContainer = document.createElement("DIV");
@ -99,7 +101,7 @@ function createShareOverlay(parentID, isGif) {
'<br/>' + '<br/>' +
'<div class="shareControls">' + '<div class="shareControls">' +
'<div class="hifiShareControls">' + '<div class="hifiShareControls">' +
'<input type="button" class="shareWithEveryone" id="' + shareWithEveryoneButtonID + '" value="SHARE WITH EVERYONE" onclick="shareWithEveryone(parentID)" /><br>' + '<input type="button" class="shareWithEveryone" id="' + shareWithEveryoneButtonID + '" value="SHARE WITH EVERYONE" onclick="shareWithEveryone(' + parentID + ')" /><br>' +
'<input type="checkbox" class="inviteConnections" id="' + inviteConnectionsCheckboxID + '" checked="checked" />' + '<input type="checkbox" class="inviteConnections" id="' + inviteConnectionsCheckboxID + '" checked="checked" />' +
'<label class="shareButtonLabel" for="' + inviteConnectionsCheckboxID + '">Invite My Connections</label><br>' + '<label class="shareButtonLabel" for="' + inviteConnectionsCheckboxID + '">Invite My Connections</label><br>' +
'<input type="button" class="cancelShare" value="CANCEL" onclick="cancelSharing(' + parentID + ')" />' + '<input type="button" class="cancelShare" value="CANCEL" onclick="cancelSharing(' + parentID + ')" />' +
@ -129,12 +131,19 @@ function selectImageToShare(selectedID) {
shareOverlayBackground.style.display = "inline"; shareOverlayBackground.style.display = "inline";
shareOverlay.style.display = "inline"; shareOverlay.style.display = "inline";
} }
function shareForUrl(selectedID) {
EventBridge.emitWebEvent(JSON.stringify({
type: "snapshot",
action: "shareSnapshotForUrl",
data: paths[parseInt(selectedID.substring(1))]
}));
}
function shareWithEveryone(selectedID) { function shareWithEveryone(selectedID) {
selectedID = selectedID.id; // Why is this necessary? selectedID = selectedID.id; // Why is this necessary?
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "snapshot", type: "snapshot",
action: "shareSnapshot", action: "shareSnapshotWithEveryone",
data: paths[parseInt(selectedID.substring(1))] data: paths[parseInt(selectedID.substring(1))]
})); }));
} }
@ -204,7 +213,9 @@ window.onload = function () {
if (messageOptions.processingGif) { if (messageOptions.processingGif) {
imageCount = message.data.length + 1; // "+1" for the GIF that'll finish processing soon imageCount = message.data.length + 1; // "+1" for the GIF that'll finish processing soon
message.data.unshift({ localPath: messageOptions.loadingGifPath }); message.data.unshift({ localPath: messageOptions.loadingGifPath });
message.data.forEach(addImage); message.data.forEach(function (element, idx, array) {
addImage(element, idx === 0);
});
} else { } else {
var gifPath = message.data[0].localPath; var gifPath = message.data[0].localPath;
var p0img = document.getElementById('p0img'); var p0img = document.getElementById('p0img');
@ -213,20 +224,26 @@ window.onload = function () {
p0img.onload = function () { p0img.onload = function () {
var shareBar = document.getElementById("p0shareBar"); var shareBar = document.getElementById("p0shareBar");
shareBar.style.width = p0img.clientWidth; shareBar.style.width = p0img.clientWidth;
shareBar.style.display = "inline";
document.getElementById('p0').style.height = p0img.clientHeight; document.getElementById('p0').style.height = p0img.clientHeight;
} }
paths[0] = gifPath; paths[0] = gifPath;
shareForUrl("p0");
} }
} else { } else {
imageCount = message.data.length; imageCount = message.data.length;
message.data.forEach(addImage); message.data.forEach(function (element, idx, array) {
addImage(element, false);
});
} }
break; break;
case 'captureSettings': case 'captureSettings':
handleCaptureSetting(message.setting); handleCaptureSetting(message.setting);
break; break;
case 'enableShareButtons':
var shareBar = document.getElementById("p0shareBar");
shareBar.style.display = "inline";
break;
default: default:
print("Unknown message action received in SnapshotReview.js."); print("Unknown message action received in SnapshotReview.js.");
break; break;

View file

@ -28,25 +28,61 @@ var button = tablet.addButton({
sortOrder: 5 sortOrder: 5
}); });
function shouldOpenFeedAfterShare() {
var persisted = Settings.getValue('openFeedAfterShare', true); // might answer true, false, "true", or "false"
return persisted && (persisted !== 'false');
}
function showFeedWindow() {
if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))) {
tablet.loadQMLSource("TabletAddressDialog.qml");
} else {
tablet.initialScreen("TabletAddressDialog.qml");
HMD.openTablet();
}
}
var outstanding;
var snapshotOptions; var snapshotOptions;
var imageData; var imageData;
var shareAfterLogin = false; var shareAfterLogin = false;
var snapshotToShareAfterLogin; var snapshotToShareAfterLogin;
var METAVERSE_BASE = location.metaverseServerUrl;
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);
}
function onMessage(message) { function onMessage(message) {
// Receives message from the html dialog via the qwebchannel EventBridge. This is complicated by the following: // Receives message from the html dialog via the qwebchannel EventBridge. This is complicated by the following:
// 1. Although we can send POJOs, we cannot receive a toplevel object. (Arrays of POJOs are fine, though.) // 1. Although we can send POJOs, we cannot receive a toplevel object. (Arrays of POJOs are fine, though.)
@ -73,7 +109,6 @@ function onMessage(message) {
options: snapshotOptions, options: snapshotOptions,
data: imageData data: imageData
})); }));
outstanding = 0;
break; break;
case 'openSettings': case 'openSettings':
if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar")) if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
@ -96,18 +131,41 @@ function onMessage(message) {
// //
onClicked(); onClicked();
break; break;
case 'shareSnapshot': case 'shareSnapshotForUrl':
isLoggedIn = Account.isLoggedIn(); isLoggedIn = Account.isLoggedIn();
if (!isLoggedIn) { if (isLoggedIn) {
print('Sharing snapshot with audience "for_url":', message.data);
Window.shareSnapshot(message.data, message.href || href);
} else {
// TODO?
}
break;
case 'shareSnapshotWithEveryone':
isLoggedIn = Account.isLoggedIn();
if (isLoggedIn) {
print('sharing', message.data);
request({
uri: METAVERSE_BASE + '/api/v1/user_stories/' + story_id,
method: 'PUT',
json: true,
body: {
audience: "for_feed",
}
}, function (error, response) {
if (error || (response.status !== 'success')) {
print("Error changing audience: ", error || response.status);
return;
}
});
} else {
// TODO
/*
needsLogin = true; needsLogin = true;
shareAfterLogin = true; shareAfterLogin = true;
snapshotToShareAfterLogin = { path: message.data, href: message.href || href }; snapshotToShareAfterLogin = { path: message.data, href: message.href || href };
} else { */
print('sharing', message.data);
outstanding++;
Window.shareSnapshot(message.data, message.href || href);
} }
/*
if (needsLogin) { if (needsLogin) {
if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar")) if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))) { || (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))) {
@ -116,7 +174,7 @@ function onMessage(message) {
tablet.loadQMLOnTop("../../dialogs/TabletLoginDialog.qml"); tablet.loadQMLOnTop("../../dialogs/TabletLoginDialog.qml");
HMD.openTablet(); HMD.openTablet();
} }
} }*/
break; break;
default: default:
print('Unknown message action received by snapshot.js!'); print('Unknown message action received by snapshot.js!');
@ -133,14 +191,15 @@ function reviewSnapshot() {
isInSnapshotReview = true; isInSnapshotReview = true;
} }
function snapshotShared(errorMessage) { function snapshotUploaded(isError, reply) {
if (!errorMessage) { if (!isError) {
print('snapshot uploaded and shared'); print('SUCCESS: Snapshot uploaded! Story with audience:for_url created! ID:', reply);
tablet.emitScriptEvent(JSON.stringify({
type: "snapshot",
action: "enableShareButtons"
}));
} else { } else {
print(errorMessage); print(reply);
}
if ((--outstanding <= 0) && shouldOpenFeedAfterShare()) {
showFeedWindow();
} }
} }
var href, domainId; var href, domainId;
@ -213,8 +272,7 @@ function stillSnapshotTaken(pathStillSnapshot, notify) {
snapshotOptions = { snapshotOptions = {
containsGif: false, containsGif: false,
processingGif: false, processingGif: false,
canShare: !!isDomainOpen(domainId), canShare: !!isDomainOpen(domainId)
openFeedAfterShare: shouldOpenFeedAfterShare()
}; };
imageData = [{ localPath: pathStillSnapshot, href: href }]; imageData = [{ localPath: pathStillSnapshot, href: href }];
reviewSnapshot(); reviewSnapshot();
@ -241,8 +299,7 @@ function processingGifStarted(pathStillSnapshot) {
containsGif: true, containsGif: true,
processingGif: true, processingGif: true,
loadingGifPath: Script.resolvePath(Script.resourcesPath() + 'icons/loadingDark.gif'), loadingGifPath: Script.resolvePath(Script.resourcesPath() + 'icons/loadingDark.gif'),
canShare: !!isDomainOpen(domainId), canShare: !!isDomainOpen(domainId)
openFeedAfterShare: shouldOpenFeedAfterShare()
}; };
imageData = [{ localPath: pathStillSnapshot, href: href }]; imageData = [{ localPath: pathStillSnapshot, href: href }];
reviewSnapshot(); reviewSnapshot();
@ -262,8 +319,7 @@ function processingGifCompleted(pathAnimatedSnapshot) {
snapshotOptions = { snapshotOptions = {
containsGif: true, containsGif: true,
processingGif: false, processingGif: false,
canShare: !!isDomainOpen(domainId), canShare: !!isDomainOpen(domainId)
openFeedAfterShare: shouldOpenFeedAfterShare()
} }
imageData = [{ localPath: pathAnimatedSnapshot, href: href }]; imageData = [{ localPath: pathAnimatedSnapshot, href: href }];
@ -283,7 +339,7 @@ function onTabletScreenChanged(type, url) {
} }
function onConnected() { function onConnected() {
if (shareAfterLogin && Account.isLoggedIn()) { if (shareAfterLogin && Account.isLoggedIn()) {
print('sharing', snapshotToShareAfterLogin.path); print('Sharing snapshot after login:', snapshotToShareAfterLogin.path);
Window.shareSnapshot(snapshotToShareAfterLogin.path, snapshotToShareAfterLogin.href); Window.shareSnapshot(snapshotToShareAfterLogin.path, snapshotToShareAfterLogin.href);
shareAfterLogin = false; shareAfterLogin = false;
} }
@ -291,7 +347,7 @@ function onConnected() {
button.clicked.connect(onClicked); button.clicked.connect(onClicked);
buttonConnected = true; buttonConnected = true;
Window.snapshotShared.connect(snapshotShared); Window.snapshotShared.connect(snapshotUploaded);
tablet.screenChanged.connect(onTabletScreenChanged); tablet.screenChanged.connect(onTabletScreenChanged);
Account.usernameChanged.connect(onConnected); Account.usernameChanged.connect(onConnected);
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {
@ -302,7 +358,7 @@ Script.scriptEnding.connect(function () {
if (tablet) { if (tablet) {
tablet.removeButton(button); tablet.removeButton(button);
} }
Window.snapshotShared.disconnect(snapshotShared); Window.snapshotShared.disconnect(snapshotUploaded);
tablet.screenChanged.disconnect(onTabletScreenChanged); tablet.screenChanged.disconnect(onTabletScreenChanged);
}); });