-
currentStream="_"}>Things
-
currentStream=""}>Streams
+
currentStream="_"}>Entries
+
currentStream=""}>Signals
diff --git a/ui/src/StreamPane.svelte b/ui/src/StreamPane.svelte
index bf88f42..6ee67f8 100644
--- a/ui/src/StreamPane.svelte
+++ b/ui/src/StreamPane.svelte
@@ -15,7 +15,7 @@
import type { Stream, Payload, Message } from "./stream";
import type { AgentPubKey } from "@holochain/client";
import { HoloHashMap } from "@holochain-open-dev/utils";
- import { debounce } from "lodash-es";
+ import { hashEqual } from "./util";
const { getStore }: any = getContext("store");
const store: ZipTestStore = getStore();
@@ -35,9 +35,10 @@
};
store.weaveClient?.walToPocket(attachment);
};
- const SCROLL_THRESHOLD = 100; // How close to the bottom must the user be to consider it "at the bottom"
type Results = {
+ from: AgentPubKey;
+ expected: number;
count: number;
acks: number;
};
@@ -46,29 +47,31 @@
$: myProfile = get(store.profilesStore.myProfile).value;
onMount(async () => {
- conversationContainer.addEventListener("scroll", handleScroll);
});
onDestroy(() => {
- conversationContainer.removeEventListener("scroll", handleScroll);
});
const getSources = (
messages: Message[],
acks: { [key: number]: HoloHashMap
}
) => {
- const sources: HoloHashMap = new HoloHashMap();
+ const sources: { [key: string]: Results } = {};
messages.forEach((m) => {
- const fromB6 = encodeHashToBase64(m.from);
- const r = sources.get(m.from);
- const results: Results = r ? r : { count: 1, acks: 0 };
- if (r) {
- results.count += 1;
- }
- if (fromB6 == store.myAgentPubKeyB64) {
- results.acks += getAckCount(acks, m.payload.created);
+ if (m.payload.type == "Msg") {
+ const [test, expected, count] = m.payload.text.split(".");
+ const r = sources[test];
+ const results: Results = r
+ ? r
+ : { expected: parseInt(expected), count: 1, acks: 0, from: m.from };
+ if (r) {
+ results.count += 1;
+ }
+ if (hashEqual(m.from, store.myAgentPubKey)) {
+ results.acks += getAckCount(acks, m.payload.created);
+ }
+ sources[test] = results;
}
- sources.set(m.from, results);
});
return sources;
};
@@ -79,10 +82,17 @@
$: lastSeen = store.lastSeen;
$: agentActive = store.agentActive;
- let inputElement;
+ let currentTest;
+ let currentTestExpected;
let inputCountElement;
let inputDelayElement;
let disabled;
+ const startTest = async () => {
+ const now = new Date();
+ currentTest = `${now.getTime()}`;
+ currentTestExpected = parseInt(inputCountElement.value);
+ await sendMessage();
+ };
const sendMessage = async () => {
let count = parseInt(inputCountElement.value);
let delay = parseInt(inputDelayElement.value);
@@ -92,18 +102,19 @@
inputCountElement.value = `${count}`;
if (count > 0) {
sendMessage();
+ } else {
+ currentTest = ""
}
}, delay);
};
- const _sendMessage = async (text) => {
+ const _sendMessage = async (count) => {
const payload: Payload = {
type: "Msg",
- text,
+ text: `${currentTest}.${currentTestExpected}.${count}`,
created: Date.now(),
};
console.log("SENDING TO", hashes);
await store.sendMessage(stream.id, payload, hashes);
- inputElement.value = "";
};
const getAckCount = (
acks: { [key: number]: HoloHashMap },
@@ -116,41 +127,7 @@
return 0;
};
let confirmDialog;
- const convertMessageText = (text: string): string => {
- let formatted = text.replace(
- /(https?:\/\/[^\s]+)/g,
- '$1'
- );
- formatted = formatted.replace(
- /(we:\/\/[^\s]+)/g,
- '$1'
- );
- return formatted;
- };
-
- let conversationContainer: HTMLElement;
-
- let scrollAtBottom = true;
- // Reactive update to scroll to the bottom every time the messages update,
- // but only if the user is near the bottom already
- $: if ($messages && $messages.length > 0) {
- if (scrollAtBottom) {
- setTimeout(scrollToBottom, 100);
- }
- }
-
- const handleScroll = debounce(() => {
- scrollAtBottom =
- conversationContainer.scrollHeight - conversationContainer.scrollTop <=
- conversationContainer.clientHeight + SCROLL_THRESHOLD;
- }, 100);
-
- function scrollToBottom() {
- if (conversationContainer) {
- conversationContainer.scrollTop = conversationContainer.scrollHeight;
- scrollAtBottom = true;
- }
- }
+
let showRecipients = 0;
@@ -165,18 +142,43 @@
-
- {#each $messages as msg}
- {@const isMyMessage =
- encodeHashToBase64(msg.from) == store.myAgentPubKeyB64}
-
- {#if msg.payload.type == "Msg"}
- {#if !isMyMessage && showFrom}
-
- {/if}
- {@html convertMessageText(msg.payload.text)}
-
{new Date(msg.payload.created).toLocaleTimeString()}
- {#if isMyMessage}
- {@const ackCount = getAckCount($acks, msg.payload.created)}
- {#if ackCount == hashes.length}
- ✓
- {:else if hashes.length > 1}
-
{
- if (showRecipients !== msg.payload.created) {
- showRecipients = msg.payload.created;
- }
- }}>{ackCount}
-
{
- showRecipients = 0;
- }}
- >
- {#if showRecipients === msg.payload.created}
- {@const keys = Array.from($acks[msg.payload.created].keys())}
-
-
- {"received by:"}
-
-
- {#each keys as agent, i}
-
{#if i < keys.length - 1},{/if}
- {/each}
-
-
- {/if}
-
- {/if}
- {/if}
- {/if}
-
- {/each}
-
-
-
-
- (disabled = !e.target.value || !inputElement.value)}
- on:keydown={(e) => {
- if (e.keyCode == 13) {
- _sendMessage(inputElement.value);
- e.stopPropagation();
- }
- }}
- label="Message"
- >
-
-
-
+
diff --git a/ui/src/ThingsPane.svelte b/ui/src/ThingsPane.svelte
index c72e265..1bde2b9 100644
--- a/ui/src/ThingsPane.svelte
+++ b/ui/src/ThingsPane.svelte
@@ -113,12 +113,13 @@
createBunch()}
- >New Bunch
+ >New Test