mirror of
https://github.com/block-core/blockcore-notes.git
synced 2024-09-29 06:20:42 +00:00
Fix issue with profile not existing
This commit is contained in:
parent
9587f04d51
commit
c1dc92e725
@ -30,11 +30,31 @@ export class ProfileService {
|
||||
|
||||
/** Will attempt to get the profile from local storage, if not available will attempt to get from relays. */
|
||||
async getProfile(pubkey: string) {
|
||||
const profile = await this.table.get(pubkey);
|
||||
const profile = await this.#get<NostrProfileDocument>(pubkey);
|
||||
|
||||
if (!profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
profile.pubkey = pubkey;
|
||||
return profile;
|
||||
}
|
||||
|
||||
async #get<T>(id: string): Promise<T | undefined> {
|
||||
try {
|
||||
const entry = await this.table.get<string, T>(id, { keyEncoding: 'utf8', valueEncoding: 'json' });
|
||||
return entry;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} catch (err: any) {
|
||||
if (err.code === 'LEVEL_NOT_FOUND') {
|
||||
return undefined;
|
||||
} else {
|
||||
console.log('HERE?!?!?');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async filter(predicate: (value: NostrProfileDocument, key: string) => boolean): Promise<NostrProfileDocument[]> {
|
||||
const iterator = this.table.iterator<string, NostrProfileDocument>({ keyEncoding: 'utf8', valueEncoding: 'json' });
|
||||
const items = [];
|
||||
@ -99,6 +119,11 @@ export class ProfileService {
|
||||
|
||||
async block(pubkey: string) {
|
||||
const profile = await this.getProfile(pubkey);
|
||||
|
||||
if (!profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
profile.block = true;
|
||||
profile.follow = false;
|
||||
await this.putProfile(pubkey, profile);
|
||||
@ -106,6 +131,11 @@ export class ProfileService {
|
||||
|
||||
async unblock(pubkey: string, follow?: boolean) {
|
||||
const profile = await this.getProfile(pubkey);
|
||||
|
||||
if (!profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
profile.block = false;
|
||||
profile.follow = follow;
|
||||
this.putProfile(pubkey, profile);
|
||||
|
@ -81,6 +81,8 @@ export class StorageService {
|
||||
}
|
||||
|
||||
async get<T>(id: string, sublevel?: string): Promise<T | undefined> {
|
||||
console.log('READING...');
|
||||
|
||||
try {
|
||||
if (sublevel) {
|
||||
const entry = await this.#db.sublevel(sublevel).get<string, T>(id, { keyEncoding: 'utf8', valueEncoding: 'json' });
|
||||
@ -94,6 +96,7 @@ export class StorageService {
|
||||
if (err.code === 'LEVEL_NOT_FOUND') {
|
||||
return undefined;
|
||||
} else {
|
||||
console.log('HERE?!?!?');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
<mat-icon class="action-button-icon">more_vert</mat-icon>
|
||||
</button>
|
||||
<mat-menu #menu="matMenu">
|
||||
<button mat-menu-item (click)="follow()" *ngIf="!profile.follow">
|
||||
<button mat-menu-item (click)="follow()" *ngIf="!profile?.follow">
|
||||
<mat-icon>add_circle</mat-icon>
|
||||
<span>Follow</span>
|
||||
</button>
|
||||
|
||||
<button mat-menu-item (click)="unfollow()" *ngIf="profile.follow">
|
||||
<button mat-menu-item (click)="unfollow()" *ngIf="profile?.follow">
|
||||
<mat-icon>remove_circle</mat-icon>
|
||||
<span>Unfollow</span>
|
||||
</button>
|
||||
@ -17,12 +17,12 @@
|
||||
<span>Move to Circle</span>
|
||||
</button>
|
||||
|
||||
<button mat-menu-item (click)="unblock()" *ngIf="profile.block == true">
|
||||
<button mat-menu-item (click)="unblock()" *ngIf="profile?.block == true">
|
||||
<mat-icon>cancel</mat-icon>
|
||||
<span>Unblock</span>
|
||||
</button>
|
||||
|
||||
<button mat-menu-item (click)="block()" *ngIf="!profile.block">
|
||||
<button mat-menu-item (click)="block()" *ngIf="!profile?.block">
|
||||
<mat-icon>block</mat-icon>
|
||||
<span>Block</span>
|
||||
</button>
|
||||
|
@ -9,23 +9,39 @@ import { NostrProfile, NostrProfileDocument } from '../../services/interfaces';
|
||||
})
|
||||
export class ProfileActionsComponent {
|
||||
@Input() pubkey: string = '';
|
||||
@Input() profile!: NostrProfileDocument;
|
||||
@Input() profile?: NostrProfileDocument;
|
||||
|
||||
constructor(private profileService: ProfileService, private utilities: Utilities) {}
|
||||
|
||||
async follow(circle?: string) {
|
||||
if (!this.profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.profileService.follow(this.profile.pubkey, circle);
|
||||
}
|
||||
|
||||
async unfollow() {
|
||||
if (!this.profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.profileService.unfollow(this.profile.pubkey);
|
||||
}
|
||||
|
||||
async block() {
|
||||
if (!this.profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.profileService.block(this.profile.pubkey);
|
||||
}
|
||||
|
||||
async unblock() {
|
||||
if (!this.profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.profileService.unblock(this.profile.pubkey);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,10 @@ export class ProfileHeaderComponent {
|
||||
this.profile = await this.profiles.getProfile(this.pubkey);
|
||||
}
|
||||
|
||||
if (!this.profile) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.imagePath = this.profile.picture;
|
||||
this.tooltip = this.profile.about;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user