From 02d6ee41024018081895603f93fb0975162b8ad0 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sun, 23 Nov 2025 00:14:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20UserProfileDialog=20?= =?UTF-8?q?=E5=B9=B6=E5=85=A5=20ChatInfoDialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/ui/App.tsx | 25 +++++----- client/ui/AppMobile.tsx | 28 ++++++------ client/ui/dialog/ChatInfoDialog.tsx | 46 ++++++++----------- client/ui/dialog/UserProfileDialog.tsx | 63 -------------------------- 4 files changed, 43 insertions(+), 119 deletions(-) delete mode 100644 client/ui/dialog/UserProfileDialog.tsx diff --git a/client/ui/App.tsx b/client/ui/App.tsx index 2d2f3c8..ce5c2fc 100644 --- a/client/ui/App.tsx +++ b/client/ui/App.tsx @@ -3,7 +3,6 @@ import data from "../Data.ts" import ChatFragment from "./chat/ChatFragment.tsx" import useEventListener from './useEventListener.ts' import User from "../api/client_data/User.ts" -import RecentChat from "../api/client_data/RecentChat.ts" import Avatar from "./Avatar.tsx" import * as React from 'react' @@ -22,7 +21,6 @@ import ChatInfoDialog from "./dialog/ChatInfoDialog.tsx" import Chat from "../api/client_data/Chat.ts" import AddContactDialog from './dialog/AddContactDialog.tsx' import CreateGroupDialog from './dialog/CreateGroupDialog.tsx' -import UserProfileDialog from "./dialog/UserProfileDialog.tsx" import DataCaches from "../api/DataCaches.ts" import getUrlForFileByHash from "../getUrlForFileByHash.ts" import Message from "../api/client_data/Message.ts" @@ -62,9 +60,6 @@ export default function App() { myProfileDialogRef.current!.open = true }) - const userProfileDialogRef = React.useRef(null) - const [userInfo, setUserInfo] = React.useState(null as unknown as User) - const addContactDialogRef = React.useRef(null) const createGroupDialogRef = React.useRef(null) @@ -112,13 +107,23 @@ export default function App() { } async function openUserInfoDialog(user: User | string) { - if (typeof user == 'object') { + const re = await Client.invoke("Chat.getIdForPrivate", { + token: data.access_token, + target: typeof user == 'object' ? user.id : user, + }) + if (re.code != 200) { + checkApiSuccessOrSncakbar(re, '获取对话失败') + return + } + + openChatInfoDialog(re.data as Chat) + /* if (typeof user == 'object') { setUserInfo(user) } else { setUserInfo(await DataCaches.getUserProfile(user)) } - userProfileDialogRef.current!.open = true + userProfileDialogRef.current!.open = true */ } // deno-lint-ignore no-window window.openUserInfoDialog = openUserInfoDialog @@ -181,18 +186,12 @@ export default function App() { - diff --git a/client/ui/AppMobile.tsx b/client/ui/AppMobile.tsx index eebb73d..deadf82 100644 --- a/client/ui/AppMobile.tsx +++ b/client/ui/AppMobile.tsx @@ -3,7 +3,6 @@ import data from "../Data.ts" import ChatFragment from "./chat/ChatFragment.tsx" import useEventListener from './useEventListener.ts' import User from "../api/client_data/User.ts" -import RecentChat from "../api/client_data/RecentChat.ts" import Avatar from "./Avatar.tsx" import * as React from 'react' @@ -21,8 +20,6 @@ import ChatInfoDialog from "./dialog/ChatInfoDialog.tsx" import Chat from "../api/client_data/Chat.ts" import AddContactDialog from './dialog/AddContactDialog.tsx' import CreateGroupDialog from './dialog/CreateGroupDialog.tsx' -import UserProfileDialog from "./dialog/UserProfileDialog.tsx" -import DataCaches from "../api/DataCaches.ts" import getUrlForFileByHash from "../getUrlForFileByHash.ts" declare global { @@ -65,9 +62,6 @@ export default function AppMobile() { const chatInfoDialogRef = React.useRef(null) const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat) - const userProfileDialogRef = React.useRef(null) - const [userInfo, setUserInfo] = React.useState(null as unknown as User) - const [myUserProfileCache, setMyUserProfileCache] = React.useState(null as unknown as User) const [isShowChatFragment, setIsShowChatFragment] = React.useState(false) @@ -112,13 +106,23 @@ export default function AppMobile() { } async function openUserInfoDialog(user: User | string) { - if (typeof user == 'object') { + const re = await Client.invoke("Chat.getIdForPrivate", { + token: data.access_token, + target: typeof user == 'object' ? user.id : user, + }) + if (re.code != 200) { + checkApiSuccessOrSncakbar(re, '获取对话失败') + return + } + + openChatInfoDialog(re.data as Chat) + /* if (typeof user == 'object') { setUserInfo(user) } else { setUserInfo(await DataCaches.getUserProfile(user)) } - userProfileDialogRef.current!.open = true + userProfileDialogRef.current!.open = true */ } // deno-lint-ignore no-window window.openUserInfoDialog = openUserInfoDialog @@ -167,7 +171,6 @@ export default function AppMobile() { { setCurrentChatId(id) @@ -178,15 +181,10 @@ export default function AppMobile() { - - + diff --git a/client/ui/dialog/ChatInfoDialog.tsx b/client/ui/dialog/ChatInfoDialog.tsx index 9529733..1ab4046 100644 --- a/client/ui/dialog/ChatInfoDialog.tsx +++ b/client/ui/dialog/ChatInfoDialog.tsx @@ -12,29 +12,32 @@ import openImageViewer from "../openImageViewer.ts" import EventBus from "../../EventBus.ts" interface Args extends React.HTMLAttributes { - chat: Chat + chat?: Chat openChatFragment: (id: string) => void chatInfoDialogRef: React.MutableRefObject - openUserInfoDialog: (user: User | string) => void sharedFavouriteChats: Chat[] } -export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment, openUserInfoDialog, sharedFavouriteChats }: Args) { - const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat) +export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment, sharedFavouriteChats }: Args) { const [favourited, setIsFavourited] = React.useState(false) - useAsyncEffect(async () => { - if (chat == null) return - const re = await Client.invoke("Chat.getInfo", { - token: data.access_token, - target: chat.id, - }) - if (re.code != 200) - return checkApiSuccessOrSncakbar(re, '获取对话信息失败') + React.useEffect(() => { + setIsFavourited(sharedFavouriteChats.map((v) => v.id).indexOf(chat?.id || '') != -1) + }) - const info = re.data as Chat - setIsFavourited(sharedFavouriteChats.map((v) => v.id).indexOf(info.id) != -1) + let userId: string | null = null + useAsyncEffect(async () => { + if (chat?.type == 'private') { + const re = await Client.invoke("Chat.getAnotherUserIdFromPrivate", { + token: data.access_token, + target: chat.id, + }) + if (re.code != 200) + return checkApiSuccessOrSncakbar(re, '获取用户失败') + userId = re.data!.user_id as string + } }, [chat, sharedFavouriteChats]) + const avatarUrl = getUrlForFileByHash(chat?.avatar_file_hash as string) return ( @@ -57,19 +60,6 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme }}> - { - chat?.type == 'private' && - { - const re = await Client.invoke("Chat.getAnotherUserIdFromPrivate", { - token: data.access_token, - target: chat.id, - }) - if (re.code != 200) - return checkApiSuccessOrSncakbar(re, '获取用户失败') - - openUserInfoDialog(re.data!.user_id as string) - }}>用户详情 - } dialog({ headline: favourited ? "取消收藏对话" : "收藏对话", description: favourited ? "确定从收藏对话列表中移除吗? (虽然这不会导致聊天记录丢失)" : "确定要添加到收藏对话列表吗?", @@ -83,7 +73,7 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme { text: "确定", onClick: () => { - ;(async () => { + ; (async () => { const re = await Client.invoke(favourited ? "User.removeContacts" : "User.addContacts", { token: data.access_token, targets: [ diff --git a/client/ui/dialog/UserProfileDialog.tsx b/client/ui/dialog/UserProfileDialog.tsx deleted file mode 100644 index c33f09d..0000000 --- a/client/ui/dialog/UserProfileDialog.tsx +++ /dev/null @@ -1,63 +0,0 @@ -import * as React from 'react' -import { Dialog } from "mdui" -import { checkApiSuccessOrSncakbar } from "../snackbar.ts" -import Client from "../../api/Client.ts" - -import data from "../../Data.ts" -import Avatar from "../Avatar.tsx" -import User from "../../api/client_data/User.ts" -import getUrlForFileByHash from "../../getUrlForFileByHash.ts" -import openImageViewer from "../openImageViewer.ts" -import Chat from "../../api/client_data/Chat.ts" - -interface Refs { - userProfileDialogRef: React.MutableRefObject - chatInfoDialogRef: React.MutableRefObject - openChatFragment: (id: string) => void - user: User -} - -export default function UserProfileDialog({ - userProfileDialogRef, - chatInfoDialogRef, - openChatFragment, - user -}: Refs) { - const avatarUrl = getUrlForFileByHash(user?.avatar_file_hash) - return ( - -
- avatarUrl && openImageViewer(avatarUrl)} /> - {user?.nickname} -
- - - - {/* 设置备注 */} - { - const re = await Client.invoke("Chat.getIdForPrivate", { - token: data.access_token, - target: user.id, - }) - if (re.code != 200) - return checkApiSuccessOrSncakbar(re, '获取对话失败') - - openChatFragment(re.data!.chat_id as string) - userProfileDialogRef.current!.open = false - chatInfoDialogRef.current!.open = false - }}>对话 - -
- ) -} \ No newline at end of file