Skip to content

Commit

Permalink
Added subscription to user likes in StateService
Browse files Browse the repository at this point in the history
  • Loading branch information
miladsoft committed Nov 16, 2024
1 parent 16f2826 commit fa8edc6
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/app/services/state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ export class StateService {
public async loadUserProfile(pubkey: string): Promise<void> {

if (this.isProfileLoaded) {
return;
return;
}

await this.subscribeToUserProfile(pubkey);
await this.subscribeToUserContacts(pubkey);
await this.subscribeToUserChats(pubkey);
await this.subscribeToUserPosts(pubkey);
await this.subscribeToMyLikes(pubkey);

this.isProfileLoaded = true;
}
Expand Down Expand Up @@ -142,6 +143,27 @@ export class StateService {
);
return replyTags.length > 0;
}


// Subscription for Likes (Event Type 7)
private async subscribeToMyLikes(pubkey: string): Promise<void> {


const likesLastUpdate = await this.storageService.getLastUpdateDate('myLikes');
const likeFilter: Filter = {
kinds: [7],
authors: [pubkey],
};

if (likesLastUpdate) {
likeFilter.since = parseInt(likesLastUpdate, 10);
}

this.subscriptionService.addSubscriptions([likeFilter], (event: NostrEvent) => {
console.log(event);
this.storageService.saveLike(event);
});
}
// ------------------- Parsing Events -------------------

private parseMetadataEvent(event: NostrEvent): any {
Expand Down

0 comments on commit fa8edc6

Please sign in to comment.