replace eslint/prettier with rome

This commit is contained in:
Ren Amamiya
2023-05-14 17:05:53 +07:00
parent 48d690d33a
commit 409a625dcc
154 changed files with 7639 additions and 8525 deletions

View File

@@ -1,6 +1,6 @@
import { readBinaryFile } from '@tauri-apps/api/fs';
import { readBinaryFile } from "@tauri-apps/api/fs";
export async function createBlobFromFile(path: string): Promise<Blob> {
const file = await readBinaryFile(path);
return new Blob([file]);
const file = await readBinaryFile(path);
return new Blob([file]);
}

View File

@@ -1,22 +1,22 @@
// get X days ago with user provided date
export function getDayAgo(numOfDays, date = new Date()) {
const days = new Date(date.getTime());
days.setDate(date.getDate() - numOfDays);
const days = new Date(date.getTime());
days.setDate(date.getDate() - numOfDays);
return days;
return days;
}
// get X hours ago with user provided date
export function getHourAgo(numOfHours, date = new Date()) {
const hours = new Date(date.getTime());
hours.setHours(date.getHours() - numOfHours);
const hours = new Date(date.getTime());
hours.setHours(date.getHours() - numOfHours);
return hours;
return hours;
}
// convert date to unix timestamp
export function dateToUnix(_date?: Date) {
const date = _date || new Date();
const date = _date || new Date();
return Math.floor(date.getTime() / 1000);
return Math.floor(date.getTime() / 1000);
}

View File

@@ -1,15 +1,15 @@
import { getActiveAccount } from '@utils/storage';
import { getActiveAccount } from "@utils/storage";
import useSWR from 'swr';
import useSWR from "swr";
const fetcher = () => getActiveAccount();
export function useActiveAccount() {
const { data, error, isLoading } = useSWR('activeAcount', fetcher);
const { data, error, isLoading } = useSWR("activeAcount", fetcher);
return {
account: data,
isLoading,
isError: error,
};
return {
account: data,
isLoading,
isError: error,
};
}

View File

@@ -1,23 +1,25 @@
import { useEffect, useState } from 'react';
import { useEffect, useState } from "react";
const getOnLineStatus = () =>
typeof navigator !== 'undefined' && typeof navigator.onLine === 'boolean' ? navigator.onLine : true;
typeof navigator !== "undefined" && typeof navigator.onLine === "boolean"
? navigator.onLine
: true;
export function useNetworkStatus() {
const [status, setStatus] = useState(getOnLineStatus());
const [status, setStatus] = useState(getOnLineStatus());
const setOnline = () => setStatus(true);
const setOffline = () => setStatus(false);
const setOnline = () => setStatus(true);
const setOffline = () => setStatus(false);
useEffect(() => {
window.addEventListener('online', setOnline);
window.addEventListener('offline', setOffline);
useEffect(() => {
window.addEventListener("online", setOnline);
window.addEventListener("offline", setOffline);
return () => {
window.removeEventListener('online', setOnline);
window.removeEventListener('offline', setOffline);
};
}, []);
return () => {
window.removeEventListener("online", setOnline);
window.removeEventListener("offline", setOffline);
};
}, []);
return status;
return status;
}

View File

@@ -1,23 +1,23 @@
// `usePageContext` allows us to access `pageContext` in any React component.
// See https://vite-plugin-ssr.com/pageContext-anywhere
import type { PageContext } from '@renderer/types';
import type { PageContext } from "@renderer/types";
import { createContext, useContext } from 'react';
import { createContext, useContext } from "react";
const Context = createContext<PageContext>(undefined as any);
export function PageContextProvider({
pageContext,
children,
pageContext,
children,
}: {
pageContext: PageContext;
children: React.ReactNode;
pageContext: PageContext;
children: React.ReactNode;
}) {
return <Context.Provider value={pageContext}>{children}</Context.Provider>;
return <Context.Provider value={pageContext}>{children}</Context.Provider>;
}
// eslint-disable-next-line react-refresh/only-export-components
export function usePageContext() {
const pageContext = useContext(Context);
return pageContext;
const pageContext = useContext(Context);
return pageContext;
}

