Initial sharing code hooked up

This commit is contained in:
Zach Fox 2017-04-21 10:17:49 -07:00
parent 01e78612c7
commit c08b40b950
2 changed files with 32 additions and 46 deletions

View file

@ -43,7 +43,7 @@ function addImage(data) {
document.getElementById(id).style.height = img.clientHeight;
}
}
paths.push(data);
paths.push(data.localPath);
}
function createShareOverlay(parentID, isGif) {
var shareOverlayContainer = document.createElement("DIV");
@ -99,7 +99,7 @@ function createShareOverlay(parentID, isGif) {
'<br/>' +
'<div class="shareControls">' +
'<div class="hifiShareControls">' +
'<input type="button" class="shareWithEveryone" id="' + shareWithEveryoneButtonID + '" value="SHARE WITH EVERYONE" onclick="" /><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" />' +
'<label class="shareButtonLabel" for="' + inviteConnectionsCheckboxID + '">Invite My Connections</label><br>' +
'<input type="button" class="cancelShare" value="CANCEL" onclick="cancelSharing(' + parentID + ')" />' +
@ -129,6 +129,15 @@ function selectImageToShare(selectedID) {
shareOverlayBackground.style.display = "inline";
shareOverlay.style.display = "inline";
}
function shareWithEveryone(selectedID) {
selectedID = selectedID.id; // Why is this necessary?
EventBridge.emitWebEvent(JSON.stringify({
type: "snapshot",
action: "shareSnapshot",
data: paths[parseInt(selectedID.substring(1))]
}));
}
function cancelSharing(selectedID) {
selectedID = selectedID.id; // Why is this necessary?
var shareOverlayContainer = document.getElementById(selectedID + "shareOverlayContainer");
@ -208,7 +217,7 @@ window.onload = function () {
document.getElementById('p0').style.height = p0img.clientHeight;
}
paths[0].localPath = gifPath;
paths[0] = gifPath;
}
} else {
imageCount = message.data.length;
@ -232,13 +241,6 @@ window.onload = function () {
});
};
// beware of bug: Cannot send objects at top level. (Nested in arrays is fine.)
function shareSelected() {
EventBridge.emitWebEvent(JSON.stringify({
type: "snapshot",
action: paths
}));
}
function doNotShare() {
EventBridge.emitWebEvent(JSON.stringify({
type: "snapshot",

View file

@ -96,43 +96,31 @@ function onMessage(message) {
//
onClicked();
break;
default:
//tablet.webEventReceived.disconnect(onMessage); // <<< It's probably this that's missing?!
HMD.closeTablet();
case 'shareSnapshot':
isLoggedIn = Account.isLoggedIn();
message.action.forEach(function (submessage) {
if (submessage.share && !isLoggedIn) {
needsLogin = true;
submessage.share = false;
shareAfterLogin = true;
snapshotToShareAfterLogin = {path: submessage.localPath, href: submessage.href || href};
}
if (submessage.share) {
print('sharing', submessage.localPath);
outstanding = true;
Window.shareSnapshot(submessage.localPath, submessage.href || href);
} else {
print('not sharing', submessage.localPath);
}
});
if (outstanding && shouldOpenFeedAfterShare()) {
showFeedWindow();
outstanding = false;
if (!isLoggedIn) {
needsLogin = true;
shareAfterLogin = true;
snapshotToShareAfterLogin = { path: message.data, href: message.href || href };
} else {
print('sharing', message.data);
outstanding++;
Window.shareSnapshot(message.data, message.href || href);
}
if (needsLogin) { // after the possible feed, so that the login is on top
var isLoggedIn = Account.isLoggedIn();
if (!isLoggedIn) {
if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))) {
Menu.triggerOption("Login / Sign Up");
} else {
tablet.loadQMLOnTop("../../dialogs/TabletLoginDialog.qml");
HMD.openTablet();
}
if (needsLogin) {
if ((HMD.active && Settings.getValue("hmdTabletBecomesToolbar"))
|| (!HMD.active && Settings.getValue("desktopTabletBecomesToolbar"))) {
Menu.triggerOption("Login / Sign Up");
} else {
tablet.loadQMLOnTop("../../dialogs/TabletLoginDialog.qml");
HMD.openTablet();
}
}
break;
default:
print('Unknown message action received by snapshot.js!');
break;
}
}
@ -298,11 +286,7 @@ function onConnected() {
print('sharing', snapshotToShareAfterLogin.path);
Window.shareSnapshot(snapshotToShareAfterLogin.path, snapshotToShareAfterLogin.href);
shareAfterLogin = false;
if (shouldOpenFeedAfterShare()) {
showFeedWindow();
}
}
}
button.clicked.connect(onClicked);