Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Bug 1239241 - Facebook SEND button for sharing conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Campo committed Feb 11, 2016
1 parent 488153c commit f11be53
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 16 deletions.
32 changes: 24 additions & 8 deletions add-on/panels/js/roomStore.js
Expand Up @@ -335,14 +335,17 @@ loop.store = loop.store || {};
loop.shared.utils.composeCallUrlEmail(actionData.roomUrl, null,
actionData.roomDescription);

var bucket = this._constants.SHARING_ROOM_URL["EMAIL_FROM_" + (from || "").toUpperCase()];
var bucket = this._constants.SHARING_ROOM_URL[
"EMAIL_FROM_" + (from || "").toUpperCase()
];
if (typeof bucket === "undefined") {
console.error("No URL sharing type bucket found for '" + from + "'");
return;
}
loop.requestMulti(
["NotifyUITour", "Loop:RoomURLEmailed"],
["TelemetryAddValue", "LOOP_SHARING_ROOM_URL", bucket]);
["TelemetryAddValue", "LOOP_SHARING_ROOM_URL", bucket]
);
},

/**
Expand All @@ -352,12 +355,25 @@ loop.store = loop.store || {};
*/
facebookShareRoomUrl: function(actionData) {
var encodedRoom = encodeURIComponent(actionData.roomUrl);
loop.request("GetLoopPref", "facebook.shareUrl")
.then(shareUrl => {
loop.request("OpenURL", shareUrl.replace("%ROOM_URL%", encodedRoom));
}).then(() => {
loop.request("NotifyUITour", "Loop:RoomURLShared");
});

loop.requestMulti(
["GetLoopPref", "facebook.appId"],
["GetLoopPref", "facebook.fallbackUrl"],
["GetLoopPref", "facebook.shareUrl"]
).then(results => {
var app_id = results[0];
var fallback_url = results[1];
var redirect_url = encodeURIComponent(actionData.originUrl ||
fallback_url);

var finalURL = results[2].replace("%ROOM_URL%", encodedRoom)
.replace("%APP_ID%", app_id)
.replace("%REDIRECT_URI%", redirect_url);

return loop.request("OpenURL", finalURL);
}).then(() => {
loop.request("NotifyUITour", "Loop:RoomURLShared");
});

var from = actionData.from;
var bucket = this._constants.SHARING_ROOM_URL["FACEBOOK_FROM_" + from.toUpperCase()];
Expand Down
39 changes: 33 additions & 6 deletions add-on/panels/test/roomStore_test.js
Expand Up @@ -520,26 +520,53 @@ describe("loop.store.RoomStore", function() {

describe("#facebookShareRoomUrl", function() {
var getLoopPrefStub;
var sharingSite = "www.sharing-site.com",
shareURL = sharingSite +
"?app_id=%APP_ID%" +
"&link=%ROOM_URL%" +
"&redirect_uri=%REDIRECT_URI%",
appId = "1234567890",
fallback = "www.fallback.com";

beforeEach(function() {
getLoopPrefStub = function() {
return "https://shared.site/?u=%ROOM_URL%";
};
getLoopPrefStub = sinon.stub();
getLoopPrefStub.withArgs("facebook.appId").returns(appId);
getLoopPrefStub.withArgs("facebook.shareUrl").returns(shareURL);
getLoopPrefStub.withArgs("facebook.fallbackUrl").returns(fallback);

LoopMochaUtils.stubLoopRequest({
GetLoopPref: getLoopPrefStub
});
});

it("should open the facebook url with room URL", function() {
it("should open the facebook share url with correct room and redirection", function() {
var room = "invalid.room",
origin = "origin.url";

store.facebookShareRoomUrl(new sharedActions.FacebookShareRoomUrl({
from: "conversation",
roomUrl: "http://invalid"
originUrl: origin,
roomUrl: room
}));

sinon.assert.calledOnce(requestStubs.OpenURL);
sinon.assert.calledWithMatch(requestStubs.OpenURL, sharingSite);
sinon.assert.calledWithMatch(requestStubs.OpenURL, room);
sinon.assert.calledWithMatch(requestStubs.OpenURL, origin);
});

it("if no origin URL, send fallback URL", function() {
var room = "invalid.room";

store.facebookShareRoomUrl(new sharedActions.FacebookShareRoomUrl({
from: "conversation",
roomUrl: room
}));

sinon.assert.calledOnce(requestStubs.OpenURL);
sinon.assert.calledWithExactly(requestStubs.OpenURL, "https://shared.site/?u=http%3A%2F%2Finvalid");
sinon.assert.calledWithMatch(requestStubs.OpenURL, sharingSite);
sinon.assert.calledWithMatch(requestStubs.OpenURL, room);
sinon.assert.calledWithMatch(requestStubs.OpenURL, fallback);
});

it("should send a telemetry event for facebook share from conversation", function() {
Expand Down
4 changes: 3 additions & 1 deletion add-on/preferences/prefs.js
Expand Up @@ -3,7 +3,6 @@ pref("loop.remote.autostart", false);
pref("loop.server", "https://loop.services.mozilla.com/v0");
pref("loop.linkClicker.url", "https://hello.firefox.com/");
pref("loop.gettingStarted.latestFTUVersion", 1);
pref("loop.facebook.shareUrl", "https://www.facebook.com/sharer/sharer.php?u=%ROOM_URL%");
pref("loop.gettingStarted.url", "https://www.mozilla.org/%LOCALE%/firefox/%VERSION%/hello/start/");
pref("loop.gettingStarted.resumeOnFirstJoin", false);
pref("loop.legal.ToS_url", "https://www.mozilla.org/about/legal/terms/firefox-hello/");
Expand Down Expand Up @@ -34,3 +33,6 @@ pref("loop.facebook.enabled", true);
#else
pref("loop.facebook.enabled", false);
#endif
pref("loop.facebook.appId", "1519239075036718");
pref("loop.facebook.shareUrl", "https://www.facebook.com/dialog/send?app_id=%APP_ID%&link=%ROOM_URL%&redirect_uri=%REDIRECT_URI%");
pref("loop.facebook.fallbackUrl", "https://hello.firefox.com/");
4 changes: 3 additions & 1 deletion shared/js/actions.js
Expand Up @@ -396,11 +396,13 @@ loop.shared.actions = (function() {
* XXX: should move to some roomActions module - refs bug 1079284
* @from: where the invitation is shared from.
* Possible values ['panel', 'conversation']
* @roomUrl: the URL that is shared
* @roomUrl: the URL that is shared.
* @roomOrigin: the URL browsed when the sharing is started - Optional.
*/
FacebookShareRoomUrl: Action.define("facebookShareRoomUrl", {
from: String,
roomUrl: String
// roomOrigin: String
}),

/**
Expand Down
2 changes: 2 additions & 0 deletions standalone/content/index.html
Expand Up @@ -9,6 +9,8 @@
<meta name="default_locale" content="en-US" />
<meta name="referrer" content="origin" />

<!-- FB Open Graph -->
<meta property="fb:app_id" content="1519239075036718" />
<meta property="og:image" content="https://hello.firefox.com/img/invitation.png" />
<meta property="og:image:height" content="630" />
<meta property="og:image:width" content="1200" />
Expand Down

0 comments on commit f11be53

Please sign in to comment.