Fix incorrectly sharing old snapshots

This commit is contained in:
Zach Fox 2017-05-31 12:00:44 -07:00
parent fd92afff8c
commit 70fdb4a168

View file

@ -36,6 +36,8 @@ var shareAfterLogin = false;
var snapshotToShareAfterLogin = [];
var METAVERSE_BASE = location.metaverseServerUrl;
var isLoggedIn;
var numGifSnapshotUploadsPending = 0;
var numStillSnapshotUploadsPending = 0;
// It's totally unnecessary to return to C++ to perform many of these requests, such as DELETEing an old story,
// POSTING a new one, PUTTING a new audience, or GETTING story data. It's far more efficient to do all of that within JS
@ -139,6 +141,12 @@ function onMessage(message) {
if (isLoggedIn) {
print('Sharing snapshot with audience "for_url":', message.data);
Window.shareSnapshot(message.data, Settings.getValue("previousSnapshotHref"));
var isGif = message.data.split('.').pop().toLowerCase() === "gif";
if (isGif) {
numGifSnapshotUploadsPending++;
} else {
numStillSnapshotUploadsPending++;
}
} else {
shareAfterLogin = true;
snapshotToShareAfterLogin.push({ path: message.data, href: Settings.getValue("previousSnapshotHref") });
@ -307,22 +315,39 @@ function onButtonClicked() {
function snapshotUploaded(isError, reply) {
if (!isError) {
var replyJson = JSON.parse(reply);
var storyID = replyJson.user_story.id;
var replyJson = JSON.parse(reply),
storyID = replyJson.user_story.id,
imageURL = replyJson.user_story.details.image_url,
isGif = imageURL.split('.').pop().toLowerCase() === "gif",
ignoreGifSnapshotData = false,
ignoreStillSnapshotData = false;
storyIDsToMaybeDelete.push(storyID);
var imageURL = replyJson.user_story.details.image_url;
var isGif = imageURL.split('.').pop().toLowerCase() === "gif";
print('SUCCESS: Snapshot uploaded! Story with audience:for_url created! ID:', storyID);
tablet.emitScriptEvent(JSON.stringify({
type: "snapshot",
action: "snapshotUploadComplete",
story_id: storyID,
image_url: imageURL,
}));
if (isGif) {
Settings.setValue("previousAnimatedSnapStoryID", storyID);
numGifSnapshotUploadsPending--;
if (numGifSnapshotUploadsPending !== 0) {
ignoreGifSnapshotData = true;
}
} else {
Settings.setValue("previousStillSnapStoryID", storyID);
numStillSnapshotUploadsPending--;
if (numStillSnapshotUploadsPending !== 0) {
ignoreStillSnapshotData = true;
}
}
if ((isGif && !ignoreGifSnapshotData) || (!isGif && !ignoreStillSnapshotData)) {
print('SUCCESS: Snapshot uploaded! Story with audience:for_url created! ID:', storyID);
tablet.emitScriptEvent(JSON.stringify({
type: "snapshot",
action: "snapshotUploadComplete",
story_id: storyID,
image_url: imageURL,
}));
if (isGif) {
Settings.setValue("previousAnimatedSnapStoryID", storyID);
} else {
Settings.setValue("previousStillSnapStoryID", storyID);
}
} else {
print('Ignoring snapshotUploaded() callback for stale ' + (isGif ? 'GIF' : 'Still' ) + ' snapshot. Stale story ID:', storyID);
}
} else {
print(reply);
@ -568,6 +593,12 @@ function onUsernameChanged() {
snapshotToShareAfterLogin.forEach(function (element) {
print('Uploading snapshot after login:', element.path);
Window.shareSnapshot(element.path, element.href);
var isGif = element.path.split('.').pop().toLowerCase() === "gif";
if (isGif) {
numGifSnapshotUploadsPending++;
} else {
numStillSnapshotUploadsPending++;
}
});
}
});