2023-06-30 14:05:57 +00:00
|
|
|
/** @jsx h */
|
2023-09-06 16:29:27 +00:00
|
|
|
import { h, render } from "https://esm.sh/preact@10.17.1";
|
2023-06-30 14:05:57 +00:00
|
|
|
import { MessagePanel } from "./message-panel.tsx";
|
2023-09-14 12:02:56 +00:00
|
|
|
import { InvalidKey, PrivateKey } from "../lib/nostr-ts/key.ts";
|
2023-09-11 15:27:38 +00:00
|
|
|
import { InMemoryAccountContext, NostrKind } from "../lib/nostr-ts/nostr.ts";
|
2023-11-16 13:22:18 +00:00
|
|
|
import { Datebase_View } from "../database.ts";
|
2023-11-17 07:06:11 +00:00
|
|
|
import { testEventBus, testEventMarker, testEventsAdapter, testRelayAdapter } from "./_setup.test.ts";
|
2023-09-11 15:27:38 +00:00
|
|
|
import { prepareNormalNostrEvent } from "../lib/nostr-ts/event.ts";
|
2023-10-15 22:39:21 +00:00
|
|
|
import { DM_List } from "./conversation-list.ts";
|
2023-09-11 15:27:38 +00:00
|
|
|
import { EventSyncer } from "./event_syncer.ts";
|
2023-11-03 13:09:13 +00:00
|
|
|
import { ConnectionPool } from "../lib/nostr-ts/relay-pool.ts";
|
2023-10-01 20:59:07 +00:00
|
|
|
import { ProfileSyncer } from "../features/profile.ts";
|
2023-09-11 18:09:38 +00:00
|
|
|
import { handle_SendMessage } from "./app_update.tsx";
|
|
|
|
import { LamportTime } from "../time.ts";
|
|
|
|
import { initialModel } from "./app_model.ts";
|
|
|
|
import { relays } from "../lib/nostr-ts/relay-list.test.ts";
|
2023-09-14 12:02:56 +00:00
|
|
|
import { fail } from "https://deno.land/std@0.176.0/testing/asserts.ts";
|
2023-11-16 13:22:18 +00:00
|
|
|
import { GroupChatSyncer, GroupMessageController } from "../features/gm.ts";
|
2023-09-11 15:27:38 +00:00
|
|
|
|
|
|
|
const ctx = InMemoryAccountContext.New(PrivateKey.Generate());
|
2023-11-17 07:50:53 +00:00
|
|
|
const database = await test_db_view();
|
2023-11-16 13:22:18 +00:00
|
|
|
|
2023-09-11 18:09:38 +00:00
|
|
|
const lamport = new LamportTime(0);
|
2023-09-11 15:27:38 +00:00
|
|
|
|
2023-11-16 13:22:18 +00:00
|
|
|
await database.addEvent(
|
|
|
|
await prepareNormalNostrEvent(ctx, {
|
|
|
|
content: "hi",
|
|
|
|
kind: NostrKind.TEXT_NOTE,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
await database.addEvent(
|
|
|
|
await prepareNormalNostrEvent(ctx, {
|
|
|
|
content: "hi 2",
|
|
|
|
kind: NostrKind.TEXT_NOTE,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
await database.addEvent(
|
|
|
|
await prepareNormalNostrEvent(ctx, {
|
|
|
|
content: "hi 3",
|
|
|
|
kind: NostrKind.TEXT_NOTE,
|
|
|
|
}),
|
|
|
|
);
|
2023-09-11 15:27:38 +00:00
|
|
|
const pool = new ConnectionPool();
|
2023-09-11 18:09:38 +00:00
|
|
|
const model = initialModel();
|
|
|
|
pool.addRelayURL(relays[0]);
|
2023-11-16 13:22:18 +00:00
|
|
|
const groupMessageController = new GroupMessageController(
|
|
|
|
ctx,
|
|
|
|
new GroupChatSyncer(database, pool),
|
|
|
|
new ProfileSyncer(database, pool),
|
|
|
|
);
|
2023-06-30 14:05:57 +00:00
|
|
|
|
2023-10-21 11:29:47 +00:00
|
|
|
const editor = model.dmEditors.get(ctx.publicKey.hex);
|
2023-10-04 21:34:43 +00:00
|
|
|
|
2023-09-11 18:09:38 +00:00
|
|
|
const view = () => {
|
2023-10-04 21:34:43 +00:00
|
|
|
if (editor == undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2023-09-11 18:09:38 +00:00
|
|
|
return (
|
|
|
|
<MessagePanel
|
2023-11-16 13:22:18 +00:00
|
|
|
profileGetter={database}
|
2023-10-04 21:34:43 +00:00
|
|
|
/**
|
|
|
|
* If we use a map to store all editor models,
|
|
|
|
* need to distinguish editor models for DMs and GMs
|
|
|
|
*/
|
|
|
|
editorModel={editor}
|
2023-09-11 18:09:38 +00:00
|
|
|
eventSyncer={new EventSyncer(pool, database)}
|
|
|
|
focusedContent={undefined}
|
|
|
|
myPublicKey={ctx.publicKey}
|
2023-10-01 20:59:07 +00:00
|
|
|
profilesSyncer={new ProfileSyncer(database, pool)}
|
2023-09-14 12:02:56 +00:00
|
|
|
emit={testEventBus.emit}
|
2023-10-04 21:34:43 +00:00
|
|
|
messages={[]}
|
2023-09-11 18:09:38 +00:00
|
|
|
rightPanelModel={{
|
|
|
|
show: true,
|
|
|
|
}}
|
2023-10-07 10:59:06 +00:00
|
|
|
isGroupChat={false}
|
2023-09-11 18:09:38 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2023-06-30 14:05:57 +00:00
|
|
|
|
2023-09-11 18:09:38 +00:00
|
|
|
render(view(), document.body);
|
|
|
|
|
|
|
|
for await (const e of testEventBus.onChange()) {
|
|
|
|
console.log(e);
|
|
|
|
if (e.type == "SendMessage") {
|
|
|
|
const err = await handle_SendMessage(
|
|
|
|
e,
|
|
|
|
ctx,
|
|
|
|
lamport,
|
|
|
|
pool,
|
2023-10-21 11:29:47 +00:00
|
|
|
model.dmEditors,
|
2023-11-16 13:22:18 +00:00
|
|
|
model.gmEditors,
|
2023-09-11 18:09:38 +00:00
|
|
|
database,
|
2023-11-16 13:22:18 +00:00
|
|
|
groupMessageController,
|
2023-09-11 18:09:38 +00:00
|
|
|
);
|
|
|
|
if (err instanceof Error) {
|
|
|
|
console.error("update:SendMessage", err);
|
|
|
|
continue; // todo: global error toast
|
|
|
|
}
|
2023-10-07 10:59:06 +00:00
|
|
|
} else if (e.type == "UpdateEditorText") {
|
2023-09-11 18:09:38 +00:00
|
|
|
}
|
|
|
|
render(view(), document.body);
|
|
|
|
}
|