Add support for NIP-27

- Closes #125
This commit is contained in:
SondreB 2023-05-12 12:17:09 +02:00
parent f93fbb3a0e
commit 6c793a7b8f
No known key found for this signature in database
GPG Key ID: D6CC44C75005FDBF
2 changed files with 30 additions and 1 deletions

View File

@ -15,11 +15,17 @@
<ng-container *ngFor="let token of dynamicText">
<ng-template [ngIf]="isString(token)">{{ token }}</ng-template>
<ng-template [ngIf]="!isString(token) && isFollowing" [ngSwitch]="token.token">
<ng-container *ngSwitchCase="'npub'"><a class="reply-link" [routerLink]="['/p', token.word]">@{{ getDisplayName(token.word) }}</a></ng-container>
<ng-container *ngSwitchCase="'nprofile'"><a class="reply-link" [routerLink]="['/p', token.word]">@{{ getDisplayName(token.word) }}</a></ng-container>
<ng-container *ngSwitchCase="'note'"><a class="reply-link" [routerLink]="['/e', token.word]">{{ token.word }}</a></ng-container>
<ng-container *ngSwitchCase="'nevent'"><a class="reply-link" [routerLink]="['/e', token.word]">{{ token.word }}</a></ng-container>
<ng-container *ngSwitchCase="'username'"><a class="reply-link" [routerLink]="['/p', token.word]">@{{ getDisplayName(token.word) }}</a></ng-container>
<ng-container *ngSwitchCase="'link'"><a [href]="[token.word]" target="_blank">{{ token.word }}</a></ng-container>
<ng-container *ngSwitchCase="'image'"><img mat-card-image class="event-image" loading="lazy" decoding="async" [matTooltip]="token.word" [alt]="token.word" [src]="token.safeWord" (click)="expandImage(token.word)" /></ng-container>
<ng-container *ngSwitchCase="'linebreak'"><br /></ng-container>
<ng-container *ngSwitchCase="'spotify'">
<ng-container *ngSwitchCase="'spotify'">1
<iframe sandbox="allow-scripts allow-same-origin" style="border-radius: 12px" [src]="token.safeWord" width="100%" height="152" frameborder="0" allowfullscreen="" allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture" loading="lazy"></iframe>
</ng-container>
<ng-container *ngSwitchCase="'tidal'">
@ -47,6 +53,12 @@
</ng-template>
<ng-template [ngIf]="!isString(token) && !isFollowing" [ngSwitch]="token.token">
<ng-container *ngSwitchCase="'npub'"><a class="reply-link" [routerLink]="['/p', token.word]">@{{ getDisplayName(token.word) }}</a></ng-container>
<ng-container *ngSwitchCase="'nprofile'"><a class="reply-link" [routerLink]="['/p', token.word]">@{{ getDisplayName(token.word) }}</a></ng-container>
<ng-container *ngSwitchCase="'note'"><a class="reply-link" [routerLink]="['/e', token.word]">{{ token.word }}</a></ng-container>
<ng-container *ngSwitchCase="'nevent'"><a class="reply-link" [routerLink]="['/e', token.word]">{{ token.word }}</a></ng-container>
<ng-container *ngSwitchCase="'username'"><a class="reply-link" [routerLink]="['/p', token.word]">@{{ getDisplayName(token.word) }}</a></ng-container>
<ng-container *ngSwitchCase="'link'"><a [href]="[token.word]" target="_blank">{{ token.word }}</a></ng-container>
<ng-container *ngSwitchCase="'image'"><a [href]="[token.word]" target="_blank">{{ token.word }}</a></ng-container>

View File

@ -9,6 +9,7 @@ import { ProfileService } from 'src/app/services/profile';
import { Utilities } from 'src/app/services/utilities';
import { NostrEventDocument, NostrProfile, NostrProfileDocument, TokenKeyword } from '../../services/interfaces';
import { ProfileImageDialog } from '../profile-image-dialog/profile-image-dialog';
import { nip19 } from 'nostr-tools';
interface MediaItem {
url: SafeResourceUrl;
@ -132,6 +133,7 @@ export class ContentComponent {
}
getDisplayName(pubkey: string) {
pubkey = this.utilities.ensureHexIdentifier(pubkey);
const profile = this.profileService.getCachedProfile(pubkey);
if (!profile) {
@ -281,6 +283,21 @@ export class ContentComponent {
}
i = res.push(keyword);
} else if (token.startsWith('nostr:')) {
const decoded = nip19.decode(token.substring(6));
const val = decoded.data as any;
if (decoded.type === 'nprofile') {
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: val.pubkey, token: decoded.type });
} else if (decoded.type === 'npub') {
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: val, token: decoded.type });
} else if (decoded.type === 'note') {
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: val, token: decoded.type });
} else if (decoded.type === 'nevent') {
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: val.id, token: decoded.type });
} else {
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: token.substring(6), token: decoded.type });
}
} else if (token.startsWith('http://') || token.startsWith('https://')) {
if (this.isImage(token)) {
i = res.push({ safeWord: this.utilities.sanitizeUrlAndBypass(token), word: token, token: 'image' });