Wow, it's really coming together!

This commit is contained in:
Zach Fox 2017-04-21 17:09:14 -07:00
parent 880bcf3b1e
commit eaa699bbfd
3 changed files with 26 additions and 34 deletions

View file

@ -79,12 +79,7 @@ void SnapshotUploader::uploadFailure(QNetworkReply& reply) {
void SnapshotUploader::createStorySuccess(QNetworkReply& reply) { void SnapshotUploader::createStorySuccess(QNetworkReply& reply) {
QString replyString = reply.readAll(); QString replyString = reply.readAll();
// oh no QT pls emit DependencyManager::get<WindowScriptingInterface>()->snapshotShared(false, replyString);
// 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;
} }

View file

@ -33,21 +33,12 @@ function addImage(data, isGifLoading) {
div.appendChild(img); div.appendChild(img);
document.getElementById("snapshot-images").appendChild(div); document.getElementById("snapshot-images").appendChild(div);
var isGif = img.src.split('.').pop().toLowerCase() === "gif"; 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); paths.push(data.localPath);
if (!isGifLoading) { if (!isGifLoading) {
shareForUrl(id); shareForUrl(id);
} }
} }
function createShareOverlay(parentID, isGif) { function createShareOverlay(parentID, isGif, shareURL) {
var shareOverlayContainer = document.createElement("DIV"); var shareOverlayContainer = document.createElement("DIV");
shareOverlayContainer.id = parentID + "shareOverlayContainer"; shareOverlayContainer.id = parentID + "shareOverlayContainer";
shareOverlayContainer.style.position = "absolute"; shareOverlayContainer.style.position = "absolute";
@ -60,7 +51,7 @@ function createShareOverlay(parentID, isGif) {
var shareBar = document.createElement("div"); var shareBar = document.createElement("div");
shareBar.id = parentID + "shareBar" shareBar.id = parentID + "shareBar"
shareBar.style.display = "none"; shareBar.style.display = "inline";
shareBar.style.width = "100%"; shareBar.style.width = "100%";
shareBar.style.height = "60px"; shareBar.style.height = "60px";
shareBar.style.lineHeight = "60px"; shareBar.style.lineHeight = "60px";
@ -107,8 +98,8 @@ function createShareOverlay(parentID, isGif) {
'<input type="button" class="cancelShare" value="CANCEL" onclick="cancelSharing(' + parentID + ')" />' + '<input type="button" class="cancelShare" value="CANCEL" onclick="cancelSharing(' + parentID + ')" />' +
'</div>' + '</div>' +
'<div class="externalShareControls">' + '<div class="externalShareControls">' +
'<iframe src="https://www.facebook.com/plugins/share_button.php?href=http%3A%2F%2Fhighfidelity.io&layout=button_count&size=small&mobile_iframe=false&width=84&height=20&appId" width="84" height="20" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>' + '<iframe src="https://www.facebook.com/plugins/share_button.php?href=' + shareURL + '&layout=button_count&size=small&mobile_iframe=false&width=84&height=20&appId" width="84" height="20" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>' +
'<a class="twitter-share-button" href="https://twitter.com/intent/tweet">Tweet</a>' + '<a class="twitter-share-button" href="https://twitter.com/intent/tweet?text=I just took a snapshot in #HiFi!&url=' + shareURL + '&via=highfidelity"></a>' +
'</div>' + '</div>' +
'</div>'; '</div>';
shareOverlayContainer.appendChild(shareOverlay); shareOverlayContainer.appendChild(shareOverlay);
@ -144,7 +135,7 @@ function shareWithEveryone(selectedID) {
EventBridge.emitWebEvent(JSON.stringify({ EventBridge.emitWebEvent(JSON.stringify({
type: "snapshot", type: "snapshot",
action: "shareSnapshotWithEveryone", action: "shareSnapshotWithEveryone",
data: paths[parseInt(selectedID.substring(1))] story_id: document.getElementById(selectedID).getAttribute("data-story-id")
})); }));
} }
function cancelSharing(selectedID) { function cancelSharing(selectedID) {
@ -221,12 +212,6 @@ window.onload = function () {
var p0img = document.getElementById('p0img'); var p0img = document.getElementById('p0img');
p0img.src = gifPath; 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; paths[0] = gifPath;
shareForUrl("p0"); shareForUrl("p0");
} }
@ -240,9 +225,15 @@ window.onload = function () {
case 'captureSettings': case 'captureSettings':
handleCaptureSetting(message.setting); handleCaptureSetting(message.setting);
break; break;
case 'enableShareButtons': case 'snapshotUploadComplete':
var shareBar = document.getElementById("p0shareBar"); var isGif = message.shareable_url.split('.').pop().toLowerCase() === "gif";
shareBar.style.display = "inline"; 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; break;
default: default:
print("Unknown message action received in SnapshotReview.js."); print("Unknown message action received in SnapshotReview.js.");

View file

@ -143,9 +143,9 @@ function onMessage(message) {
case 'shareSnapshotWithEveryone': case 'shareSnapshotWithEveryone':
isLoggedIn = Account.isLoggedIn(); isLoggedIn = Account.isLoggedIn();
if (isLoggedIn) { if (isLoggedIn) {
print('sharing', message.data); print('Modifying audience of story ID', message.story_id, "to 'for_feed'");
request({ request({
uri: METAVERSE_BASE + '/api/v1/user_stories/' + story_id, uri: METAVERSE_BASE + '/api/v1/user_stories/' + message.story_id,
method: 'PUT', method: 'PUT',
json: true, json: true,
body: { body: {
@ -153,8 +153,10 @@ function onMessage(message) {
} }
}, function (error, response) { }, function (error, response) {
if (error || (response.status !== 'success')) { if (error || (response.status !== 'success')) {
print("Error changing audience: ", error || response.status); print("ERROR changing audience: ", error || response.status);
return; return;
} else {
print("SUCCESS changing audience!");
} }
}); });
} else { } else {
@ -193,10 +195,14 @@ function reviewSnapshot() {
function snapshotUploaded(isError, reply) { function snapshotUploaded(isError, reply) {
if (!isError) { 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({ tablet.emitScriptEvent(JSON.stringify({
type: "snapshot", 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 { } else {
print(reply); print(reply);