Rebase fixup

This commit is contained in:
Kieran 2023-01-15 22:59:05 +00:00
parent c7e42c1f75
commit bd247991bc
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
6 changed files with 18 additions and 26 deletions

View File

@ -10,7 +10,6 @@ import "@webscopeio/react-textarea-autocomplete/style.css";
import "./Textarea.css"; import "./Textarea.css";
// @ts-expect-error // @ts-expect-error
import Nostrich from "../nostrich.jpg"; import Nostrich from "../nostrich.jpg";
// @ts-expect-error
import { hexToBech32 } from "../Util"; import { hexToBech32 } from "../Util";
import type { User } from "../nostr/types"; import type { User } from "../nostr/types";
import { db } from "../db"; import { db } from "../db";

View File

@ -58,9 +58,11 @@ export default function useEventPublisher() {
} }
return { return {
broadcast: (ev: NEvent) => { broadcast: (ev: NEvent | undefined) => {
console.debug("Sending event: ", ev); if (ev) {
System.BroadcastEvent(ev); console.debug("Sending event: ", ev);
System.BroadcastEvent(ev);
}
}, },
metadata: async (obj: UserMetadata) => { metadata: async (obj: UserMetadata) => {
if (pubKey) { if (pubKey) {

View File

@ -41,11 +41,10 @@ export default function useLoginFeed() {
useEffect(() => { useEffect(() => {
let contactList = main.notes.filter(a => a.kind === EventKind.ContactList); let contactList = main.notes.filter(a => a.kind === EventKind.ContactList);
let notifications = main.notes.filter(a => a.kind === EventKind.TextNote); let notifications = main.notes.filter(a => a.kind === EventKind.TextNote);
let metadata = main.notes.filter(a => a.kind === EventKind.SetMetadata) let metadata = main.notes.filter(a => a.kind === EventKind.SetMetadata);
.map(a => mapEventToProfile(a)) let profiles = metadata.map(a => mapEventToProfile(a))
.filter(a => a !== undefined) .filter(a => a !== undefined)
.map(a => a!); .map(a => a!);
let profiles = metadata.map(a => mapEventToProfile(a));
let dms = main.notes.filter(a => a.kind === EventKind.DirectMessage); let dms = main.notes.filter(a => a.kind === EventKind.DirectMessage);
for (let cl of contactList) { for (let cl of contactList) {
@ -65,10 +64,7 @@ export default function useLoginFeed() {
} }
dispatch(addNotifications(notifications)); dispatch(addNotifications(notifications));
dispatch(setUserData(profiles)); dispatch(setUserData(profiles));
const userMetadata = metadata.map(ev => { db.users.bulkPut(profiles);
return {...JSON.parse(ev.content), pubkey: ev.pubkey }
})
db.users.bulkPut(metadata);
dispatch(addDirectMessage(dms)); dispatch(addDirectMessage(dms));
}, [main]); }, [main]);
} }

View File

@ -21,7 +21,7 @@ type RouterParams = {
export default function ChatPage() { export default function ChatPage() {
const params = useParams<RouterParams>(); const params = useParams<RouterParams>();
const publisher = useEventPublisher(); const publisher = useEventPublisher();
const id = bech32ToHex(params.id); const id = bech32ToHex(params.id ?? "");
const dms = useSelector<any, RawEvent[]>(s => filterDms(s.login.dms, s.login.publicKey)); const dms = useSelector<any, RawEvent[]>(s => filterDms(s.login.dms, s.login.publicKey));
const [content, setContent] = useState<string>(); const [content, setContent] = useState<string>();
const { ref, inView, entry } = useInView(); const { ref, inView, entry } = useInView();
@ -49,15 +49,17 @@ export default function ChatPage() {
}, [inView, dmListRef, sortedDms]); }, [inView, dmListRef, sortedDms]);
async function sendDm() { async function sendDm() {
let ev = await publisher.sendDm(content, id); if (content) {
console.debug(ev); let ev = await publisher.sendDm(content, id);
publisher.broadcast(ev); console.debug(ev);
setContent(""); publisher.broadcast(ev);
setContent(undefined);
}
} }
async function onEnter(e: KeyboardEvent) { async function onEnter(e: KeyboardEvent) {
let isEnter = e.code === "Enter"; let isEnter = e.code === "Enter";
if(isEnter && !e.shiftKey) { if (isEnter && !e.shiftKey) {
await sendDm(); await sendDm();
} }
} }

View File

@ -107,7 +107,7 @@ export default function ProfilePage() {
function avatar() { function avatar() {
return ( return (
<div className="avatar-wrapper"> <div className="avatar-wrapper">
<div style={{ '--img-url': backgroundImage }} className="avatar" data-domain={isVerified ? domain : ''}> <div style={{ '--img-url': backgroundImage }} className="avatar" data-domain={domain?.toLowerCase()}>
</div> </div>
</div> </div>
) )

View File

@ -84,14 +84,7 @@ const UsersSlice = createSlice({
}; };
} }
state.users[x.pubkey] = x; state.users[x.pubkey] = x;
db.users.put({ db.users.put(x)
pubkey: x.pubkey,
name: x.name,
display_name: x.display_name,
nip05: x.nip05,
picture: x.picture,
})
window.localStorage.setItem(`user:${x.pubkey}`, JSON.stringify(x));
state.users = { state.users = {
...state.users ...state.users