add requestAnimationFrame to socialgraph handleevent
This commit is contained in:
@ -51,43 +51,45 @@ export default class SocialGraph {
|
|||||||
if (event.kind !== 3) {
|
if (event.kind !== 3) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
requestAnimationFrame(() => {
|
||||||
const author = ID(event.pubkey);
|
try {
|
||||||
const timestamp = event.created_at;
|
const author = ID(event.pubkey);
|
||||||
const existingTimestamp = this.latestFollowEventTimestamps.get(author);
|
const timestamp = event.created_at;
|
||||||
if (existingTimestamp && timestamp <= existingTimestamp) {
|
const existingTimestamp = this.latestFollowEventTimestamps.get(author);
|
||||||
return;
|
if (existingTimestamp && timestamp <= existingTimestamp) {
|
||||||
}
|
return;
|
||||||
this.latestFollowEventTimestamps.set(author, timestamp);
|
}
|
||||||
|
this.latestFollowEventTimestamps.set(author, timestamp);
|
||||||
|
|
||||||
// Collect all users followed in the new event.
|
// Collect all users followed in the new event.
|
||||||
const followedInEvent = new Set<UID>();
|
const followedInEvent = new Set<UID>();
|
||||||
for (const tag of event.tags) {
|
for (const tag of event.tags) {
|
||||||
if (tag[0] === "p") {
|
if (tag[0] === "p") {
|
||||||
const followedUser = ID(tag[1]);
|
const followedUser = ID(tag[1]);
|
||||||
if (followedUser !== author) {
|
if (followedUser !== author) {
|
||||||
followedInEvent.add(followedUser);
|
followedInEvent.add(followedUser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Get the set of users currently followed by the author.
|
// Get the set of users currently followed by the author.
|
||||||
const currentlyFollowed = this.followedByUser.get(author) || new Set<UID>();
|
const currentlyFollowed = this.followedByUser.get(author) || new Set<UID>();
|
||||||
|
|
||||||
// Find users that need to be removed.
|
// Find users that need to be removed.
|
||||||
for (const user of currentlyFollowed) {
|
for (const user of currentlyFollowed) {
|
||||||
if (!followedInEvent.has(user)) {
|
if (!followedInEvent.has(user)) {
|
||||||
this.removeFollower(user, author);
|
this.removeFollower(user, author);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Add or update the followers based on the new event.
|
// Add or update the followers based on the new event.
|
||||||
for (const user of followedInEvent) {
|
for (const user of followedInEvent) {
|
||||||
this.addFollower(user, author);
|
this.addFollower(user, author);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// might not be logged in or sth
|
||||||
}
|
}
|
||||||
} catch (e) {
|
});
|
||||||
// might not be logged in or sth
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isFollowing(follower: HexKey, followedUser: HexKey): boolean {
|
isFollowing(follower: HexKey, followedUser: HexKey): boolean {
|
||||||
|
Reference in New Issue
Block a user