From a48c2be6fa5c0cfdb3ec6d19dd3bef81c5ea275d Mon Sep 17 00:00:00 2001 From: DM Date: Wed, 13 Dec 2023 20:00:31 +0800 Subject: [PATCH] feat: filter out duplicate data in the following list, based on the address --- packages/site/.env.development | 2 +- packages/site/src/pages/monitor/list.tsx | 2 +- packages/snap/snap.manifest.json | 2 +- packages/snap/src/fetch.ts | 4 ++-- packages/snap/src/index.ts | 2 ++ packages/snap/src/utils/activitiy.ts | 22 ++++++++++++++++++++-- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/site/.env.development b/packages/site/.env.development index 51d4564..7ef2996 100644 --- a/packages/site/.env.development +++ b/packages/site/.env.development @@ -2,4 +2,4 @@ * To use this, rename to $(.env.production) and set the production SNAP_ORIGIN here */ SNAP_ORIGIN=local:http://localhost:8080 -ENVIRONMENT=production +ENVIRONMENT=development diff --git a/packages/site/src/pages/monitor/list.tsx b/packages/site/src/pages/monitor/list.tsx index 1b1317b..d6703c9 100644 --- a/packages/site/src/pages/monitor/list.tsx +++ b/packages/site/src/pages/monitor/list.tsx @@ -30,7 +30,7 @@ const MonitorList = () => { const [monitorList, setMonitorList] = useState([]); const handleGetState = async () => { const snapState = await sendGetState(); - // console.log(snapState); + console.log(snapState); }; useEffect(() => { diff --git a/packages/snap/snap.manifest.json b/packages/snap/snap.manifest.json index c67a6e9..a4b6451 100644 --- a/packages/snap/snap.manifest.json +++ b/packages/snap/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/NaturalSelectionLabs/RSS3-Social-Notifier-Snap.git" }, "source": { - "shasum": "UQMSWUeez7d4pWGO4PTKV0FEFuWExXKgWHgpWIjIDnQ=", + "shasum": "9RFzIrzPKGZ+8Mz0KVZLP+3Cety8ZE16twEnLfs2FgU=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snap/src/fetch.ts b/packages/snap/src/fetch.ts index cb30f18..b22b0b2 100644 --- a/packages/snap/src/fetch.ts +++ b/packages/snap/src/fetch.ts @@ -14,10 +14,10 @@ export const getSocialActivitiesUrl = (address: string) => `https://testnet.rss3.io/data/accounts/${address}/activities?tag=social&direction=out`; /** - * Get social count by rss3. + * Get social activities by rss3. * * @param address - The wallet address. - * @returns The social count. + * @returns The social activities. */ export async function getSocialActivities(address: string) { const resp = await fetch(getSocialActivitiesUrl(address)); diff --git a/packages/snap/src/index.ts b/packages/snap/src/index.ts index c67aeb4..a112400 100644 --- a/packages/snap/src/index.ts +++ b/packages/snap/src/index.ts @@ -351,6 +351,8 @@ export const onCronjob: OnCronjobHandler = async ({ request }) => { ); const socialActivities = await Promise.all(resultPromise); + // remove duplicates by following list address + // filter the changed social count const changedSocialCounts = socialActivities.filter((activity) => state.socialActivities.find( diff --git a/packages/snap/src/utils/activitiy.ts b/packages/snap/src/utils/activitiy.ts index 4783397..4627de1 100644 --- a/packages/snap/src/utils/activitiy.ts +++ b/packages/snap/src/utils/activitiy.ts @@ -56,8 +56,26 @@ export async function buildNeedToNotifyContents() { (item) => item.watchedProfiles ?? [], ); + const tempAddresses = new Set(); + const filteredProfiles = watchedProfiles.filter((profile) => { + const filteredFollowing = (profile.following || []).filter((item) => { + const { address } = item; + if (!tempAddresses.has(address)) { + tempAddresses.add(address); + return true; + } + return false; + }); + + if (filteredFollowing.length > 0) { + return { ...profile, following: filteredFollowing }; + } + + return false; + }); + const AllContents: Component[][] = []; - const contentPromises = watchedProfiles.flatMap(async (profile) => { + const contentPromises = filteredProfiles.flatMap(async (profile) => { const latestActivities = profile.following?.flatMap((fProfile) => fProfile.lastActivities ?? []) ?? []; @@ -127,7 +145,7 @@ export function getExecuteHandler(profile: Profile): ExecuteHandler { export async function addWatchedProfilesToState() { const state = await getState(); const monitorsPromises = state.monitor.flatMap(async (monitor) => { - monitor.latestUpdateTime = moment().format('YYYY/MM/DD hh:mm:ss'); + monitor.latestUpdateTime = moment().format('YYYY/MM/DD HH:mm:ss'); const profilesPromises = monitor.profiles.flatMap(async (rss3Profile) => { const { handle, execute } = getExecuteHandler(rss3Profile); return handle ? await execute(rss3Profile.handle, monitor) : undefined;