2023-06-30 14:05:57 +00:00
|
|
|
/** @jsx h */
|
2024-03-15 13:44:17 +00:00
|
|
|
import { fail } from "https://deno.land/std@0.176.0/testing/asserts.ts";
|
2023-09-06 16:29:27 +00:00
|
|
|
import { h, render } from "https://esm.sh/preact@10.17.1";
|
2024-03-15 13:44:17 +00:00
|
|
|
import { prepareEncryptedNostrEvent } from "../../libs/nostr.ts/event.ts";
|
2024-01-01 17:28:10 +00:00
|
|
|
import { InMemoryAccountContext, NostrKind } from "../../libs/nostr.ts/nostr.ts";
|
|
|
|
import { relays } from "../../libs/nostr.ts/relay-list.test.ts";
|
|
|
|
import { ConnectionPool } from "../../libs/nostr.ts/relay-pool.ts";
|
|
|
|
import { test_db_view, testEventBus } from "./_setup.test.ts";
|
|
|
|
import { DirectedMessageController } from "../features/dm.ts";
|
2024-03-15 13:44:17 +00:00
|
|
|
import { DM_List } from "./conversation-list.ts";
|
|
|
|
import { MessagePanel } from "./message-panel.tsx";
|
|
|
|
import { sleep } from "https://raw.githubusercontent.com/BlowaterNostr/csp/master/csp.ts";
|
2023-09-11 15:27:38 +00:00
|
|
|
|
2024-03-15 13:44:17 +00:00
|
|
|
const pool = new ConnectionPool();
|
|
|
|
pool.addRelayURL(relays[2]);
|
2023-11-17 07:50:53 +00:00
|
|
|
const database = await test_db_view();
|
2023-11-16 13:22:18 +00:00
|
|
|
|
2024-03-15 13:44:17 +00:00
|
|
|
const ctx = InMemoryAccountContext.Generate();
|
|
|
|
const dmController = new DirectedMessageController(ctx);
|
2023-09-11 15:27:38 +00:00
|
|
|
|
2024-03-15 13:44:17 +00:00
|
|
|
const event = await prepareEncryptedNostrEvent(ctx, {
|
|
|
|
content: `test`,
|
|
|
|
encryptKey: ctx.publicKey,
|
|
|
|
kind: NostrKind.DIRECT_MESSAGE,
|
|
|
|
tags: [
|
|
|
|
["p", ctx.publicKey.hex],
|
|
|
|
],
|
|
|
|
});
|
|
|
|
if (event instanceof Error) fail(event.message);
|
2023-06-30 14:05:57 +00:00
|
|
|
|
2024-03-15 13:44:17 +00:00
|
|
|
await dmController.addEvent(event);
|
2023-10-04 21:34:43 +00:00
|
|
|
|
2024-03-15 13:44:17 +00:00
|
|
|
const messages = dmController.getChatMessages(ctx.publicKey.hex);
|
2023-09-11 18:09:38 +00:00
|
|
|
|
2024-03-15 13:44:17 +00:00
|
|
|
for (let i = 10;; i++) {
|
|
|
|
messages.push({
|
|
|
|
author: ctx.publicKey,
|
|
|
|
content: `${i}`,
|
|
|
|
created_at: new Date(),
|
|
|
|
event: messages[0].event,
|
|
|
|
lamport: i,
|
|
|
|
type: "text",
|
|
|
|
});
|
|
|
|
render(
|
|
|
|
<div class="w-screen h-screen">
|
|
|
|
<MessagePanel
|
|
|
|
getters={{
|
|
|
|
profileGetter: database,
|
|
|
|
relayRecordGetter: database,
|
|
|
|
isUserBlocked: new DM_List(ctx).isUserBlocked,
|
|
|
|
getEventByID: database.getEventByID,
|
|
|
|
}}
|
|
|
|
myPublicKey={ctx.publicKey}
|
|
|
|
emit={testEventBus.emit}
|
|
|
|
eventSub={testEventBus}
|
|
|
|
messages={messages}
|
|
|
|
/>
|
|
|
|
</div>,
|
|
|
|
document.body,
|
|
|
|
);
|
|
|
|
await sleep(100);
|
2023-09-11 18:09:38 +00:00
|
|
|
}
|