From 3b846eb52f7b56db8c461e24341b2f175d0c7452 Mon Sep 17 00:00:00 2001 From: Hiba-Almade Date: Thu, 24 Nov 2022 16:28:25 +0300 Subject: [PATCH] fix duplicates features when shared. --- widget/app.js | 56 ++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/widget/app.js b/widget/app.js index 2b8f6d7..d5b136e 100644 --- a/widget/app.js +++ b/widget/app.js @@ -142,7 +142,6 @@ function updateRecordsForSorting() { allItems.map(item => { item.data.titleIndex = item.data.title.toLowerCase(); buildfire.userData.update(item.id, item.data, "topics", (err, res) => { - console.log(res) }) }); } @@ -534,16 +533,16 @@ function getBreadcrumbs() { if (err) reject(err); let homeBreadcrumb = null; breadcrumbs.map(bread => { - if (bread.label === "Home") { + if (bread?.label === "Home") { bread.label = context.title; homeBreadcrumb = bread; pluginBreadCrumbs.push(bread); } - if (bread.options.instanceId === context.instanceId) { + if (bread?.options.instanceId === context.instanceId) { pluginBreadCrumbs.push(bread); } - if (bread.label === context.title) { - if (bread.label !== homeBreadcrumb.label) { + if (bread?.label === context.title) { + if (bread?.label !== homeBreadcrumb?.label) { pluginBreadCrumbs.push(bread); } } @@ -942,50 +941,51 @@ function setStrings() { } function shareWithOthers(data) { - console.log(data) - let link = {}; - link.title = data.title; - link.type = "website"; - link.description = "Join group"; let toShare = {}; - toShare.title = data.title; - toShare.createdBy = { _id: data.createdBy._id }; - toShare.privacy = data.privacy; - toShare.type = data.type; - console.log(toShare); - link.data = { - toShare + toShare.data = { + id: data.id, + title: data.title, + privacy: data.privacy, + createdById: data.createdBy._id, + parentTopicId: data.parentTopicId, + type: data.type, }; - - buildfire.deeplink.generateUrl(link, function (err, result) { + buildfire.deeplink.generateUrl(toShare, function (err, result) { if (err) { console.error(err) } else { buildfire.device.share({ - subject: link.title, - text: link.description, - image: 'http://myImageUrl', + subject: data.title, + text: "Join group", link: result.url }, function (err, result) { if (err) console.log(err) else console.log(result) - Helper.trackAction(Helper.EVENTS.TOPIC_SHEARED); + Helper.trackAction(Helper.EVENTS.TOPIC_SHEARED); }); } }); } function subscribeToGroup(data) { - let group = data.toShare; - if (group.privacy === 'public') return getData(); - if (group.createdBy._id === loggedUser._id) return getData(); + let group = data.data; + if (group?.privacy === 'public') { + getData(); + navigateTo(data); + return; + } + if (group?.createdById === loggedUser._id) { + getData(); + navigateTo(data); + return; + } let searchOptions = {} searchOptions.filter = { $and: [ { '$json.createdBy._id': loggedUser._id }, - { '$json.title': group.title }, + { '$json.title': group?.title }, ] } buildfire.userData.search(searchOptions, 'topics', function (err, result) { @@ -994,6 +994,7 @@ function subscribeToGroup(data) { } if (result && result.length > 0) { getData(); + navigateTo(result) } else { const topic = new Topic({ @@ -1008,6 +1009,7 @@ function subscribeToGroup(data) { .then((result => { showMessage(`You have been added to ${topic.title} topic`) getData(); + navigateTo(result); })) .catch(err => { console.error(err);