From eaa699bbfdba3fe875bfe78b1cf5ab2f6147c083 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Fri, 21 Apr 2017 17:09:14 -0700 Subject: [PATCH] Wow, it's really coming together! --- interface/src/ui/SnapshotUploader.cpp | 7 +---- scripts/system/html/js/SnapshotReview.js | 37 +++++++++--------------- scripts/system/snapshot.js | 16 ++++++---- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/interface/src/ui/SnapshotUploader.cpp b/interface/src/ui/SnapshotUploader.cpp index 54faa822b8..aa37608476 100644 --- a/interface/src/ui/SnapshotUploader.cpp +++ b/interface/src/ui/SnapshotUploader.cpp @@ -79,12 +79,7 @@ void SnapshotUploader::uploadFailure(QNetworkReply& reply) { void SnapshotUploader::createStorySuccess(QNetworkReply& reply) { 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()->snapshotShared(false, storyId); + emit DependencyManager::get()->snapshotShared(false, replyString); delete this; } diff --git a/scripts/system/html/js/SnapshotReview.js b/scripts/system/html/js/SnapshotReview.js index 042bc55fb5..6e15dad567 100644 --- a/scripts/system/html/js/SnapshotReview.js +++ b/scripts/system/html/js/SnapshotReview.js @@ -33,21 +33,12 @@ function addImage(data, isGifLoading) { div.appendChild(img); document.getElementById("snapshot-images").appendChild(div); var isGif = img.src.split('.').pop().toLowerCase() === "gif"; - div.appendChild(createShareOverlay(id, isGif)); - if (!isGif) { - img.onload = function () { - var shareBar = document.getElementById(id + "shareBar"); - shareBar.style.width = img.clientWidth; - - document.getElementById(id).style.height = img.clientHeight; - } - } paths.push(data.localPath); if (!isGifLoading) { shareForUrl(id); } } -function createShareOverlay(parentID, isGif) { +function createShareOverlay(parentID, isGif, shareURL) { var shareOverlayContainer = document.createElement("DIV"); shareOverlayContainer.id = parentID + "shareOverlayContainer"; shareOverlayContainer.style.position = "absolute"; @@ -60,7 +51,7 @@ function createShareOverlay(parentID, isGif) { var shareBar = document.createElement("div"); shareBar.id = parentID + "shareBar" - shareBar.style.display = "none"; + shareBar.style.display = "inline"; shareBar.style.width = "100%"; shareBar.style.height = "60px"; shareBar.style.lineHeight = "60px"; @@ -107,8 +98,8 @@ function createShareOverlay(parentID, isGif) { '' + '' + '
' + - '' + - '' + + '' + + '' + '
' + ''; shareOverlayContainer.appendChild(shareOverlay); @@ -144,7 +135,7 @@ function shareWithEveryone(selectedID) { EventBridge.emitWebEvent(JSON.stringify({ type: "snapshot", action: "shareSnapshotWithEveryone", - data: paths[parseInt(selectedID.substring(1))] + story_id: document.getElementById(selectedID).getAttribute("data-story-id") })); } function cancelSharing(selectedID) { @@ -221,12 +212,6 @@ window.onload = function () { var p0img = document.getElementById('p0img'); p0img.src = gifPath; - p0img.onload = function () { - var shareBar = document.getElementById("p0shareBar"); - shareBar.style.width = p0img.clientWidth; - document.getElementById('p0').style.height = p0img.clientHeight; - } - paths[0] = gifPath; shareForUrl("p0"); } @@ -240,9 +225,15 @@ window.onload = function () { case 'captureSettings': handleCaptureSetting(message.setting); break; - case 'enableShareButtons': - var shareBar = document.getElementById("p0shareBar"); - shareBar.style.display = "inline"; + case 'snapshotUploadComplete': + var isGif = message.shareable_url.split('.').pop().toLowerCase() === "gif"; + var id = "p0" + if (imageCount > 1 && !isGif) { + id = "p1"; + } + var parentDiv = document.getElementById(id); + parentDiv.setAttribute('data-story-id', message.id); + document.getElementById(id).appendChild(createShareOverlay(id, isGif, message.story_url)); break; default: print("Unknown message action received in SnapshotReview.js."); diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index 37f3070dc0..6b0b8e1214 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -143,9 +143,9 @@ function onMessage(message) { case 'shareSnapshotWithEveryone': isLoggedIn = Account.isLoggedIn(); if (isLoggedIn) { - print('sharing', message.data); + print('Modifying audience of story ID', message.story_id, "to 'for_feed'"); request({ - uri: METAVERSE_BASE + '/api/v1/user_stories/' + story_id, + uri: METAVERSE_BASE + '/api/v1/user_stories/' + message.story_id, method: 'PUT', json: true, body: { @@ -153,8 +153,10 @@ function onMessage(message) { } }, function (error, response) { if (error || (response.status !== 'success')) { - print("Error changing audience: ", error || response.status); + print("ERROR changing audience: ", error || response.status); return; + } else { + print("SUCCESS changing audience!"); } }); } else { @@ -193,10 +195,14 @@ function reviewSnapshot() { function snapshotUploaded(isError, reply) { if (!isError) { - print('SUCCESS: Snapshot uploaded! Story with audience:for_url created! ID:', reply); + print('SUCCESS: Snapshot uploaded! Story with audience:for_url created!'); + var replyJson = JSON.parse(reply); tablet.emitScriptEvent(JSON.stringify({ type: "snapshot", - action: "enableShareButtons" + action: "snapshotUploadComplete", + id: replyJson.user_story.id, + story_url: "https://highfidelity.com/user_stories/" + replyJson.user_story.id, + shareable_url: replyJson.user_story.details.shareable_url, })); } else { print(reply);