Skip to content

Commit

Permalink
fix duplicates features when shared.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiba-Almade committed Nov 24, 2022
1 parent 4b7a459 commit 3b846eb
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions widget/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
});
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -994,6 +994,7 @@ function subscribeToGroup(data) {
}
if (result && result.length > 0) {
getData();
navigateTo(result)
}
else {
const topic = new Topic({
Expand All @@ -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);
Expand Down

0 comments on commit 3b846eb

Please sign in to comment.