use swr for note fetcher

This commit is contained in:
Ren Amamiya
2023-04-27 08:57:41 +07:00
parent 38c6b2c76d
commit 8cadb7467f
7 changed files with 204 additions and 312 deletions

11
src/utils/broadcast.tsx Normal file
View 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);
};

View File

@@ -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) => {