mirror of
https://github.com/block-core/blockcore-notes.git
synced 2024-09-29 22:40:44 +00:00
parent
14616b5c41
commit
53f614380f
@ -11,6 +11,7 @@ import { QueueService } from '../services/queue.service';
|
||||
import { ArticleService } from '../services/article';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { ProfileService } from '../services/profile';
|
||||
import { EventService } from '../services/event';
|
||||
|
||||
export interface NoteDialogData {
|
||||
note: string;
|
||||
@ -69,7 +70,8 @@ export class EditorComponent {
|
||||
private location: Location,
|
||||
private fb: FormBuilder,
|
||||
public navigation: NavigationService,
|
||||
public profileService: ProfileService
|
||||
public profileService: ProfileService,
|
||||
private eventService: EventService
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@ -111,9 +113,7 @@ export class EditorComponent {
|
||||
pubkey: this.appState.getPublicKey(),
|
||||
};
|
||||
|
||||
// Parse hashtags.
|
||||
|
||||
|
||||
this.event.tags = this.eventService.parseContentReturnTags(this.event.content);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,6 +121,25 @@ export class EventService {
|
||||
return this.tagsOfTypeValues(event, 't');
|
||||
}
|
||||
|
||||
parseContentReturnTags(content: string) {
|
||||
// Parse the content using regular expression to get the hashtags.
|
||||
const hashTags = this.getUniqueHashtags(content);
|
||||
|
||||
// Map the hashtag array to the Nostr event tag format.
|
||||
const tags = hashTags.map((tag) => {
|
||||
return ['t', tag.substring(1)];
|
||||
});
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
getUniqueHashtags(text: string) {
|
||||
const regex = /#\w+/g;
|
||||
const matches = text.match(regex);
|
||||
const uniqueHashtags = [...new Set(matches)];
|
||||
return uniqueHashtags;
|
||||
}
|
||||
|
||||
tagsOfType(event: NostrEventDocument | null, type: string) {
|
||||
if (!event) {
|
||||
return [];
|
||||
|
@ -7,12 +7,13 @@ import { NoteDialog } from '../shared/create-note-dialog/create-note-dialog';
|
||||
import { ApplicationState } from './applicationstate';
|
||||
import { Event, Kind } from 'nostr-tools';
|
||||
import { DataService } from './data';
|
||||
import { EventService } from './event';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class NavigationService {
|
||||
constructor(private router: Router, public dialog: MatDialog, private appState: ApplicationState, private dataService: DataService) {}
|
||||
constructor(private eventService: EventService, private router: Router, public dialog: MatDialog, private appState: ApplicationState, private dataService: DataService) {}
|
||||
|
||||
#showMore: BehaviorSubject<void> = new BehaviorSubject<void>(undefined);
|
||||
showMore$ = this.#showMore.asObservable();
|
||||
@ -94,7 +95,7 @@ export class NavigationService {
|
||||
let event = this.dataService.createEvent(Kind.Text, note);
|
||||
|
||||
// Parse hashtags:
|
||||
|
||||
event.tags = this.eventService.parseContentReturnTags(event.content);
|
||||
|
||||
// TODO: We should likely save this event locally to ensure user don't loose their posts
|
||||
// if all of the network is down.
|
||||
|
Loading…
Reference in New Issue
Block a user