This commit is contained in:
smolgrrr 2023-11-27 14:43:32 +11:00
parent 5404ad0bf9
commit 316c31206e
3 changed files with 95 additions and 97 deletions

View File

@ -1,8 +1,8 @@
import {
ArrowUpTrayIcon,
ServerIcon,
CpuChipIcon,
ArrowPathIcon,
FaceSmileIcon
PlusCircleIcon
} from "@heroicons/react/24/outline";
import { XCircleIcon } from "@heroicons/react/24/solid";
import { useState, useEffect, useRef } from "react";
@ -135,13 +135,13 @@ const NewNoteCard = ({
>
<input type="hidden" name="MAX_FILE_SIZE" defaultValue={2.5 * 1024 * 1024} />
<div className="px-4 flex flex-col rounded-lg">
{"C:\\WIRE>"}
<textarea
name="com"
wrap="soft"
className="shadow-lg w-full px-4 py-3 h-28 border-none bg-black text-white"
className="shadow-lg w-full px-4 py-3 border-blue-500 bg-black text-white"
value={comment}
onChange={(e) => setComment(e.target.value)}
rows={comment.split('\n').length || 1}
/>
<div className="relative">
{file !== "" && (
@ -172,10 +172,10 @@ const NewNoteCard = ({
ref={emojiRef}
/>
)}
<FaceSmileIcon className="h-4 w-4 text-neutral-400 cursor-pointer" onClick={pickEmoji} />
<PlusCircleIcon className="h-4 w-4 text-neutral-400 cursor-pointer" onClick={pickEmoji} />
</div>
<div className="flex items-center">
<ArrowUpTrayIcon
<ServerIcon
className="h-4 w-4 text-neutral-400 cursor-pointer"
onClick={() => document.getElementById("file_input")?.click()}
/>

View File

@ -10,7 +10,7 @@ export default function Header() {
<div className="flex items-center gap-2">
<img src="/icon.png" className="h-12" alt="logo" />
<span className="font-semibold text-white">
{'>'}.. Wired
{"~\\WIRED>"}
</span>
</div>
</a>

View File

@ -1,95 +1,95 @@
import {sub, subOnce, unsubAll} from './relays';
import { sub, subOnce, unsubAll } from './relays';
import { Event } from 'nostr-tools';
type SubCallback = (
event: Event,
relay: string,
) => void;
event: Event,
relay: string,
) => void;
/** subscribe to global feed */
export const subGlobalFeed = (onEvent: SubCallback) => {
console.info('subscribe to global feed');
unsubAll();
const now = Math.floor(Date.now() * 0.001);
const pubkeys = new Set<string>();
const notes = new Set<string>();
const prefix = Math.floor(16 / 4); // 4 bits in each '0' character
sub({ // get past events
cb: (evt, relay) => {
pubkeys.add(evt.pubkey);
notes.add(evt.id);
onEvent(evt, relay);
},
filter: {
...(prefix && {ids: ['0'.repeat(prefix)]}),
kinds: [1],
since: Math.floor((Date.now() * 0.001) - (24 * 60 * 60)),
limit: 500,
},
unsub: true
});
// // New Callback to only add events that pass the PoW requirement
// const powFilteredCallback = (evt: Event, relay: string) => {
// if (getPow(evt.id) > 2) { // Replace '5' with your actual PoW requirement
// pubkeys.add(evt.pubkey);
// notes.add(evt.id);
// onEvent(evt, relay);
// }
// };
console.info('subscribe to global feed');
unsubAll();
const now = Math.floor(Date.now() * 0.001);
const pubkeys = new Set<string>();
const notes = new Set<string>();
const prefix = Math.floor(16 / 4); // 4 bits in each '0' character
sub({ // get past events
cb: (evt, relay) => {
pubkeys.add(evt.pubkey);
notes.add(evt.id);
onEvent(evt, relay);
},
filter: {
...(prefix && { ids: ['0'.repeat(prefix)] }),
kinds: [1],
since: Math.floor((Date.now() * 0.001) - (24 * 60 * 60)),
limit: 500,
},
unsub: true
});
setTimeout(() => {
// get profile info
sub({
cb: onEvent,
filter: {
authors: Array.from(pubkeys),
kinds: [0],
limit: pubkeys.size,
},
unsub: true,
});
pubkeys.clear();
sub({
cb: onEvent,
filter: {
'#e': Array.from(notes),
kinds: [1],
},
unsub: true,
});
// // New Callback to only add events that pass the PoW requirement
// const powFilteredCallback = (evt: Event, relay: string) => {
// if (getPow(evt.id) > 2) { // Replace '5' with your actual PoW requirement
// pubkeys.add(evt.pubkey);
// notes.add(evt.id);
// onEvent(evt, relay);
// }
// };
notes.clear();
}, 2000);
// subscribe to future notes, reactions and profile updates
setTimeout(() => {
// get profile info
sub({
cb: (evt, relay) => {
onEvent(evt, relay);
if (
evt.kind !== 1
|| pubkeys.has(evt.pubkey)
) {
return;
}
subOnce({ // get profile data
relay,
cb: onEvent,
filter: {
authors: [evt.pubkey],
kinds: [0],
limit: 1,
}
});
},
cb: onEvent,
filter: {
...(prefix && {ids: ['0'.repeat(prefix)]}),
kinds: [1],
since: now,
authors: Array.from(pubkeys),
kinds: [0],
limit: pubkeys.size,
},
unsub: true,
});
};
pubkeys.clear();
sub({
cb: onEvent,
filter: {
'#e': Array.from(notes),
kinds: [1],
},
unsub: true,
});
notes.clear();
}, 2000);
// subscribe to future notes, reactions and profile updates
sub({
cb: (evt, relay) => {
onEvent(evt, relay);
if (
evt.kind !== 1
|| pubkeys.has(evt.pubkey)
) {
return;
}
subOnce({ // get profile data
relay,
cb: onEvent,
filter: {
authors: [evt.pubkey],
kinds: [0],
limit: 1,
}
});
},
filter: {
...(prefix && { ids: ['0'.repeat(prefix)] }),
kinds: [1],
since: now,
},
});
};
/** subscribe to global feed */
export const simpleSub24hFeed = (onEvent: SubCallback) => {
@ -158,16 +158,14 @@ export const subNote = (
}, 2000);
replies.add(eventId);
setTimeout(() => {
sub({
cb: onReply,
filter: {
'#e': [eventId],
kinds: [1],
},
unsub: true, // TODO: probably keep this subscription also after onReply/unsubAll
});
}, 200);
// subscribe to future replies
sub({
cb: onReply,
filter: {
'#e': [eventId],
kinds: [1],
},
});
};
/** quick subscribe to a note id (nip-19) */