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 1e5ffdc
Show file tree
Hide file tree
Showing 6 changed files with 28 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": "JzJh23BBGdsijFOEAQw8fREDnXCr9VJDCVESa8+qMX0=",
"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
23 changes: 21 additions & 2 deletions packages/snap/src/utils/activitiy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,27 @@ export async function buildNeedToNotifyContents() {
(item) => item.watchedProfiles ?? [],
);

const tempAddresses = new Set();
const filteredProfiles = watchedProfiles
.map((profile) => {
const filteredFollowing =
profile.following?.filter((item) => {
const { address } = item;
if (!tempAddresses.has(address)) {
tempAddresses.add(address);
return true;
}
return false;
}) || [];

return filteredFollowing.length > 0
? { ...profile, following: filteredFollowing }
: null;
})
.filter(Boolean) as TSocialGraphResult[];

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 +146,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 1e5ffdc

Please sign in to comment.