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";
// @ts-expect-error
import Nostrich from "../nostrich.jpg";
// @ts-expect-error
import { hexToBech32 } from "../Util";
import type { User } from "../nostr/types";
import { db } from "../db";

View File

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

View File

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

View File

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

View File

@ -107,7 +107,7 @@ export default function ProfilePage() {
function avatar() {
return (
<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>
)

View File

@ -84,14 +84,7 @@ const UsersSlice = createSlice({
};
}
state.users[x.pubkey] = x;
db.users.put({
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));
db.users.put(x)
state.users = {
...state.users