View File

@@ -1,34 +1,34 @@
import { METADATA_SERVICE } from '@stores/constants';
import { METADATA_SERVICE } from "@stores/constants";
import { createPleb, getPleb } from '@utils/storage';
import { createPleb, getPleb } from "@utils/storage";
import useSWR from 'swr';
import useSWR from "swr";
const fetcher = async (pubkey: string) => {
const result = await getPleb(pubkey);
if (result) {
const metadata = JSON.parse(result['metadata']);
result['content'] = metadata.content;
delete result['metadata'];
const result = await getPleb(pubkey);
if (result) {
const metadata = JSON.parse(result["metadata"]);
result["content"] = metadata.content;
result["metadata"] = undefined;
return result;
} else {
const result = await fetch(`${METADATA_SERVICE}/${pubkey}/metadata.json`);
const resultJSON = await result.json();
const cache = await createPleb(pubkey, resultJSON);
return result;
} else {
const result = await fetch(`${METADATA_SERVICE}/${pubkey}/metadata.json`);
const resultJSON = await result.json();
const cache = await createPleb(pubkey, resultJSON);
if (cache) {
return resultJSON;
}
}
if (cache) {
return resultJSON;
}
}
};
export function useProfile(pubkey: string) {
const { data, error, isLoading } = useSWR(pubkey, fetcher);
const { data, error, isLoading } = useSWR(pubkey, fetcher);
return {
user: data ? JSON.parse(data.content ? data.content : null) : null,
isLoading,
isError: error,
};
return {
user: data ? JSON.parse(data.content ? data.content : null) : null,
isLoading,
isError: error,
};
}

View File

@@ -1,12 +1,16 @@
import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/api/notification';
import {
isPermissionGranted,
requestPermission,
sendNotification,
} from "@tauri-apps/api/notification";
export async function sendNativeNotification(content: string) {
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}
if (permissionGranted) {
sendNotification({ title: 'TAURI', body: content });
}
let permissionGranted = await isPermissionGranted();
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === "granted";
}
if (permissionGranted) {
sendNotification({ title: "TAURI", body: content });
}
}

View File

@@ -1,57 +1,66 @@
import { Event, parseReferences } from 'nostr-tools';
import { Event, parseReferences } from "nostr-tools";
const getURLs = new RegExp(
'(^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal|wss|ws):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))',
'gmi'
"(^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal|wss|ws):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))",
"gmi",
);
export function noteParser(event: Event) {
const references = parseReferences(event);
const content: { original: string; parsed: any; notes: string[]; images: string[]; videos: string[] } = {
original: event.content,
parsed: event.content,
notes: [],
images: [],
videos: [],
};
const references = parseReferences(event);
const content: {
original: string;
parsed: any;
notes: string[];
images: string[];
videos: string[];
} = {
original: event.content,
parsed: event.content,
notes: [],
images: [],
videos: [],
};
// handle media
content.original.match(getURLs)?.forEach((item) => {
// make sure url is trimmed
const url = item.trim();
// handle media
content.original.match(getURLs)?.forEach((item) => {
// make sure url is trimmed
const url = item.trim();
if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/)) {
// image url
content.images.push(url);
// remove url from original content
content.parsed = content.parsed.replace(url, '');
} else if (url.match(/\.(mp4|webm|mov|ogv|avi|mp3)$/)) {
// video
content.videos.push(url);
// remove url from original content
content.parsed = content.parsed.replace(url, '');
}
});
if (url.match(/\.(jpg|jpeg|gif|png|webp|avif)$/)) {
// image url
content.images.push(url);
// remove url from original content
content.parsed = content.parsed.replace(url, "");
} else if (url.match(/\.(mp4|webm|mov|ogv|avi|mp3)$/)) {
// video
content.videos.push(url);
// remove url from original content
content.parsed = content.parsed.replace(url, "");
}
});
// map hashtag to em
content.original.match(/#(\w+)(?!:\/\/)/g)?.forEach((item) => {
content.parsed = content.parsed.replace(item, ` [${item}](https://primal.net/search/${item})`);
});
// map hashtag to em
content.original.match(/#(\w+)(?!:\/\/)/g)?.forEach((item) => {
content.parsed = content.parsed.replace(
item,
` [${item}](https://primal.net/search/${item})`,
);
});
// handle nostr mention
references.forEach((item) => {
const profile = item.profile;
const event = item.event;
// handle nostr mention
references.forEach((item) => {
const profile = item.profile;
const event = item.event;
if (event) {
content.notes.push(event.id);
content.parsed = content.parsed.replace(item.text, '');
}
if (event) {
content.notes.push(event.id);
content.parsed = content.parsed.replace(item.text, "");
}
if (profile) {
content.parsed = content.parsed.replace(item.text, `*${profile.pubkey}*`);
}
});
if (profile) {
content.parsed = content.parsed.replace(item.text, `*${profile.pubkey}*`);
}
});
return content;
return content;
}

