mirror of
https://github.com/block-core/blockcore-notes.git
synced 2024-09-29 22:40:44 +00:00
Added article support
This commit is contained in:
parent
6313a7d48a
commit
cae47b192f
@ -28,6 +28,7 @@ import { LabelService } from './services/label';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { BadgeService } from './services/badge';
|
||||
import { State } from './services/state';
|
||||
import { EventService } from './services/event';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
@ -68,7 +69,8 @@ export class AppComponent {
|
||||
private bottomSheet: MatBottomSheet,
|
||||
public searchService: SearchService,
|
||||
public theme: ThemeService,
|
||||
private state: State
|
||||
private state: State,
|
||||
private eventService: EventService
|
||||
) {
|
||||
if (!this.visibilityHandler) {
|
||||
this.visibilityHandler = addEventListener('visibilitychange', (event) => {
|
||||
|
@ -40,6 +40,46 @@
|
||||
</mat-list-item>
|
||||
<mat-divider></mat-divider>
|
||||
</mat-list>
|
||||
|
||||
<mat-list >
|
||||
<div mat-subheader>Reposts</div>
|
||||
<mat-list-item *ngFor="let state of state.events.reposts| keyvalue">
|
||||
<mat-icon matListItemIcon>folder</mat-icon>
|
||||
<div matListItemTitle>{{state.key}}</div>
|
||||
<div matListItemLine>{{state.value.content}}</div>
|
||||
</mat-list-item>
|
||||
<mat-divider></mat-divider>
|
||||
</mat-list>
|
||||
|
||||
<mat-list >
|
||||
<div mat-subheader>Zap</div>
|
||||
<mat-list-item *ngFor="let state of state.events.zap | keyvalue">
|
||||
<mat-icon matListItemIcon>folder</mat-icon>
|
||||
<div matListItemTitle>{{state.key}}</div>
|
||||
<div matListItemLine>{{state.value.content}}</div>
|
||||
</mat-list-item>
|
||||
<mat-divider></mat-divider>
|
||||
</mat-list>
|
||||
|
||||
<mat-list >
|
||||
<div mat-subheader>Zap Request</div>
|
||||
<mat-list-item *ngFor="let state of state.events.zapRequest| keyvalue">
|
||||
<mat-icon matListItemIcon>folder</mat-icon>
|
||||
<div matListItemTitle>{{state.key}}</div>
|
||||
<div matListItemLine>{{state.value.content}}</div>
|
||||
</mat-list-item>
|
||||
<mat-divider></mat-divider>
|
||||
</mat-list>
|
||||
|
||||
<mat-list >
|
||||
<div mat-subheader>Article</div>
|
||||
<mat-list-item *ngFor="let state of state.events.longFormContent | keyvalue">
|
||||
<mat-icon matListItemIcon>folder</mat-icon>
|
||||
<div matListItemTitle>{{state.key}}</div>
|
||||
<div matListItemLine>{{state.value.content}}</div>
|
||||
</mat-list-item>
|
||||
<mat-divider></mat-divider>
|
||||
</mat-list>
|
||||
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@ export class StateService {
|
||||
|
||||
addEvent(event: NostrEvent) {
|
||||
// TODO: Temporarily removed to avoid building massive in-memory state.
|
||||
switch (event.kind) {
|
||||
switch (event.kind as any) {
|
||||
case Kind.Metadata:
|
||||
this.addIfNewer(event, event.pubkey, this.state.events.metadata);
|
||||
if (this.state.pubkey == event.pubkey) {
|
||||
@ -24,11 +24,43 @@ export class StateService {
|
||||
this.addIfNewer(event, event.pubkey, this.state.events.contacts);
|
||||
break;
|
||||
case Kind.Reaction:
|
||||
this.addIfNewer(event, event.content, this.state.events.reaction);
|
||||
this.addIfMissing(event, this.state.events.reaction);
|
||||
break;
|
||||
case 6:
|
||||
this.addIfMissing(event, this.state.events.reposts);
|
||||
break;
|
||||
case Kind.Zap:
|
||||
this.addIfMissing(event, this.state.events.zap);
|
||||
break;
|
||||
case Kind.ZapRequest:
|
||||
this.addIfMissing(event, this.state.events.zapRequest);
|
||||
break;
|
||||
case Kind.Article:
|
||||
const slug = this.firstDTag(event);
|
||||
this.addIfNewer(event, slug!, this.state.events.longFormContent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tagsOfType(event: NostrEvent | null, type: string) {
|
||||
if (!event) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const tags = event.tags.filter((t) => t[0] === type);
|
||||
return tags;
|
||||
}
|
||||
|
||||
firstDTag(event: NostrEvent | null | any) {
|
||||
const tags = this.tagsOfType(event, 'd');
|
||||
|
||||
if (tags.length == 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return tags[0][1];
|
||||
}
|
||||
|
||||
addIfMissing(event: NostrEvent, map: Map<string, NostrEvent>) {
|
||||
if (map.has(event.id)) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user