diff --git a/control/languages/controllers/stringsUI.js b/control/languages/controllers/stringsUI.js index dc71860..1396630 100644 --- a/control/languages/controllers/stringsUI.js +++ b/control/languages/controllers/stringsUI.js @@ -9,15 +9,15 @@ const stringsUI = { this._debouncers[key] = setTimeout(fn, 300); }, - capitalize(input) { - var words = input.split(' '); - var CapitalizedWords = []; - words.forEach(element => { - CapitalizedWords.push(element[0].toUpperCase() + element.slice(1, element.length)); - }); - return CapitalizedWords.join(' '); - } - + capitalize(input) { + var words = input.split(' '); + var CapitalizedWords = []; + words.forEach(element => { + CapitalizedWords.push(element[0].toUpperCase() + element.slice(1, element.length)); + }); + return CapitalizedWords.join(' '); + } + , init(containerId, strings, stringsConfig) { this.strings = strings; this.stringsConfig = stringsConfig; @@ -47,14 +47,19 @@ const stringsUI = { let sec = this.createAndAppend("section", "", [], container); this.createIfNotEmpty("h1", this.capitalize(sectionObj.title), ["section-title"], sec); - for (let key in sectionObj.labels) this.buildLabel(sec, sectionProp + "." + key, sectionObj.labels[key]); + for (let key in sectionObj.labels) { + if (sectionObj.labels[key].subtitle) { + this.createIfNotEmpty("h4", this.capitalize(sectionObj.labels[key].subtitle), ["section-sub-title"], sec); + } + this.buildLabel(sec, sectionProp + "." + key, sectionObj.labels[key]); + } container.appendChild(sec); } , buildLabel(container, prop, labelObj) { let rowDiv = this.createAndAppend('div', '', ["item", "row", "margin-bottom-fifteen"], container); let labelDiv = this.createAndAppend('div', '', [], rowDiv); this.createAndAppend('span', labelObj.title, ["col-md-3", "labels", "pull-left"], labelDiv); // Label Text Span - + let inputDiv = this.createAndAppend('div', '', ["col-md-9", "pull-left"], rowDiv); let inputElement; diff --git a/control/languages/styles/bf_base.css b/control/languages/styles/bf_base.css index a00bf62..c2b1993 100644 --- a/control/languages/styles/bf_base.css +++ b/control/languages/styles/bf_base.css @@ -52,6 +52,13 @@ h4, h5, h6 { margin-top: 0; } +.section-sub-title { + font-size: 16px; + color: var(--c-info); + margin-bottom: 2rem; + margin-top: 2rem; +} + .text-secondary { color: var(--c-gray6); } diff --git a/widget/app.service.js b/widget/app.service.js index b9207c6..9f2df56 100644 --- a/widget/app.service.js +++ b/widget/app.service.js @@ -12,10 +12,12 @@ .factory('Location', [function () { var _location = location; return { - go: function (path) { + go: function (path, pushToHistory = true) { _location.href = path; let label = path.includes('thread') ? 'thread' : path.includes('members') ? 'members' : 'report'; - buildfire.history.push(label, {}); + if (pushToHistory) { + buildfire.history.push(label, {}); + } }, goToHome: function () { _location.href = _location.href.substr(0, _location.href.indexOf('#')); @@ -134,8 +136,23 @@ console.error('Error decoding deepLinkData:', error); return null; } + }, + evaluateExpression(expression) { + return new Promise((resolve, reject) => { + buildfire.dynamic.expressions.evaluate({expression}, (err, result) => { + if (err) return reject(err); + resolve(result.evaluatedExpression); + }); + }) + }, + setExpression(expression) { + buildfire.dynamic.expressions.getContext = (options, callback) => { + const context = { + plugin: expression + } + callback(null, context) + } } - } }]) .factory("SubscribedUsersData", function () { @@ -706,7 +723,7 @@ } } }]) - .factory('SocialItems', ['Util', '$rootScope', function (Util, $rootScope) { + .factory('SocialItems', ['Util', '$rootScope', '$timeout', function (Util, $rootScope, $timeout) { var _this; var SocialItems = function () { _this = this; @@ -836,9 +853,8 @@ if (error) return console.log(error); if (data && data.result.length) { - const result = data.result.filter(item => !_this.items.find(_item => _item.id === item.id)); + const result = data.result.filter(newItem => !_this.items.some(existItem => existItem.id === newItem.id)); const newItems = result.map(item => { - _this.setupImageList(item.data); return {...item.data, id: item.id}; }); _this.items = _this.items.concat(newItems); @@ -869,6 +885,10 @@ }); } + SocialItems.prototype.getPostById = function (id, callback) { + buildfire.publicData.getById(id, "posts", callback); + } + function getSort() { if (_this.indexingUpdateDone) return { @@ -920,16 +940,15 @@ return filter; } - SocialItems.prototype.setupImageList = function(post) { - post.imageListId = "imageList_" + post.id; - if (post.imageUrl) { - setTimeout(function () { - let imageList = document.getElementById(post.imageListId); + SocialItems.prototype.setupImageList = function(listId, item) { + if (item.imageUrl) { + $timeout(() => { + let imageList = document.getElementById(listId); if (!imageList) return; - if (Array.isArray(post.imageUrl)) { - imageList.images = post.imageUrl; + if (Array.isArray(item.imageUrl)) { + imageList.images = item.imageUrl; } else { - imageList.images = [post.imageUrl]; + imageList.images = [item.imageUrl]; } imageList.addEventListener('imageSelected', (e) => { let selectedImage = e.detail.filter(image => image.selected); @@ -939,13 +958,16 @@ images: selectedImage }); }); - }, 0); + }); } }; function startBackgroundService() { if (!_this.newPostTimerChecker) { _this.newPostTimerChecker = setInterval(function () { + if (_this.items.length > _this.pageSize) { + return clearInterval(_this.newPostTimerChecker); + } let searchOptions = { filter: getFilter(), sort: { @@ -963,11 +985,10 @@ if (results.totalRecord > _this.pageSize) { _this.showMorePosts = true; } else _this.showMorePosts = false; - + if (data && data.length) { let items = data.map(item => { const existItem = _this.items.find(_item => _item.id === item.id) || {}; - _this.setupImageList(item.data); return {...existItem, ...item.data, id: item.id}; }); @@ -1015,16 +1036,30 @@ delete stringsCopy[defaultKey].labels; }); let strings = {} - strings = Object.assign({}, stringsCopy.mainWall, stringsCopy.sideThread, stringsCopy.members, stringsCopy.input, stringsCopy.modal); + for (let key in stringsConfig) { + strings = Object.assign(strings, stringsCopy[key]); + } Object.keys(strings).forEach(e => { strings[e].value ? _this.languages[e] = strings[e].value : _this.languages[e] = strings[e].defaultValue; }); } else { let strings = {}; - if (response.data && response.data.mainWall && response.data.sideThread && response.data.members && response.data.input && response.data.modal) + if (response.data && response.data.mainWall && response.data.sideThread && response.data.members && response.data.input && response.data.modal) { strings = Object.assign({}, response.data.mainWall, response.data.sideThread, response.data.members, response.data.input, response.data.modal); - else - strings = Object.assign({}, stringsConfig.mainWall.labels, stringsConfig.sideThread.labels, stringsConfig.members.labels, stringsConfig.input.labels, stringsConfig.modal.labels); + + const newProperties = ['pushNotifications']; + newProperties.forEach((key) => { + if (response.data[key]) { + strings = Object.assign(strings, response.data[key]); + } else { + strings = Object.assign(strings, stringsConfig[key].labels); + } + }); + } else { + for (let key in stringsConfig) { + strings = Object.assign(strings, stringsCopy[key].labels); + } + } Object.keys(strings).forEach(e => { if (e == "specificChat" && strings[e].value == "") _this.languages[e] = strings[e].value diff --git a/widget/assets/js/shared/stringsConfig.js b/widget/assets/js/shared/stringsConfig.js index b2bc871..c48f445 100644 --- a/widget/assets/js/shared/stringsConfig.js +++ b/widget/assets/js/shared/stringsConfig.js @@ -185,5 +185,108 @@ const stringsConfig = { } } }, + pushNotifications: { + title: "Push Notifications", + labels: { + personalNotificationMessageTitle: { + title: "Title" + , subtitle: "Private Message Notification" + , placeholder: "New Private Message" + , maxLength: 25 + , defaultValue: "New Private Message" + }, + personalNotificationMessageBody: { + title: "Body" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} sent you a private message." + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} sent you a private message." + }, + personalInAppMessageBody: { + title: "In App Message" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} sent you a private message." + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} sent you a private message." + }, + publicNotificationMessageTitle: { + title: "Title" + , subtitle: "New Post Notification" + , placeholder: "New Post" + , maxLength: 25 + , defaultValue: "New Post" + }, + publicNotificationMessageBody: { + title: "Body" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} added a new post on ${context.plugin.title}" + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} added a new post on ${context.plugin.title}" + }, + publicInAppMessageBody: { + title: "In App Message" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} added a new post on ${context.plugin.title}" + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} added a new post on ${context.plugin.title}" + }, + + commentNotificationMessageTitle: { + title: "Title" + , subtitle: "New Comment Notification" + , placeholder: "New Comment" + , maxLength: 25 + , defaultValue: "New Comment" + }, + commentNotificationMessageBody: { + title: "Body" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} commented on a post on ${context.plugin.title}" + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} commented on a post on ${context.plugin.title}" + }, + commentInAppMessageBody: { + title: "In App Message" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} commented on a post on ${context.plugin.title}" + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} commented on a post on ${context.plugin.title}" + }, + + postLikeNotificationTitle: { + title: "Title" + , subtitle: "Post Like Notification" + , placeholder: "Post Like" + , maxLength: 25 + , defaultValue: "Post Like" + }, + postLikeNotificationMessageBody: { + title: "Body" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} liked your post." + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} liked your post." + }, + postLikeInAppMessageBody: { + title: "In App Message" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} liked your post." + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} liked your post." + }, + + commentLikeNotificationTitle: { + title: "Title" + , subtitle: "Comment Like Notification" + , placeholder: "Comment Like" + , maxLength: 25 + , defaultValue: "Comment Like" + }, + commentLikeNotificationMessageBody: { + title: "Body" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} liked your comment." + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} liked your comment." + }, + commentLikeInAppMessageBody: { + title: "In App Message" + , placeholder: "${context.appUser?context.appUser.displayName:'Someone'} liked your comment." + , maxLength: 150 + , defaultValue: "${context.appUser?context.appUser.displayName:'Someone'} liked your comment." + }, + } + }, }; diff --git a/widget/controllers/widget.thread.controller.js b/widget/controllers/widget.thread.controller.js index 8d24d53..4eba870 100644 --- a/widget/controllers/widget.thread.controller.js +++ b/widget/controllers/widget.thread.controller.js @@ -23,28 +23,6 @@ type: 'list-item-avatar, list-item-two-line' }); - var counter = 0; - $scope.setupImageList = function (comment) { - if (comment.imageUrl.length) { - comment.imageListId = "commentImageList_" + (counter++); - setTimeout(function () { - let imageList = document.getElementById(comment.imageListId); - if (Array.isArray(comment.imageUrl)) { - imageList.images = comment.imageUrl; - } else { - imageList.images = [comment.imageUrl[0]] - } - imageList.addEventListener('imageSelected', (e) => { - let selectedImage = e.detail.filter(image => image.selected); - if (selectedImage && selectedImage[0] && selectedImage[0].name) - selectedImage[0].name = selectedImage[0].name; - buildfire.imagePreviewer.show({ - images: selectedImage - }); - }); - }, 0); - } - }; Thread.showHideCommentBox = function () { if (Thread.SocialItems && Thread.SocialItems.appSettings && Thread.SocialItems.appSettings.allowSideThreadTags && Thread.SocialItems.appSettings.sideThreadUserTags && Thread.SocialItems.appSettings.sideThreadUserTags.length > 0 @@ -501,28 +479,43 @@ sendToSelf: false }; - if (text === 'comment') { - options.users = [Thread.post.userId]; - options.text = Thread.SocialItems.getUserName(Thread.SocialItems.userDetails) + ' commented on post: ' + Thread.SocialItems.context.title; - } - else if (text === 'likedComment'){ - options.users = [post.userId]; - options.text = Thread.SocialItems.getUserName(Thread.SocialItems.userDetails) + ' liked a comment on ' + Thread.SocialItems.context.title; + Util.setExpression({title: Thread.SocialItems.context.title}); + + let titleKey, messageKey, inAppMessageKey; + if (text === 'likedComment') { + options.users = [post.userId]; + titleKey = Thread.SocialItems.languages.commentLikeNotificationTitle; + messageKey = Thread.SocialItems.languages.commentLikeNotificationMessageBody; + inAppMessageKey = Thread.SocialItems.languages.commentLikeInAppMessageBody; + } else if (text === 'likedPost') { + options.users = [Thread.post.userId]; + titleKey = Thread.SocialItems.languages.postLikeNotificationTitle; + messageKey = Thread.SocialItems.languages.postLikeNotificationMessageBody; + inAppMessageKey = Thread.SocialItems.languages.postLikeInAppMessageBody; + } else if (text === 'comment') { + options.users = [Thread.post.userId]; + titleKey = Thread.SocialItems.languages.commentNotificationMessageTitle; + messageKey = Thread.SocialItems.languages.commentNotificationMessageBody; + inAppMessageKey = Thread.SocialItems.languages.commentInAppMessageBody; } - else if (text === 'likedPost'){ - options.users = [Thread.post.userId]; - options.text = Thread.SocialItems.getUserName(Thread.SocialItems.userDetails) + ' liked a post on ' + Thread.SocialItems.context.title; - } - options.inAppMessage = options.text; + if (Thread.SocialItems.wid) { options.queryString = `&dld=${encodeURIComponent(JSON.stringify({wid: Thread.SocialItems.wid}))}` } else { options.queryString = `&dld=${encodeURIComponent(JSON.stringify({postId: Thread.post.id}))}` } - buildfire.notifications.pushNotification.schedule(options, function (err) { - if (err) return console.error('Error while setting PN schedule.', err); - console.log("SENT NOTIFICATION", options); - }); + + Promise.all([Util.evaluateExpression(titleKey), Util.evaluateExpression(messageKey), Util.evaluateExpression(inAppMessageKey)]) + .then(([title, message, inAppMessage]) => { + options.title = title; + options.text = message; + options.inAppMessage = inAppMessage; + + buildfire.notifications.pushNotification.schedule(options, function (err) { + if (err) return console.error('Error while setting PN schedule.', err); + console.log("SENT NOTIFICATION", options); + }); + }) } } }); diff --git a/widget/controllers/widget.wall.controller.js b/widget/controllers/widget.wall.controller.js index 93db5fd..1db0121 100644 --- a/widget/controllers/widget.wall.controller.js +++ b/widget/controllers/widget.wall.controller.js @@ -31,13 +31,18 @@ type: 'list-item-avatar, list-item-two-line, image'}); WidgetWall.startSkeleton = function () { + if (!WidgetWall.skeletonActive) { WidgetWall.skeleton.start(); WidgetWall.skeletonActive = true; + } } WidgetWall.stopSkeleton = function () { + WidgetWall.postsLoaded = true; + if (WidgetWall.skeletonActive) { WidgetWall.skeleton.stop(); WidgetWall.skeletonActive = false; + } } WidgetWall.showHideCommentBox = function () { @@ -155,9 +160,7 @@ WidgetWall.getPosts = function (callback = null) { WidgetWall.SocialItems.getPosts(function (err, data) { - WidgetWall.postsLoaded = true; WidgetWall.showUserLikes(); - WidgetWall.stopSkeleton(); window.buildfire.messaging.sendMessageToControl({ name: 'SEND_POSTS_TO_CP', posts: WidgetWall.SocialItems.items, @@ -325,12 +328,9 @@ sendToSelf: false }; - if (text === 'post') - options.text = WidgetWall.SocialItems.getUserName(WidgetWall.SocialItems.userDetails) + ' added new post on ' + WidgetWall.SocialItems.context.title; - else if (text === 'like') - options.text = WidgetWall.SocialItems.getUserName(WidgetWall.SocialItems.userDetails) + ' liked a post on ' + WidgetWall.SocialItems.context.title; + if (text === 'like' && post.userId === WidgetWall.SocialItems.userDetails.userId) return; - options.inAppMessage = options.text; + util.setExpression({ title: WidgetWall.SocialItems.context.title }); const queryStringObj = {}; if (WidgetWall.SocialItems.wid) { @@ -344,66 +344,93 @@ queryStringObj.wTitle = WidgetWall.SocialItems.pluginTitle; } - if (text === 'like' && post.userId === WidgetWall.SocialItems.userDetails.userId) return; - + let titleKey, messageKey, inAppMessageKey; if (WidgetWall.SocialItems.isPrivateChat) { + if (text === 'post') { + titleKey = WidgetWall.SocialItems.languages.personalNotificationMessageTitle; + messageKey = WidgetWall.SocialItems.languages.personalNotificationMessageBody; + inAppMessageKey = WidgetWall.SocialItems.languages.personalInAppMessageBody; + } else if (text === 'like') { + titleKey = WidgetWall.SocialItems.languages.postLikeNotificationTitle; + messageKey = WidgetWall.SocialItems.languages.postLikeNotificationMessageBody; + inAppMessageKey = WidgetWall.SocialItems.languages.postLikeInAppMessageBody; + } + Promise.all([util.evaluateExpression(titleKey), util.evaluateExpression(messageKey), util.evaluateExpression(inAppMessageKey)]) + .then(([title, message, inAppMessage]) => { + options.title = title; + options.text = message; + options.inAppMessage = inAppMessage; + + let userIdsTosSend = []; + if (WidgetWall.SocialItems.userIds) { + queryStringObj.userIds = WidgetWall.SocialItems.userIds; + + const userIds = WidgetWall.SocialItems.userIds.split(',').filter((userId) => userId !== WidgetWall.SocialItems.userDetails.userId); + userIdsTosSend = userIds; + } else { + const user1Id = WidgetWall.SocialItems.wid.slice(0, 24); + const user2Id = WidgetWall.SocialItems.wid.slice(24, 48); + let userToSend = user1Id === WidgetWall.SocialItems.userDetails.userId ? + user2Id : user1Id; + userIdsTosSend.push(userToSend); + queryStringObj.userIds = [user1Id, user2Id]; + } - let userIdsTosSend = []; - if (WidgetWall.SocialItems.userIds) { - queryStringObj.userIds = WidgetWall.SocialItems.userIds; - - const userIds = WidgetWall.SocialItems.userIds.split(',').filter((userId) => userId !== WidgetWall.SocialItems.userDetails.userId); - userIdsTosSend = userIds; - } else { - const user1Id = WidgetWall.SocialItems.wid.slice(0, 24); - const user2Id = WidgetWall.SocialItems.wid.slice(24, 48); - let userToSend = user1Id === WidgetWall.SocialItems.userDetails.userId ? - user2Id : user1Id; - userIdsTosSend.push(userToSend); - queryStringObj.userIds = [user1Id, user2Id]; - } - - options.queryString =`&dld=${encodeURIComponent(JSON.stringify({...queryStringObj }))}` - - for (const userToSend of userIdsTosSend) { - SubscribedUsersData.getGroupFollowingStatus(userToSend, WidgetWall.SocialItems.wid, WidgetWall.SocialItems.context.instanceId, function (err, status) { - if (err) console.error('Error while getting initial group following status.', err); - if (status.length && status[0].data && !status[0].data.leftWall) { - options.users.push(userToSend); - options.text = WidgetWall.SocialItems.getUserName(WidgetWall.SocialItems.userDetails) + ' added new post on ' + - WidgetWall.SocialItems.getUserName(WidgetWall.SocialItems.userDetails) + ' | ' + WidgetWall.SocialItems.getUserName(status[0].data.userDetails); - - buildfire.notifications.pushNotification.schedule(options, function (err) { - - if (err) return console.error('Error while setting PN schedule.', err); - - }); - } else if (!status.length && WidgetWall.SocialItems.appSettings.allowAutoSubscribe) { - buildfire.auth.getUserProfile({ - userId: userToSend - }, (err, user) => { - if (err || !user) return console.error(err); - options.users.push(userToSend); - options.text = WidgetWall.SocialItems.getUserName(WidgetWall.SocialItems.userDetails) + ' added new post on ' + - WidgetWall.SocialItems.getUserName(WidgetWall.SocialItems.userDetails) + ' | ' + WidgetWall.SocialItems.getUserName(user); - buildfire.notifications.pushNotification.schedule(options, function (err) { - if (err) return console.error('Error while setting PN schedule.', err); - console.log("SENT NOTIFICATION", options); - }); - }); - } - }); - } + options.queryString =`&dld=${encodeURIComponent(JSON.stringify({...queryStringObj }))}` + + for (const userToSend of userIdsTosSend) { + SubscribedUsersData.getGroupFollowingStatus(userToSend, WidgetWall.SocialItems.wid, WidgetWall.SocialItems.context.instanceId, function (err, status) { + if (err) console.error('Error while getting initial group following status.', err); + if (status.length && status[0].data && !status[0].data.leftWall) { + options.users.push(userToSend); + + buildfire.notifications.pushNotification.schedule(options, function (err) { + if (err) return console.error('Error while setting PN schedule.', err); + }); + } else if (!status.length && WidgetWall.SocialItems.appSettings.allowAutoSubscribe) { + buildfire.auth.getUserProfile({ + userId: userToSend + }, (err, user) => { + if (err || !user) return console.error(err); + options.users.push(userToSend); + + buildfire.notifications.pushNotification.schedule(options, function (err) { + if (err) return console.error('Error while setting PN schedule.', err); + }); + }); + } + }); + } + }) } else { - options.queryString =`&dld=${encodeURIComponent(JSON.stringify({...queryStringObj }))}` - if (text === 'like') { - options.users.push(post.userId); - } else options.groupName = WidgetWall.SocialItems.wid === '' ? - WidgetWall.SocialItems.context.instanceId : WidgetWall.SocialItems.wid - buildfire.notifications.pushNotification.schedule(options, function (err) { - if (err) return console.error('Error while setting PN schedule.', err); - console.log("SENT NOTIFICATION", options); - }); + if (text === 'post') { + titleKey = WidgetWall.SocialItems.languages.publicNotificationMessageTitle; + messageKey = WidgetWall.SocialItems.languages.publicNotificationMessageBody; + inAppMessageKey = WidgetWall.SocialItems.languages.publicInAppMessageBody; + } else if (text === 'like') { + titleKey = WidgetWall.SocialItems.languages.postLikeNotificationTitle; + messageKey = WidgetWall.SocialItems.languages.postLikeNotificationMessageBody; + inAppMessageKey = WidgetWall.SocialItems.languages.postLikeInAppMessageBody; + options.users.push(post.userId); + } + Promise.all([util.evaluateExpression(titleKey), util.evaluateExpression(messageKey), util.evaluateExpression(inAppMessageKey)]) + .then(([title, message, inAppMessage]) => { + options.title = title; + options.text = message; + options.inAppMessage = inAppMessage; + + options.queryString =`&dld=${encodeURIComponent(JSON.stringify({...queryStringObj }))}` + if (WidgetWall.SocialItems.wid) { + options.groupName = WidgetWall.SocialItems.wid; + } else { + options.groupName = WidgetWall.SocialItems.context.instanceId; + } + + buildfire.notifications.pushNotification.schedule(options, function (err) { + if (err) return console.error('Error while setting PN schedule.', err); + console.log("SENT NOTIFICATION", options); + }); + }) } } @@ -529,7 +556,6 @@ WidgetWall.SocialItems.getSettings((err, result) => { if (err) { WidgetWall.stopSkeleton(); - WidgetWall.postsLoaded = true; return console.error("Fetching settings failed.", err); } if (result) { @@ -543,11 +569,15 @@ if (res) WidgetWall.SocialItems.blockedUsers = res; WidgetWall.SocialItems.authenticateUserWOLogin(null, (err, user) => { - if (err) return console.error("Getting user failed.", err); + if (err) { + WidgetWall.stopSkeleton(); + return console.error("Getting user failed.", err); + } WidgetWall.getPosts(()=>{ if (user) { WidgetWall.checkFollowingStatus(user); WidgetWall.checkForPrivateChat(); + WidgetWall.checkForDeeplinks(); } else { WidgetWall.groupFollowingStatus = false; } @@ -560,19 +590,36 @@ WidgetWall.init(); - WidgetWall.handleDeepLinkActions = function (deeplinkData){ + WidgetWall.handleDeepLinkActions = function (deeplinkData, pushToHistory){ if (deeplinkData) { if (deeplinkData.fromReportAbuse) { WidgetWall.SocialItems.reportData = deeplinkData; $rootScope.showThread = false; $timeout(function () { - Location.go('#/report'); + Location.go('#/report', pushToHistory); + if (pushToHistory) { + WidgetWall.stopSkeleton(); + } }); return; } if (deeplinkData.postId) { - WidgetWall.goInToThread(deeplinkData.postId); - return; + let isPostExist = WidgetWall.SocialItems.items.find(post => post.id === deeplinkData.postId); + if (isPostExist) { + return WidgetWall.goInToThread(deeplinkData.postId, pushToHistory); + } else { + return WidgetWall.SocialItems.getPostById(deeplinkData.postId, (err, res) => { + if (err) { + WidgetWall.stopSkeleton(); + console.error(err); + } else if (res && res.data && res.id) { + WidgetWall.SocialItems.items.push({...res.data, id: res.id}); + WidgetWall.goInToThread(deeplinkData.postId, pushToHistory); + } else { + WidgetWall.stopSkeleton(); + } + }); + } } const wallId = deeplinkData.wid const userIds = deeplinkData.userIds; @@ -587,6 +634,10 @@ } else { WidgetWall.openGroupChat(userIds, wallId, wTitle); } + WidgetWall.SocialItems.items = []; + WidgetWall.stopSkeleton(); + } else { + WidgetWall.stopSkeleton(); } } @@ -616,19 +667,21 @@ } }); } + } - if (!WidgetWall.deeplinkHandled){ - Buildfire.deeplink.getData((data) => { - WidgetWall.deeplinkHandled = true; - const deeplinkData = WidgetWall.util.parseDeeplinkData(data); - WidgetWall.handleDeepLinkActions(deeplinkData); - }, true); - } - - Buildfire.deeplink.onUpdate((data) => { - const deeplinkData = WidgetWall.util.parseDeeplinkData(data); - WidgetWall.handleDeepLinkActions(deeplinkData); - }, true); + WidgetWall.checkForDeeplinks = function () { + if (!WidgetWall.deeplinkHandled){ + Buildfire.deeplink.getData((data) => { + WidgetWall.deeplinkHandled = true; + const deeplinkData = WidgetWall.util.parseDeeplinkData(data); + WidgetWall.handleDeepLinkActions(deeplinkData, false); + }, true); + } + + Buildfire.deeplink.onUpdate((data) => { + const deeplinkData = WidgetWall.util.parseDeeplinkData(data); + WidgetWall.handleDeepLinkActions(deeplinkData, true); + }, true); } WidgetWall.sanitizeWall = function (callback) { @@ -715,7 +768,9 @@ showLabelInTitlebar: true }); - WidgetWall.getPosts(); + WidgetWall.getPosts(() => { + document.getElementById('top').scrollTop = 0 + }); } $rootScope.$on('loadPrivateChat', function (event, error) { @@ -1068,7 +1123,6 @@ _id: postData.userDetails && postData.userDetails.userId ? postData.userDetails.userId : null }, postData.text, () => SocialDataStore.createPost(postData).then((response) => { - WidgetWall.SocialItems.setupImageList(postData); WidgetWall.SocialItems.items.unshift(postData); Buildfire.messaging.sendMessageToControl({ name: EVENTS.POST_CREATED, @@ -1268,13 +1322,19 @@ return moment(timestamp.toString()).fromNow(); }; - WidgetWall.goInToThread = function (threadId) { + WidgetWall.goInToThread = function (threadId, pushToHistory) { WidgetWall.SocialItems.authenticateUser(null, (err, user) => { - if (err) return console.error("Getting user failed.", err); + if (err) { + WidgetWall.stopSkeleton(); + return console.error("Getting user failed.", err); + } if (user) { WidgetWall.checkFollowingStatus(null , ()=>{ if (threadId && !WidgetWall.SocialItems.userBanned) { - Location.go('#/thread/' + threadId); + Location.go('#/thread/' + threadId, pushToHistory); + } + if (pushToHistory) { + WidgetWall.stopSkeleton(); } }); } diff --git a/widget/index.html b/widget/index.html index 2a2165e..2922329 100644 --- a/widget/index.html +++ b/widget/index.html @@ -13,7 +13,7 @@ - + @@ -57,11 +57,8 @@
diff --git a/widget/templates/thread.html b/widget/templates/thread.html index e8823a1..208ab6d 100644 --- a/widget/templates/thread.html +++ b/widget/templates/thread.html @@ -1,7 +1,7 @@