update chats
This commit is contained in:
@@ -13,7 +13,11 @@ export function ChatMessageList() {
|
||||
const itemContent: any = useCallback(
|
||||
(index: string | number) => {
|
||||
return (
|
||||
<ChatMessageItem data={messages[index]} userPrivkey={account.privkey} />
|
||||
<ChatMessageItem
|
||||
data={messages[index]}
|
||||
userPubkey={account.pubkey}
|
||||
userPrivkey={account.privkey}
|
||||
/>
|
||||
);
|
||||
},
|
||||
[account.privkey, account.pubkey, messages],
|
||||
|
||||
@@ -7,13 +7,14 @@ import { memo } from "react";
|
||||
|
||||
export const ChatMessageItem = memo(function ChatMessageItem({
|
||||
data,
|
||||
userPubkey,
|
||||
userPrivkey,
|
||||
}: {
|
||||
data: any;
|
||||
userPubkey: string;
|
||||
userPrivkey: string;
|
||||
}) {
|
||||
const decryptedContent = useDecryptMessage(data, userPrivkey);
|
||||
console.log(decryptedContent);
|
||||
const decryptedContent = useDecryptMessage(data, userPubkey, userPrivkey);
|
||||
// if we have decrypted content, use it instead of the encrypted content
|
||||
if (decryptedContent) {
|
||||
data["content"] = decryptedContent;
|
||||
@@ -26,7 +27,7 @@ export const ChatMessageItem = memo(function ChatMessageItem({
|
||||
<div className="flex flex-col">
|
||||
<ChatMessageUser pubkey={data.sender_pubkey} time={data.created_at} />
|
||||
<div className="-mt-[20px] pl-[49px]">
|
||||
<div className="whitespace-pre-line break-words text-base leading-tight">
|
||||
<div className="whitespace-pre-line break-words text-base text-zinc-100 leading-tight">
|
||||
{content.parsed || ""}
|
||||
</div>
|
||||
{Array.isArray(content.images) && content.images.length ? (
|
||||
|
||||
@@ -35,7 +35,7 @@ export function ChatMessageUser({
|
||||
</div>
|
||||
<div className="flex w-full flex-1 items-start justify-between">
|
||||
<div className="flex items-baseline gap-2 text-base">
|
||||
<span className="font-semibold leading-none text-white group-hover:underline">
|
||||
<span className="font-semibold leading-none text-zinc-200 group-hover:underline">
|
||||
{user?.nip05 || user?.name || shortenKey(pubkey)}
|
||||
</span>
|
||||
<span className="leading-none text-zinc-500">·</span>
|
||||
|
||||
@@ -16,13 +16,24 @@ export function ChatSidebar({ pubkey }: { pubkey: string }) {
|
||||
className="h-11 w-11 rounded-md object-cover"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<h3 className="leading-none text-lg font-semibold">
|
||||
{user?.display_name || user?.name}
|
||||
</h3>
|
||||
<p className="leading-none text-zinc-400">
|
||||
{user?.nip05 || user?.username || shortenKey(pubkey)}
|
||||
</p>
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex flex-col gap-1">
|
||||
<h3 className="leading-none text-lg font-semibold">
|
||||
{user?.display_name || user?.name}
|
||||
</h3>
|
||||
<h5 className="leading-none text-zinc-400">
|
||||
{user?.nip05 || user?.username || shortenKey(pubkey)}
|
||||
</h5>
|
||||
</div>
|
||||
<div>
|
||||
<p className="leading-tight">{user?.bio || user?.about}</p>
|
||||
<a
|
||||
href={`/app/user?npub=${user.npub}`}
|
||||
className="mt-3 inline-flex w-full h-10 items-center justify-center rounded-md bg-zinc-900 hover:bg-zinc-800 text-sm text-zinc-300 hover:text-zinc-100 font-medium"
|
||||
>
|
||||
View full profile
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import { nip04 } from "nostr-tools";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useDecryptMessage(data: any, userPriv: string) {
|
||||
export function useDecryptMessage(
|
||||
data: any,
|
||||
userPubkey: string,
|
||||
userPriv: string,
|
||||
) {
|
||||
const [content, setContent] = useState(data.content);
|
||||
|
||||
useEffect(() => {
|
||||
async function decrypt() {
|
||||
const result = await nip04.decrypt(
|
||||
userPriv,
|
||||
data.sender_pubkey,
|
||||
data.content,
|
||||
);
|
||||
const pubkey =
|
||||
userPubkey === data.sender_pubkey
|
||||
? data.receiver_pubkey
|
||||
: data.sender_pubkey;
|
||||
const result = await nip04.decrypt(userPriv, pubkey, data.content);
|
||||
setContent(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,15 +33,15 @@ export function Page() {
|
||||
const getQuery = useCallback(() => {
|
||||
const query = [];
|
||||
const follows = JSON.parse(account.follows);
|
||||
const last = parseInt(lastLogin);
|
||||
|
||||
let queryNoteSince: number;
|
||||
let querySince: number;
|
||||
|
||||
if (totalNotes === 0) {
|
||||
queryNoteSince = dateToUnix(getHourAgo(48, now.current));
|
||||
} else {
|
||||
if (parseInt(lastLogin) > 0) {
|
||||
queryNoteSince = parseInt(lastLogin);
|
||||
queryNoteSince = last;
|
||||
} else {
|
||||
queryNoteSince = dateToUnix(getHourAgo(48, now.current));
|
||||
}
|
||||
@@ -58,21 +58,21 @@ export function Page() {
|
||||
query.push({
|
||||
kinds: [4],
|
||||
"#p": [account.pubkey],
|
||||
since: querySince,
|
||||
since: last,
|
||||
});
|
||||
|
||||
// kind 4 (chats) query
|
||||
query.push({
|
||||
kinds: [4],
|
||||
authors: [account.pubkey],
|
||||
since: querySince,
|
||||
since: last,
|
||||
});
|
||||
|
||||
// kind 43, 43 (mute user, hide message) query
|
||||
query.push({
|
||||
authors: [account.pubkey],
|
||||
kinds: [43, 44],
|
||||
since: querySince,
|
||||
since: last,
|
||||
});
|
||||
|
||||
return query;
|
||||
@@ -107,8 +107,8 @@ export function Page() {
|
||||
const receiver = event.tags.find((t) => t[0] === "p")[1];
|
||||
createChat(
|
||||
event.id,
|
||||
event.pubkey,
|
||||
receiver,
|
||||
event.pubkey,
|
||||
event.content,
|
||||
event.tags,
|
||||
event.created_at,
|
||||
@@ -116,8 +116,8 @@ export function Page() {
|
||||
} else {
|
||||
createChat(
|
||||
event.id,
|
||||
event.pubkey,
|
||||
account.pubkey,
|
||||
event.pubkey,
|
||||
event.content,
|
||||
event.tags,
|
||||
event.created_at,
|
||||
|
||||
Reference in New Issue
Block a user