Skip to content

Commit

Permalink
Merge pull request #158 from BuildFire/fix/handle-deeplink
Browse files Browse the repository at this point in the history
fix(deeplinks): handle deeplink data
  • Loading branch information
mas-iota authored Feb 28, 2025
2 parents 9d7c922 + fbb5284 commit 9c4c79f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 25 deletions.
40 changes: 35 additions & 5 deletions widget/app.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
if (currentTime) {
lastAnalyticsTime = currentTime;
}

if (!analyticsTrackingInterval) {
analyticsTrackingInterval = setInterval(() => {
lastAnalyticsTime += 5;
Expand Down Expand Up @@ -251,7 +251,37 @@
}
}

return { getImageUrl }
function decodeObject(obj) {
if (typeof obj === 'string') return decodeURIComponent(obj);
// If the input is not an object or is null, return it as is
if (typeof obj !== 'object' || obj === null) {
return obj;
}

// If the input is an array, iterate over its elements
if (Array.isArray(obj)) {
return obj.map(item => decodeObject(item));
}

// If the input is an object, iterate over its properties
const decodedObj = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
const value = obj[key];

// If the value is a string, decode it
if (typeof value === 'string') {
decodedObj[key] = decodeURIComponent(value);
} else {
// If the value is an object or array, recursively decode it
decodedObj[key] = decodeObject(value);
}
}
}
return decodedObj;
}

return { getImageUrl, decodeObject };
}])

/**
Expand All @@ -274,11 +304,11 @@
link.title = item.title;
link.description = item.title + ", by " + item.author;
link.imageUrl = item.image && item.image.url ? item.image.url : null;

link.data = {
link: item.guid,
};

buildfire.deeplink.generateUrl(link, (err, result) => {
if (err) {
console.error(err);
Expand All @@ -300,4 +330,4 @@
share: _share
};
});
})(window.angular, window.buildfire, window._);
})(window.angular, window.buildfire, window._);
44 changes: 24 additions & 20 deletions widget/controllers/widget.home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
(function (angular) {
angular
.module('mediaCenterRSSPluginWidget')
.controller('WidgetHomeCtrl', ['$scope', 'DataStore', 'Buildfire', 'FeedParseService', 'TAG_NAMES', 'ItemDetailsService', 'Location', '$filter', 'Underscore', '$rootScope', 'FEED_IMAGES', 'trackAnalyticsActions', 'utils',
.controller('WidgetHomeCtrl', ['$scope', 'DataStore', 'Buildfire', 'FeedParseService', 'TAG_NAMES', 'ItemDetailsService', 'Location', '$filter', 'Underscore', '$rootScope', 'FEED_IMAGES', 'trackAnalyticsActions', 'utils',
function ($scope, DataStore, Buildfire, FeedParseService, TAG_NAMES, ItemDetailsService, Location, $filter, Underscore, $rootScope, FEED_IMAGES, trackAnalyticsActions, utils) {

if (window.device) {
Expand Down Expand Up @@ -37,7 +37,7 @@
function extractItemFromFeeds(feeds = {}, itemId) {
if (!feeds || typeof feeds !== 'object' || !itemId) return null;
let itemData = null;

Object.keys(feeds).forEach(key => {
if (feeds[key].items && feeds[key].items.length) {
let feedItem = feeds[key].items.find(el => el.guid == itemId);
Expand All @@ -49,7 +49,7 @@
});
return itemData;
}

$scope.deeplinkData = null;
$scope.isDeeplinkItemOpened = false;
$scope.first = true;
Expand All @@ -69,7 +69,7 @@
...data.feed,
guid: data.link,
imageSrcUrl: data.feed.image_url ,
pubDate: data.feed.publish_date
pubDate: data.feed.publish_date
};
WidgetHome.proceedToItem(-1, item, pushToHistory);
} else if (data.link) {
Expand Down Expand Up @@ -112,12 +112,12 @@
}
}

/**
/**
* Private variables
*
* @name _items used to hold RSS feed items and helps in lazy loading.
* @type {object}
* @private
* @type {object}
* @private
*
* @name limit used to load a number of items in list on scroll
* @type {number}
Expand Down Expand Up @@ -178,12 +178,16 @@
};

// show the deeplink skeleton if the deeplink is present
buildfire.deeplink.getData(function (data) {
if (!data) return;
try {
buildfire.deeplink.getData(function (data) {
if (!data) return;

$scope.deeplinkData = data;
toggleDeeplinkSkeleton(true);
});
$scope.deeplinkData = utils.decodeObject(data);
toggleDeeplinkSkeleton(true);
});
} catch (e) {
console.error('Error getting deeplink data', e);
}
buildfire.deeplink.onUpdate(function (data) {
if (!data) return;

Expand All @@ -194,7 +198,7 @@
}
});

/**
/**
* @name WidgetHome.data is used to hold user's data object which used throughout the app.
* @type {object}
*/
Expand All @@ -210,7 +214,7 @@
*/
WidgetHome.items = [];

/**
/**
* @name WidgetHome.busy is used to disable ng-infinite scroll when more data not available to show.
* @type {boolean}
*/
Expand Down Expand Up @@ -287,13 +291,13 @@
isInit = false;

function checkFeedEquality(currentItems, fetchedItems) {

if (!currentItems[0] || !currentItems[0].guid) return false;

var sameLength = currentItems.length === fetchedItems.length;
var firstItemUnchanged = currentItems[0].guid === fetchedItems[0].guid;
var lastItemUnchanged = currentItems[currentItems.length - 1].guid === fetchedItems[fetchedItems.length - 1].guid;

return sameLength && firstItemUnchanged && lastItemUnchanged;
}
};
Expand Down Expand Up @@ -452,7 +456,7 @@
WidgetHome.loading = true;
if (!$scope.$$phase) $scope.$digest();
}

WidgetHome.fetchFeedResults(feed).then((result) => {
let isChanged = !WidgetHome.checkFeedEquality(WidgetHome.feedsCache[feed.id].items ?? [], result.data.items);
WidgetHome.feedsCache[feed.id] = {
Expand All @@ -466,7 +470,7 @@

if (isChanged) WidgetHome.renderFeedItems();
WidgetHome.loading = false;

if (Object.keys(WidgetHome.feedsData).length === WidgetHome.data.content.feeds.length) WidgetHome.dataTotallyLoaded = true;

if (!$scope.$$phase) $scope.$digest();
Expand Down Expand Up @@ -548,7 +552,7 @@
if (WidgetHome.isItems) {
WidgetHome.loading = false;
}

WidgetHome.handleInitialParsing();
}).catch((err) => {
console.error(err)
Expand Down Expand Up @@ -789,4 +793,4 @@

}
]);
})(window.angular);
})(window.angular);

0 comments on commit 9c4c79f

Please sign in to comment.