Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove duplicated addresses #6

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading