use swr for note fetcher
This commit is contained in:
11
src/utils/broadcast.tsx
Normal file
11
src/utils/broadcast.tsx
Normal file
@@ -0,0 +1,11 @@
|
||||
import { WRITEONLY_RELAYS } from '@stores/constants';
|
||||
|
||||
import { getEventHash, signEvent } from 'nostr-tools';
|
||||
|
||||
export const broadcast = ({ pool, data, privkey }: { pool: any; data: any; privkey: string }) => {
|
||||
const event = data;
|
||||
event.id = getEventHash(event);
|
||||
event.sig = signEvent(event, privkey);
|
||||
|
||||
pool.publish(event, WRITEONLY_RELAYS);
|
||||
};
|
||||
@@ -50,6 +50,26 @@ export const getParentID = (arr: string[], fallback: string) => {
|
||||
return parentID;
|
||||
};
|
||||
|
||||
// get parent id from event tags
|
||||
export const getQuoteID = (arr: string[]) => {
|
||||
const tags = destr(arr);
|
||||
let quoteID = null;
|
||||
|
||||
if (tags.length > 0) {
|
||||
if (tags[0][0] === 'e') {
|
||||
quoteID = tags[0][1];
|
||||
} else {
|
||||
tags.forEach((tag) => {
|
||||
if (tag[0] === 'e') {
|
||||
quoteID = tag[1];
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return quoteID;
|
||||
};
|
||||
|
||||
// sort messages by timestamp
|
||||
export const sortMessages = (arr: any) => {
|
||||
arr.sort((a, b) => {
|
||||
|
||||
Reference in New Issue
Block a user