View File

@@ -1,6 +1,6 @@
import { nip19 } from 'nostr-tools';
import { nip19 } from "nostr-tools";
export function shortenKey(pubkey: string) {
const npub = nip19.npubEncode(pubkey);
return npub.substring(0, 16).concat('...');
const npub = nip19.npubEncode(pubkey);
return npub.substring(0, 16).concat("...");
}

View File

@@ -1,246 +1,302 @@
import Database from 'tauri-plugin-sql-api';
import Database from "tauri-plugin-sql-api";
let db: null | Database = null;
// connect database (sqlite)
// path: tauri::api::path::BaseDirectory::App
export async function connect(): Promise<Database> {
if (db) {
return db;
}
db = await Database.load('sqlite:lume.db');
return db;
if (db) {
return db;
}
db = await Database.load("sqlite:lume.db");
return db;
}
// get active account
export async function getActiveAccount() {
const db = await connect();
// #TODO: check is_active == true
const result = await db.select(`SELECT * FROM accounts WHERE is_active = 1 LIMIT 1;`);
return result[0];
const db = await connect();
// #TODO: check is_active == true
const result = await db.select(
"SELECT * FROM accounts WHERE is_active = 1 LIMIT 1;",
);
return result[0];
}
// get all accounts
export async function getAccounts() {
const db = await connect();
return await db.select(`SELECT * FROM accounts WHERE is_active = 0 ORDER BY created_at DESC;`);
const db = await connect();
return await db.select(
"SELECT * FROM accounts WHERE is_active = 0 ORDER BY created_at DESC;",
);
}
// create account
export async function createAccount(
pubkey: string,
privkey: string,
metadata: string,
follows?: string[][],
is_active?: number
pubkey: string,
privkey: string,
metadata: string,
follows?: string[][],
is_active?: number,
) {
const db = await connect();
return await db.execute(
'INSERT OR IGNORE INTO accounts (pubkey, privkey, metadata, follows, is_active) VALUES (?, ?, ?, ?, ?);',
[pubkey, privkey, metadata, follows || '', is_active || 0]
);
const db = await connect();
return await db.execute(
"INSERT OR IGNORE INTO accounts (pubkey, privkey, metadata, follows, is_active) VALUES (?, ?, ?, ?, ?);",
[pubkey, privkey, metadata, follows || "", is_active || 0],
);
}
// update account
export async function updateAccount(column: string, value: string | string[], pubkey: string) {
const db = await connect();
return await db.execute(`UPDATE accounts SET ${column} = ? WHERE pubkey = ?;`, [value, pubkey]);
export async function updateAccount(
column: string,
value: string | string[],
pubkey: string,
) {
const db = await connect();
return await db.execute(
`UPDATE accounts SET ${column} = ? WHERE pubkey = ?;`,
[value, pubkey],
);
}
// get all plebs
export async function getPlebs() {
const db = await connect();
return await db.select(`SELECT * FROM plebs ORDER BY created_at DESC;`);
const db = await connect();
return await db.select("SELECT * FROM plebs ORDER BY created_at DESC;");
}
// get pleb by pubkey
export async function getPleb(pubkey: string) {
const db = await connect();
const result = await db.select(`SELECT * FROM plebs WHERE pubkey = "${pubkey}"`);
return result[0];
const db = await connect();
const result = await db.select(
`SELECT * FROM plebs WHERE pubkey = "${pubkey}"`,
);
return result[0];
}
// create pleb
export async function createPleb(pubkey: string, metadata: string) {
const db = await connect();
return await db.execute('INSERT OR IGNORE INTO plebs (pubkey, metadata) VALUES (?, ?);', [pubkey, metadata]);
const db = await connect();
return await db.execute(
"INSERT OR IGNORE INTO plebs (pubkey, metadata) VALUES (?, ?);",
[pubkey, metadata],
);
}
// count total notes
export async function countTotalChannels() {
const db = await connect();
const result = await db.select('SELECT COUNT(*) AS "total" FROM channels;');
return result[0];
const db = await connect();
const result = await db.select('SELECT COUNT(*) AS "total" FROM channels;');
return result[0];
}
// count total notes
export async function countTotalNotes() {
const db = await connect();
const result = await db.select('SELECT COUNT(*) AS "total" FROM notes WHERE kind IN (1, 6);');
return result[0].total;
const db = await connect();
const result = await db.select(
'SELECT COUNT(*) AS "total" FROM notes WHERE kind IN (1, 6);',
);
return result[0].total;
}
// count total notes
export async function countTotalLongNotes() {
const db = await connect();
const result = await db.select('SELECT COUNT(*) AS "total" FROM notes WHERE kind = 30023;');
return result[0].total;
const db = await connect();
const result = await db.select(
'SELECT COUNT(*) AS "total" FROM notes WHERE kind = 30023;',
);
return result[0].total;
}
// get all notes
export async function getNotes(time: number, limit: number, offset: number) {
const db = await connect();
const db = await connect();
const notes: any = { data: null, nextCursor: 0 };
const query: any = await db.select(
`SELECT * FROM notes WHERE created_at <= "${time}" AND kind IN (1, 6, 1063) GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
);
const notes: any = { data: null, nextCursor: 0 };
const query: any = await db.select(
`SELECT * FROM notes WHERE created_at <= "${time}" AND kind IN (1, 6, 1063) GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`,
);
notes['data'] = query;
notes['nextCursor'] = offset + limit;
notes["data"] = query;
notes["nextCursor"] = offset + limit;
return notes;
return notes;
}
// get all long notes
export async function getLongNotes(time: number, limit: number, offset: number) {
const db = await connect();
export async function getLongNotes(
time: number,
limit: number,
offset: number,
) {
const db = await connect();
const notes: any = { data: null, nextCursor: 0 };
const query: any = await db.select(
`SELECT * FROM notes WHERE created_at <= "${time}" AND kind = 30023 GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`
);
const notes: any = { data: null, nextCursor: 0 };
const query: any = await db.select(
`SELECT * FROM notes WHERE created_at <= "${time}" AND kind = 30023 GROUP BY parent_id ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`,
);
notes['data'] = query;
notes['nextCursor'] = offset + limit;
notes["data"] = query;
notes["nextCursor"] = offset + limit;
return notes;
return notes;
}
// get all note authors
export async function getNoteAuthors() {
const db = await connect();
const result = await db.select(`SELECT DISTINCT pubkey FROM notes ORDER BY created_at DESC`);
return result;
const db = await connect();
const result = await db.select(
"SELECT DISTINCT pubkey FROM notes ORDER BY created_at DESC",
);
return result;
}
// get note by id
export async function getNoteByID(event_id: string) {
const db = await connect();
const result = await db.select(`SELECT * FROM notes WHERE event_id = "${event_id}";`);
return result[0];
const db = await connect();
const result = await db.select(
`SELECT * FROM notes WHERE event_id = "${event_id}";`,
);
return result[0];
}
// get all latest notes
export async function getLatestNotes(time: number) {
const db = await connect();
return await db.select(
`SELECT * FROM notes WHERE created_at > "${time}" GROUP BY parent_id ORDER BY created_at DESC;`
);
const db = await connect();
return await db.select(
`SELECT * FROM notes WHERE created_at > "${time}" GROUP BY parent_id ORDER BY created_at DESC;`,
);
}
// create note
export async function createNote(
event_id: string,
account_id: number,
pubkey: string,
kind: number,
tags: string[],
content: string,
created_at: number,
parent_id: string
event_id: string,
account_id: number,
pubkey: string,
kind: number,
tags: string[],
content: string,
created_at: number,
parent_id: string,
) {
const db = await connect();
return await db.execute(
'INSERT OR IGNORE INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);',
[event_id, account_id, pubkey, kind, tags, content, created_at, parent_id]
);
const db = await connect();
return await db.execute(
"INSERT OR IGNORE INTO notes (event_id, account_id, pubkey, kind, tags, content, created_at, parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?);",
[event_id, account_id, pubkey, kind, tags, content, created_at, parent_id],
);
}
// get all channels
export async function getChannels(limit: number, offset: number) {
const db = await connect();
return await db.select(`SELECT * FROM channels ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`);
const db = await connect();
return await db.select(
`SELECT * FROM channels ORDER BY created_at DESC LIMIT "${limit}" OFFSET "${offset}";`,
);
}
// get channel by id
export async function getChannel(id: string) {
const db = await connect();
const result = await db.select(`SELECT * FROM channels WHERE event_id = "${id}";`);
return result[0];
const db = await connect();
const result = await db.select(
`SELECT * FROM channels WHERE event_id = "${id}";`,
);
return result[0];
}
// create channel
export async function createChannel(event_id: string, pubkey: string, metadata: string, created_at: number) {
const db = await connect();
return await db.execute(
'INSERT OR IGNORE INTO channels (event_id, pubkey, metadata, created_at) VALUES (?, ?, ?, ?);',
[event_id, pubkey, metadata, created_at]
);
export async function createChannel(
event_id: string,
pubkey: string,
metadata: string,
created_at: number,
) {
const db = await connect();
return await db.execute(
"INSERT OR IGNORE INTO channels (event_id, pubkey, metadata, created_at) VALUES (?, ?, ?, ?);",
[event_id, pubkey, metadata, created_at],
);
}
// update channel metadata
export async function updateChannelMetadata(event_id: string, value: string) {
const db = await connect();
return await db.execute('UPDATE channels SET metadata = ? WHERE event_id = ?;', [value, event_id]);
const db = await connect();
return await db.execute(
"UPDATE channels SET metadata = ? WHERE event_id = ?;",
[value, event_id],
);
}
// get all chats
export async function getChats(account_id: number) {
const db = await connect();
return await db.select(`SELECT * FROM chats WHERE account_id <= "${account_id}" ORDER BY created_at DESC;`);
const db = await connect();
return await db.select(
`SELECT * FROM chats WHERE account_id <= "${account_id}" ORDER BY created_at DESC;`,
);
}
// create chat
export async function createChat(account_id: number, pubkey: string, created_at: number) {
const db = await connect();
return await db.execute('INSERT OR IGNORE INTO chats (account_id, pubkey, created_at) VALUES (?, ?, ?);', [
account_id,
pubkey,
created_at,
]);
export async function createChat(
account_id: number,
pubkey: string,
created_at: number,
) {
const db = await connect();
return await db.execute(
"INSERT OR IGNORE INTO chats (account_id, pubkey, created_at) VALUES (?, ?, ?);",
[account_id, pubkey, created_at],
);
}
// get last login
export async function getLastLogin() {
const db = await connect();
const result = await db.select(`SELECT value FROM settings WHERE key = "last_login";`);
return result[0]?.value;
const db = await connect();
const result = await db.select(
`SELECT value FROM settings WHERE key = "last_login";`,
);
return result[0]?.value;
}
// update last login
export async function updateLastLogin(value: number) {
const db = await connect();
return await db.execute(`UPDATE settings SET value = ${value} WHERE key = "last_login";`);
const db = await connect();
return await db.execute(
`UPDATE settings SET value = ${value} WHERE key = "last_login";`,
);
}
// get blacklist by kind and account id
export async function getBlacklist(account_id: number, kind: number) {
const db = await connect();
return await db.select(`SELECT * FROM blacklist WHERE account_id = "${account_id}" AND kind = "${kind}";`);
const db = await connect();
return await db.select(
`SELECT * FROM blacklist WHERE account_id = "${account_id}" AND kind = "${kind}";`,
);
}
// get active blacklist by kind and account id
export async function getActiveBlacklist(account_id: number, kind: number) {
const db = await connect();
return await db.select(
`SELECT content FROM blacklist WHERE account_id = "${account_id}" AND kind = "${kind}" AND status = 1;`
);
const db = await connect();
return await db.select(
`SELECT content FROM blacklist WHERE account_id = "${account_id}" AND kind = "${kind}" AND status = 1;`,
);
}
// add to blacklist
export async function addToBlacklist(account_id: number, content: string, kind: number, status?: number) {
const db = await connect();
return await db.execute('INSERT OR IGNORE INTO blacklist (account_id, content, kind, status) VALUES (?, ?, ?, ?);', [
account_id,
content,
kind,
status || 1,
]);
export async function addToBlacklist(
account_id: number,
content: string,
kind: number,
status?: number,
) {
const db = await connect();
return await db.execute(
"INSERT OR IGNORE INTO blacklist (account_id, content, kind, status) VALUES (?, ?, ?, ?);",
[account_id, content, kind, status || 1],
);
}
// update item in blacklist
export async function updateItemInBlacklist(content: string, status: number) {
const db = await connect();
return await db.execute(`UPDATE blacklist SET status = "${status}" WHERE content = "${content}";`);
const db = await connect();
return await db.execute(
`UPDATE blacklist SET status = "${status}" WHERE content = "${content}";`,
);
}

View File

@@ -1,93 +1,93 @@
import destr from 'destr';
import destr from "destr";
// convert NIP-02 to array of pubkey
export function nip02ToArray(tags: any) {
const arr = [];
tags.forEach((item) => {
arr.push(item[1]);
});
const arr = [];
tags.forEach((item) => {
arr.push(item[1]);
});
return arr;
return arr;
}
// convert array to NIP-02 tag list
export function arrayToNIP02(arr: string[]) {
const nip02_arr = [];
arr.forEach((item) => {
nip02_arr.push(['p', item]);
});
const nip02_arr = [];
arr.forEach((item) => {
nip02_arr.push(["p", item]);
});
return nip02_arr;
return nip02_arr;
}
// convert array object to pure array
export function arrayObjToPureArr(arr: any) {
const pure_arr = [];
arr.forEach((item) => {
pure_arr.push(item.content);
});
const pure_arr = [];
arr.forEach((item) => {
pure_arr.push(item.content);
});
return pure_arr;
return pure_arr;
}
// get parent id from event tags
export function getParentID(arr: string[], fallback: string) {
const tags = destr(arr);
let parentID = fallback;
const tags = destr(arr);
let parentID = fallback;
if (tags.length > 0) {
if (tags[0][0] === 'e') {
parentID = tags[0][1];
} else {
tags.forEach((tag) => {
if (tag[0] === 'e' && (tag[2] === 'root' || tag[3] === 'root')) {
parentID = tag[1];
}
});
}
}
if (tags.length > 0) {
if (tags[0][0] === "e") {
parentID = tags[0][1];
} else {
tags.forEach((tag) => {
if (tag[0] === "e" && (tag[2] === "root" || tag[3] === "root")) {
parentID = tag[1];
}
});
}
}
return parentID;
return parentID;
}
// check id present in event tags
export function isTagsIncludeID(id: string, arr: string[]) {
const tags = destr(arr);
const tags = destr(arr);
if (tags.length > 0) {
if (tags[0][1] === id) {
return true;
}
} else {
return false;
}
if (tags.length > 0) {
if (tags[0][1] === id) {
return true;
}
} else {
return false;
}
}
// get parent id from event tags
export function getQuoteID(arr: string[]) {
const tags = destr(arr);
let quoteID = null;
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];
}
});
}
}
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;
return quoteID;
}
// sort events by timestamp
export function sortEvents(arr: any) {
arr.sort((a, b) => {
return a.created_at - b.created_at;
});
arr.sort((a, b) => {
return a.created_at - b.created_at;
});
return arr;
return arr;
}