Skip to content

Commit

Permalink
Removed MetadataService and its references, updated ChatService, Expl…
Browse files Browse the repository at this point in the history
…oreComponent, ProfileComponent, SettingsProfileComponent, UserComponent, EventService, and Post class to no longer use MetadataService
  • Loading branch information
miladsoft committed Nov 6, 2024
1 parent 3eeefe1 commit 521dc12
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 318 deletions.
29 changes: 16 additions & 13 deletions src/app/components/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BehaviorSubject, from, Observable, of, Subject, throwError } from 'rxjs
import { filter, map, switchMap, take, catchError } from 'rxjs/operators';
import { Chat, Contact, Profile } from 'app/components/chat/chat.types';
import { StorageService } from 'app/services/storage.service';
import { MetadataService } from 'app/services/metadata.service';
import { RelayService } from 'app/services/relay.service';
import { SignerService } from 'app/services/signer.service';
import { MetadataQueueService } from 'app/services/metadata-queue.service';
Expand All @@ -27,7 +26,6 @@ export class ChatService implements OnDestroy {
private _unsubscribeAll: Subject<void> = new Subject<void>();

constructor(
private _metadataService: MetadataService,
private _signerService: SignerService,
private _storageService: StorageService,
private _relayService: RelayService,
Expand Down Expand Up @@ -78,19 +76,24 @@ export class ChatService implements OnDestroy {
return;
}

const metadata =
await this._metadataService.fetchMetadataWithCache(pubkey);
if (metadata) {
const contact: Contact = {
pubKey: pubkey,
displayName: metadata.name ? metadata.name : 'Unknown',
picture: metadata.picture,
about: metadata.about,
};
this._contact.next(contact);

this._storageService.profile$.subscribe((data) => {
if (data && data.pubKey && data.metadata) {
if (data.pubKey === pubkey) {

const contact: Contact = {
pubKey: pubkey,
displayName: data.metadata.name ? data.metadata.name : 'Unknown',
picture: data.metadata.picture,
about: data.metadata.about,
};
this._contact.next(contact);

}
}
});


}
} catch (error) {
console.error('Error fetching contact metadata:', error);
}
Expand Down
4 changes: 0 additions & 4 deletions src/app/components/explore/explore.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ import { MatProgressBarModule } from '@angular/material/progress-bar';
import { MatSelectModule } from '@angular/material/select';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { MatTooltipModule } from '@angular/material/tooltip';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { Router, RouterLink } from '@angular/router';
import { Project } from 'app/interface/project.interface';
import { StorageService } from 'app/services/storage.service';
import { MetadataService } from 'app/services/metadata.service';
import { catchError, Observable, of, Subject, takeUntil, tap } from 'rxjs';
import { ProjectsService, ProjectStats } from '../../services/projects.service';
import { ChatService } from '../chat/chat.service';
import { Contact } from '../chat/chat.types';
import { BookmarkService } from 'app/services/bookmark.service';

@Component({
Expand Down
3 changes: 1 addition & 2 deletions src/app/components/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { SignerService } from 'app/services/signer.service';
import { SocialService } from 'app/services/social.service';
import { StorageService } from 'app/services/storage.service';
import { SafeUrlPipe } from 'app/shared/pipes/safe-url.pipe';
import { LightningInvoice, LightningResponse, Post } from 'app/types/post';
import { LightningInvoice, LightningResponse } from 'app/types/post';
import { InfiniteScrollModule } from 'ngx-infinite-scroll';
import { Filter, NostrEvent } from 'nostr-tools';
import { Observable, Subject, takeUntil } from 'rxjs';
Expand Down Expand Up @@ -83,7 +83,6 @@ interface Chip {
SafeUrlPipe,
MatProgressSpinnerModule,
InfiniteScrollModule,
EventListComponent,
MatIconModule,
MatExpansionModule,
MatSidenavModule,
Expand Down
47 changes: 29 additions & 18 deletions src/app/components/settings/profile/profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TextFieldModule } from '@angular/cdk/text-field';
import { CommonModule } from '@angular/common';
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
OnInit,
ViewEncapsulation,
Expand All @@ -22,9 +23,9 @@ import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { Router } from '@angular/router';
import { hexToBytes } from '@noble/hashes/utils';
import { MetadataService } from 'app/services/metadata.service';
import { RelayService } from 'app/services/relay.service';
import { SignerService } from 'app/services/signer.service';
import { StorageService } from 'app/services/storage.service';
import { PasswordDialogComponent } from 'app/shared/password-dialog/password-dialog.component';
import { NostrEvent, UnsignedEvent, finalizeEvent } from 'nostr-tools';

Expand All @@ -50,14 +51,18 @@ import { NostrEvent, UnsignedEvent, finalizeEvent } from 'nostr-tools';
export class SettingsProfileComponent implements OnInit {
profileForm: FormGroup;
content: string;
user: any;

constructor(
private _fb: FormBuilder,
private _signerService: SignerService,
private _metadataService: MetadataService,
private _relayService: RelayService,
private _router: Router,
private _dialog: MatDialog
private _dialog: MatDialog,
private _storageService: StorageService,
private _changeDetectorRef: ChangeDetectorRef,


) {}

ngOnInit(): void {
Expand All @@ -83,23 +88,29 @@ export class SettingsProfileComponent implements OnInit {
this.setValues();
}

async setValues() {
let kind0 = await this._metadataService.getProfile(
this._signerService.getPublicKey()
);
if (kind0) {
async setValues(): Promise<void> {
try {
const publicKey = await this._signerService.getPublicKey();
const metadata = await this._storageService.getProfile(publicKey);

this.user = metadata;

this.profileForm.setValue({
name: kind0.name || '',
username: kind0.username || '',
displayName: kind0.displayName || '',
website: kind0.website || '',
about: kind0.about || '',
picture: kind0.picture || '',
banner: kind0.banner || '',
lud06: kind0.lud06 || '',
lud16: kind0.lud16 || '',
nip05: kind0.nip05 || '',
name: this.user?.name || '',
username: this.user?.username || '',
displayName: this.user?.displayName || '',
website: this.user?.website || '',
about: this.user?.about || '',
picture: this.user?.picture || '',
banner: this.user?.banner || '',
lud06: this.user?.lud06 || '',
lud16: this.user?.lud16 || '',
nip05: this.user?.nip05 || '',
});

this._changeDetectorRef.detectChanges();
} catch (error) {
console.error('Error fetching profile:', error);
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/app/layout/common/user/user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ import { MatMenuModule } from '@angular/material/menu';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { StorageService } from 'app/services/storage.service';
import { MetadataService } from 'app/services/metadata.service';
import { SignerService } from 'app/services/signer.service';
import { SubscriptionService } from 'app/services/subscription.service';
import { Filter, NostrEvent } from 'nostr-tools';
import { Subject, takeUntil } from 'rxjs';
import { StateService } from 'app/services/state.service';
import { init as initNostrLogin, launch as launchNostrLoginDialog } from '@blockcore/nostr-login';
import { NostrLoginService } from 'app/services/nostr-login.service';

@Component({
Expand Down
8 changes: 1 addition & 7 deletions src/app/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { NewEvent } from 'app/types/NewEvent';
import { Filter, finalizeEvent, NostrEvent } from 'nostr-tools';
import { BehaviorSubject, Observable } from 'rxjs';
import { throttleTime } from 'rxjs/operators';
import { MetadataService } from './metadata.service';
import { RelayService } from './relay.service';
import { SignerService } from './signer.service';
import { QueueService } from './queue-service.service';
Expand Down Expand Up @@ -39,7 +38,6 @@ export class PaginatedEventService {
constructor(
private relayService: RelayService,
private signerService: SignerService,
private metadataService: MetadataService,
private queueService: QueueService
) {
}
Expand Down Expand Up @@ -309,11 +307,7 @@ export class PaginatedEventService {

newEvent.likedByMe = this.myLikedNoteIds.includes(event.id);

const metadata = await this.metadataService.fetchMetadataWithCache(event.pubkey);
if (metadata) {
newEvent.username = metadata.name || newEvent.npub;
newEvent.picture = metadata.picture || '/images/avatars/avatar-placeholder.png';
}


return newEvent;
}
Expand Down
151 changes: 0 additions & 151 deletions src/app/services/metadata.service.ts

This file was deleted.

Loading

0 comments on commit 521dc12

Please sign in to comment.