fix: expired local msg

This commit is contained in:
Tristan Yang
2025-03-26 11:20:47 +08:00
parent 5c42e5f4a1
commit 7b8e6c28ac
2 changed files with 28 additions and 7 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "vocechat-web", "name": "vocechat-web",
"version": "0.9.2", "version": "0.9.3",
"homepage": "https://voce.chat", "homepage": "https://voce.chat",
"dependencies": { "dependencies": {
"@metamask/onboarding": "^1.0.1", "@metamask/onboarding": "^1.0.1",
+27 -6
View File
@@ -1,4 +1,4 @@
import React, { useEffect } from "react"; import { useEffect, useRef } from "react";
import clsx from "clsx"; import clsx from "clsx";
import useExpiredResMap from "@/hooks/useExpiredResMap"; import useExpiredResMap from "@/hooks/useExpiredResMap";
@@ -7,6 +7,9 @@ import IconImage from "@/assets/icons/file.image.svg";
import IconUnknown from "@/assets/icons/file.unknown.svg"; import IconUnknown from "@/assets/icons/file.unknown.svg";
import IconVideo from "@/assets/icons/file.video.svg"; import IconVideo from "@/assets/icons/file.video.svg";
import IconInfo from "@/assets/icons/info.svg"; import IconInfo from "@/assets/icons/info.svg";
import { useLocation } from "react-router-dom";
import useRemoveLocalMessage from "../../hooks/useRemoveLocalMessage";
import { ChatContext } from "../../types/common";
type Props = { type Props = {
type?: "file" | "audio" | "image" | "video"; type?: "file" | "audio" | "image" | "video";
@@ -16,25 +19,33 @@ const InfoMap = {
file: { file: {
title: "File not Found", title: "File not Found",
desc: "File expired or deleted", desc: "File expired or deleted",
icon: <IconUnknown className="w-9 shrink-0 h-auto grayscale" /> icon: <IconUnknown className="w-9 shrink-0 h-auto grayscale" />,
}, },
audio: { audio: {
title: "Audio not Found", title: "Audio not Found",
desc: "Audio expired or deleted", desc: "Audio expired or deleted",
icon: <IconAudio className="w-9 shrink-0 h-auto grayscale" /> icon: <IconAudio className="w-9 shrink-0 h-auto grayscale" />,
}, },
image: { image: {
title: "Image not Found", title: "Image not Found",
desc: "Image expired or deleted", desc: "Image expired or deleted",
icon: <IconImage className="w-9 shrink-0 h-auto grayscale" /> icon: <IconImage className="w-9 shrink-0 h-auto grayscale" />,
}, },
video: { video: {
title: "Video not Found", title: "Video not Found",
desc: "Video expired or deleted", desc: "Video expired or deleted",
icon: <IconVideo className="w-9 shrink-0 h-auto grayscale" /> icon: <IconVideo className="w-9 shrink-0 h-auto grayscale" />,
} },
}; };
const ExpiredMessage = ({ type = "file", url = "" }: Props) => { const ExpiredMessage = ({ type = "file", url = "" }: Props) => {
const { pathname } = useLocation();
console.log("pppp", pathname);
const [context = "channel", id = 0] = pathname.split("/").slice(-2);
const removeLocalMessage = useRemoveLocalMessage({
context: context as ChatContext,
id: +id,
});
const msgRef = useRef<HTMLDivElement | null>(null);
const { setExpired } = useExpiredResMap(); const { setExpired } = useExpiredResMap();
const { title, desc, icon } = InfoMap[type]; const { title, desc, icon } = InfoMap[type];
useEffect(() => { useEffect(() => {
@@ -42,9 +53,19 @@ const ExpiredMessage = ({ type = "file", url = "" }: Props) => {
setExpired(url); setExpired(url);
} }
}, [url]); }, [url]);
useEffect(() => {
const msgEle = msgRef.current;
if (!msgEle) return;
const mid = msgEle.closest("[data-msg-mid]")?.getAttribute("data-msg-mid") ?? "";
if (mid.length == 13) {
// 本地消息
removeLocalMessage(+mid);
}
}, [removeLocalMessage]);
return ( return (
<div <div
ref={msgRef}
className={clsx( className={clsx(
`bg-stone-100 dark:bg-stone-900 border box-border md:w-96 rounded-md border-gray-300 dark:border-gray-500` `bg-stone-100 dark:bg-stone-900 border box-border md:w-96 rounded-md border-gray-300 dark:border-gray-500`
)} )}