added reply message to channel

This commit is contained in:
Ren Amamiya
2023-04-12 10:03:16 +07:00
parent ac5e78a6b8
commit d8d3113fb9
21 changed files with 336 additions and 70 deletions

View File

@@ -68,18 +68,6 @@ export function getChats(data: GetChatData) {
return invoke<Chat[]>('get_chats', { data });
}
export type CreateNoteData = {
event_id: string;
pubkey: string;
kind: number;
tags: string;
content: string;
parent_id: string;
parent_comment_id: string;
created_at: number;
account_id: number;
};
export type CreatePlebData = { pleb_id: string; pubkey: string; kind: number; metadata: string; account_id: number };
export type Note = {
id: number;
eventId: string;
@@ -92,19 +80,31 @@ export type Note = {
createdAt: number;
accountId: number;
};
export type CreateChatData = { pubkey: string; created_at: number; account_id: number };
export type GetNoteByIdData = { event_id: string };
export type CreateChannelData = { event_id: string; content: string; account_id: number };
export type CreatePlebData = { pleb_id: string; pubkey: string; kind: number; metadata: string; account_id: number };
export type Chat = { id: number; pubkey: string; createdAt: number; accountId: number };
export type Account = { id: number; pubkey: string; privkey: string; active: boolean; metadata: string };
export type GetChatData = { account_id: number };
export type GetChannelData = { limit: number; offset: number };
export type CreateChannelData = { event_id: string; content: string; account_id: number };
export type GetPlebPubkeyData = { pubkey: string };
export type UpdateChannelData = { event_id: string; active: boolean };
export type GetActiveChannelData = { active: boolean };
export type GetPlebData = { account_id: number };
export type CreateAccountData = { pubkey: string; privkey: string; metadata: string };
export type Channel = { id: number; eventId: string; content: string; active: boolean; accountId: number };
export type GetLatestNoteData = { date: number };
export type GetPlebData = { account_id: number; kind: number };
export type CreateAccountData = { pubkey: string; privkey: string; metadata: string };
export type GetPlebPubkeyData = { pubkey: string };
export type Channel = { id: number; eventId: string; content: string; active: boolean; accountId: number };
export type GetChatData = { account_id: number };
export type CreateNoteData = {
event_id: string;
pubkey: string;
kind: number;
tags: string;
content: string;
parent_id: string;
parent_comment_id: string;
created_at: number;
account_id: number;
};
export type UpdateChannelData = { event_id: string; active: boolean };
export type Pleb = { id: number; plebId: string; pubkey: string; kind: number; metadata: string; accountId: number };
export type CreateChatData = { pubkey: string; created_at: number; account_id: number };
export type GetNoteData = { date: number; limit: number; offset: number };
export type GetActiveChannelData = { active: boolean };
export type GetNoteByIdData = { event_id: string };

View File

@@ -12,18 +12,35 @@ export const fetchMetadata = async (pubkey: string) => {
export const useMetadata = (pubkey) => {
const [profile, setProfile] = useState(null);
/*
const insertPlebToDB = useCallback(async (account, pubkey, metadata) => {
const { createPleb } = await import('@utils/bindings');
return await createPleb({
pleb_id: pubkey + '-lume' + account.toString(),
pubkey: pubkey,
kind: 1,
metadata: metadata,
account_id: account,
}).catch(console.error);
}, []);
*/
const getCachedMetadata = useCallback(async () => {
const { getPlebByPubkey } = await import('@utils/bindings');
getPlebByPubkey({ pubkey: pubkey })
.then((res) => {
if (res) {
const metadata = JSON.parse(res.metadata);
// update state
setProfile(metadata);
} else {
fetchMetadata(pubkey).then((res: any) => {
if (res.content) {
const metadata = JSON.parse(res.content);
// update state
setProfile(metadata);
// save to database
// insertPlebToDB(activeAccount.id, pubkey, metadata);
}
});
}