From 62e2095baca87d9c777b3443cfe678c983d86f6b Mon Sep 17 00:00:00 2001 From: Ayman Habeb Date: Thu, 22 Feb 2018 15:48:55 -0800 Subject: [PATCH 1/2] add comment in push notification, userTags (#403) * add comment options for userTags * return auth user and Control Panel user in secondaryUserLookup --- pluginTester/scripts/overrides.js | 26 +++++++++++++++---- .../notifications/pushNotifications.js | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pluginTester/scripts/overrides.js b/pluginTester/scripts/overrides.js index 1776fb57..91337ca9 100644 --- a/pluginTester/scripts/overrides.js +++ b/pluginTester/scripts/overrides.js @@ -96,13 +96,29 @@ postMaster.servicePluginAPIs.service.tag = 'service'; }; - ///override the authAPI.getCurrentUser to return CP loggedIn user + ///override the authAPI.getCurrentUser to return auth authAPI.secondaryUserLookup = function () { - var user = window.currentUser; - if(!user) { + if(!window.currentUser || !window.currentUser.userToken || !window.currentUser.auth) return null; - } - return user.authProfile ? user.authProfile : user; + + if (!window.currentAuthUser) { + var appId = ''; + if (appContext.currentApp && appContext.currentApp.appId) + appId = appContext.currentApp.appId; + + var request = new XMLHttpRequest(); + request.open('GET', 'https://app.buildfire.com/api/user/auth/' + appId, false); // `false` makes the request synchronous + request.setRequestHeader("userToken", window.currentUser.userToken); + request.setRequestHeader("auth", window.currentUser.auth); + request.send(null); + if (request.status === 200) { + window.currentAuthUser = JSON.parse(request.responseText); + } + } + if (window.currentAuthUser) + window.currentAuthUser._cpUser = window.currentUser; + + return window.currentAuthUser; }; /// diff --git a/scripts/buildfire/services/notifications/pushNotifications.js b/scripts/buildfire/services/notifications/pushNotifications.js index d6e9d356..74efaf10 100644 --- a/scripts/buildfire/services/notifications/pushNotifications.js +++ b/scripts/buildfire/services/notifications/pushNotifications.js @@ -8,6 +8,7 @@ buildfire.notifications.pushNotification = { //text: string //at: Date (optional), representing the time to send the push notification. //users: array (optional) + //userTags: array (optional) //groupName: string (optional) //queryString: string (optional) schedule: function (options, callback) { From 8d3acd7b81f3971f832f7a97e973a6943fa002eb Mon Sep 17 00:00:00 2001 From: Daniel Hindi Date: Sat, 24 Feb 2018 14:26:18 -0800 Subject: [PATCH 2/2] fix shape scale --- .../buildfire/services/social/reactions.js | 209 ++++++++++++++++++ styles/reactions.css | 57 +++++ 2 files changed, 266 insertions(+) create mode 100644 scripts/buildfire/services/social/reactions.js create mode 100644 styles/reactions.css diff --git a/scripts/buildfire/services/social/reactions.js b/scripts/buildfire/services/social/reactions.js new file mode 100644 index 00000000..f1ba4e55 --- /dev/null +++ b/scripts/buildfire/services/social/reactions.js @@ -0,0 +1,209 @@ +/** + * Created by danielhindi on 2/16/18. + */ + +if (typeof (buildfire) == "undefined") throw ("please add buildfire.js first to use BuildFire services"); +if (!buildfire.social) buildfire.social = {}; + +buildfire.social.reactions= (function(){ + + var endPoint="https://kzq9kqyroa.execute-api.us-east-1.amazonaws.com/dev/social/"; + + function createReactionDiv(container,articleId,emotion){ + var div = document.createElement('div'); + div.setAttribute('emotion',emotion); + + + function handler() { + + if (this.parentNode.className.indexOf("activeBar") >= 0) { + console.log(this.getAttribute('emotion')); + this.parentNode.classList.remove("activeBar"); + buildfire.social.reactions.toggleEmotion(articleId,emotion,function(err,result){ +debugger; + }); + } + else { + this.parentNode.classList.add("activeBar"); + } + + } + + if(location.protocol.indexOf("http")==0) + div.onclick=handler; + else + div.ontouch=handler; + + container.appendChild(div); + } + function createReactionDivs(container,articleId){ + ['hate','love','lol','wow','sad','like'].forEach(function(e){ + createReactionDiv(container,articleId,e); + }); + + } + + function getUser(callback) { + buildfire.auth.getCurrentUser(function (err, user) { + if (err) + callback(err); + else if (!user) { + buildfire.auth.login({}, function (err, user) { + if (err) + callback(err); + else + callback(null,user); + }); + } + else + callback(null,user); + + }); + } + + function addLastReactorsPics(div,participants) { + if (!participants || !div || !participants.length) return; + + var picCount=0; + for (var i = participants.length - 1; i >= 0 && picCount < 3; i--){ + if (participants[i].user.profilePic) { + var img = document.createElement('img'); + img.src = buildfire.imageLib.cropImage(participants[i].user.profilePic, {width: 52, height: 52}); + img.className = "reactorAvatar"; + div.appendChild(img); + picCount++; + } + } + + + } + + function didIParticipate(userId,participants) { + if(!userId || !participants)return false; + if (stats.participants && participants.length) + for (var i = 0; i < participants.length; i++) + if (participants.userId == userId) + return true; + return false; + } + + return { + fetchStats:function(articleIds,currentUserId,callback){ + if(!callback)callback=function(){}; + + var ids = articleIds; + if(!Array.isArray(ids)) + ids=[ids]; + var url = endPoint + "articles?includeAllReaction=1&articleIds="+ ids.join(","); + + fetch(url).then(function(res) { + + if(res.status == 200){ + res.json().then(function(b){ + if(Array.isArray(b) && b.length > 0 ) + callback(null,b[0]); + else + callback(); + }).catch(function(err){ + console.error(err); + }); + } + else if(res.status == 400) + console.error(res) ; + } ); + + + } + ,toggleEmotion:function(articleId,emotion,callback){ + if(!callback)callback=function(){}; + getUser(function(err,user){ + if(err) + callback(new Error('no logged in user',err)); + else { + + fetch(endPoint + "reactToggle",{ + method: 'post', + body: JSON.stringify({ + articleId,articleId + ,emotion:emotion + ,user: user + }) + }).then(function(res) { +debugger; + if(res.status == 200){ + res.json().then(function(b){ + if(Array.isArray(b) && b.length > 0 ) + callback(null,b[0]); + else + callback(); + }).catch(function(err){ + console.error(err); + }); + } + else if(res.status == 400) + console.error(res) ; + } ); + } + }); + + + + + } + ,attach:function(element,articleId,currentUserId){ + + var divTransformer = document.createElement('div'); + divTransformer.className = "reactionTransformer"; + element.appendChild(divTransformer); + + + var divReactionBar = document.createElement('div'); + divReactionBar.className="reactionBar"; + createReactionDivs(divReactionBar,articleId); + + divTransformer.appendChild(divReactionBar); + + this.fetchStats(articleId,currentUserId,function(err,stats){ + if(!stats)return; + + var divReactionStats = document.createElement('div'); + divReactionStats.className="reactionStats"; + + addLastReactorsPics(divReactionStats,stats.participants); + + + if(didIParticipate(currentUserId,stats.participants)){ + + } + + + var count = 0 ; + for(p in stats.emotions) + count+= stats.emotions[p]; + + if(count) { + var divReactionCount = document.createElement('div'); + divReactionCount.className = "reactionCount"; + divReactionCount.innerHTML = "(+" + count + ")"; + divReactionStats.appendChild(divReactionCount); + } + divTransformer.appendChild(divReactionStats); + + }); + + + + } + } +})(); + +document.addEventListener("DOMContentLoaded", function() { + buildfire.auth.getCurrentUser(function(err,user){ + var elements = document.querySelectorAll(".reactionContainer[articleId]"); + elements.forEach(function(e){ + var articleId= e.getAttribute("articleId"); + buildfire.social.reactions.attach(e,articleId,user?user.id:null); + }); + }); + +}); \ No newline at end of file diff --git a/styles/reactions.css b/styles/reactions.css new file mode 100644 index 00000000..c8ff4bf9 --- /dev/null +++ b/styles/reactions.css @@ -0,0 +1,57 @@ + +.reactionContainer{ + overflow: hidden; + height: 55px; + padding-bottom: 3px; + white-space: nowrap; +} + +.reactionContainer > .reactionTransformer { + transform: scale(1); + transform-origin: 0%; + white-space: nowrap; +} + +.reactionContainer .reactionBar{ + float: left; + background-color: white; + background-image: url('./media/reactions.png'); + background-repeat: no-repeat; + height: 52px; + width: 279px; + box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05); + border-radius: 50px; + margin-left: -230px; + transition: 250ms ease-out; +} + +.reactionContainer .reactionBar.activeBar{ + margin-left: 10px ; +} + +.reactionContainer .reactionBar > div{ + + margin-left: 1px; + width:45px; + height:52px; + float: left; + white-space: nowrap; +} + +.reactionContainer .reactionStats > .reactorAvatar{ + width: 50px; + height:50px; + border-radius: 50%; + border:3px solid white; +} + +.reactionContainer .reactionStats > .reactorAvatar:nth-child(n+2){ + margin-left: -20px; +} + +.reactionContainer .reactionStats > .reactionCount{ + font-size: 20px; + display: inline; + padding-top: 15px; + +}