Skip to content

Commit

Permalink
feat: filter out duplicate data in the following list, based on the a…
Browse files Browse the repository at this point in the history
…ddress
  • Loading branch information
dmoosocool committed Dec 15, 2023
1 parent 48a5538 commit a48c2be
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/site/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion packages/site/src/pages/monitor/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const MonitorList = () => {
const [monitorList, setMonitorList] = useState<SocialMonitor[]>([]);
const handleGetState = async () => {
const snapState = await sendGetState();
// console.log(snapState);
console.log(snapState);
};

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/snap/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions packages/snap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 20 additions & 2 deletions packages/snap/src/utils/activitiy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []) ??
[];
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a48c2be

Please sign in to comment.