mirror of
https://github.com/block-core/angor-hub-old.git
synced 2026-01-31 07:34:21 +01:00
Added share functionality to post-event component, updated event service to handle sharing, and made minor changes to post component and state service.
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
"></mat-icon>
|
||||
<span class="ml-2">Comment</span>
|
||||
</button>
|
||||
<button class="mr-1 px-3" mat-button>
|
||||
<button class="mr-1 px-3" mat-button (click)="onShare(post)">
|
||||
<mat-icon class="text-green-500 icon-size-5" [svgIcon]="'heroicons_solid:share'"></mat-icon>
|
||||
<span class="ml-2">Share</span>
|
||||
</button>
|
||||
|
||||
@@ -28,6 +28,7 @@ import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
|
||||
import { PostComponent } from 'app/layout/common/post/post.component';
|
||||
import { NewEvent } from 'app/types/NewEvent';
|
||||
import { EventService } from 'app/services/event.service';
|
||||
import { AngorConfirmationService } from '@angor/services/confirmation';
|
||||
|
||||
|
||||
export interface PostReaction {
|
||||
@@ -88,7 +89,9 @@ export class PostEventComponent implements OnInit, OnDestroy {
|
||||
private _changeDetectorRef: ChangeDetectorRef,
|
||||
public parseContent: ParseContentService,
|
||||
private _sanitizer: DomSanitizer,
|
||||
private _eventService: EventService
|
||||
private _eventService: EventService,
|
||||
private _angorConfirmationService: AngorConfirmationService,
|
||||
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
@@ -217,6 +220,42 @@ export class PostEventComponent implements OnInit, OnDestroy {
|
||||
this.sendLike(event);
|
||||
}
|
||||
|
||||
onShare(event: NewEvent): void {
|
||||
const dialogRef = this._angorConfirmationService.open({
|
||||
title: 'Share',
|
||||
message:
|
||||
'Are you sure you want to share this post on your profile? <span class="font-medium">This action is permanent and cannot be undone.</span>',
|
||||
icon: {
|
||||
show: true,
|
||||
name: 'heroicons_solid:share',
|
||||
color: 'primary',
|
||||
},
|
||||
actions: {
|
||||
confirm: {
|
||||
show: true,
|
||||
label: 'Yes, Share',
|
||||
color: 'primary',
|
||||
},
|
||||
cancel: {
|
||||
show: true,
|
||||
label: 'Cancel',
|
||||
},
|
||||
},
|
||||
dismissible: true,
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
console.log(result);
|
||||
if (result === "confirmed") {
|
||||
this._eventService.shareEvent(event).then(() => {
|
||||
this._changeDetectorRef.detectChanges();
|
||||
}).catch(error => console.error('Failed to share post', error));
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
ngOnDestroy(): void {
|
||||
|
||||
if (this.subscriptionId) {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PostComponent } from './post.component';
|
||||
|
||||
describe('PostComponent', () => {
|
||||
let component: PostComponent;
|
||||
let fixture: ComponentFixture<PostComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [PostComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(PostComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -171,6 +171,11 @@ export class PostComponent implements OnDestroy {
|
||||
|
||||
dialogRef.afterClosed().subscribe((result) => {
|
||||
console.log(result);
|
||||
if (result === "confirmed") {
|
||||
this.eventService.shareEvent(event);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -169,4 +169,41 @@ export class EventService {
|
||||
console.error('Failed to send reply event:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async shareEvent(event: NewEvent): Promise<void> {
|
||||
if (!event) return;
|
||||
|
||||
try {
|
||||
const tags = [
|
||||
['e', event.id],
|
||||
['p', event.pubkey],
|
||||
];
|
||||
|
||||
const content = '';
|
||||
|
||||
const unsignedEvent = this.signerService.getUnsignedEvent(
|
||||
6,
|
||||
tags,
|
||||
content
|
||||
);
|
||||
let signedEvent: NostrEvent;
|
||||
|
||||
if (this.signerService.isUsingSecretKey()) {
|
||||
const privateKey = await this.signerService.getDecryptedSecretKey();
|
||||
const privateKeyBytes = hexToBytes(privateKey);
|
||||
signedEvent = finalizeEvent(unsignedEvent, privateKeyBytes);
|
||||
} else {
|
||||
signedEvent = await this.signerService.signEventWithExtension(
|
||||
unsignedEvent
|
||||
);
|
||||
}
|
||||
|
||||
await this.relayService.publishEventToWriteRelays(signedEvent);
|
||||
console.log('Event shared successfully:', signedEvent);
|
||||
} catch (error) {
|
||||
console.error('Failed to share event:', error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { SubscriptionService } from './subscription.service';
|
||||
import { NostrEvent, Filter } from 'nostr-tools';
|
||||
import { ContactEvent, StorageService } from './storage.service';
|
||||
import { Contacts, EncryptedDirectMessage } from 'nostr-tools/kinds';
|
||||
import { Contacts, EncryptedDirectMessage, Reaction, ShortTextNote } from 'nostr-tools/kinds';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@@ -121,7 +121,7 @@ export class StateService {
|
||||
|
||||
const postsLastUpdate = await this.storageService.getLastUpdateDate('posts');
|
||||
const postFilter: Filter = {
|
||||
kinds: [1],
|
||||
kinds: [ShortTextNote],
|
||||
authors: [pubkey],
|
||||
};
|
||||
|
||||
@@ -151,7 +151,7 @@ export class StateService {
|
||||
|
||||
const likesLastUpdate = await this.storageService.getLastUpdateDate('myLikes');
|
||||
const likeFilter: Filter = {
|
||||
kinds: [7],
|
||||
kinds: [Reaction],
|
||||
authors: [pubkey],
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user