diff --git a/client/api/client_data/Chat.ts b/client/api/client_data/Chat.ts index 50319b8..2607314 100644 --- a/client/api/client_data/Chat.ts +++ b/client/api/client_data/Chat.ts @@ -4,7 +4,7 @@ export default class Chat { declare type: ChatType declare id: string declare title: string - declare avatar?: string + declare avatar_file_hash?: string declare settings?: { [key: string]: unknown } declare is_member: boolean diff --git a/client/api/client_data/User.ts b/client/api/client_data/User.ts index 2b279c2..4a41263 100644 --- a/client/api/client_data/User.ts +++ b/client/api/client_data/User.ts @@ -2,5 +2,5 @@ export default class User { declare id: string declare username?: string declare nickname: string - declare avatar?: string + declare avatar_file_hash?: string } diff --git a/client/getUrlForFileByHash.ts b/client/getUrlForFileByHash.ts new file mode 100644 index 0000000..4a1db3d --- /dev/null +++ b/client/getUrlForFileByHash.ts @@ -0,0 +1,3 @@ +export default function getUrlForFileByHash(file_hash?: string, defaultUrl?: string) { + return file_hash ? "uploaded_files/" + file_hash: defaultUrl +} diff --git a/client/ui/App.tsx b/client/ui/App.tsx index 8ed75b5..c8e2694 100644 --- a/client/ui/App.tsx +++ b/client/ui/App.tsx @@ -24,6 +24,7 @@ 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 { namespace React { @@ -160,7 +161,7 @@ export default function App() { - + diff --git a/client/ui/AppMobile.tsx b/client/ui/AppMobile.tsx index 4973bf7..abc70bf 100644 --- a/client/ui/AppMobile.tsx +++ b/client/ui/AppMobile.tsx @@ -23,6 +23,7 @@ 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 { namespace React { @@ -200,7 +201,7 @@ export default function AppMobile() { }}> - + { @@ -226,7 +227,7 @@ export default function AppMobile() { } diff --git a/client/ui/chat/Message.tsx b/client/ui/chat/Message.tsx index b53dd5e..f7d29b9 100644 --- a/client/ui/chat/Message.tsx +++ b/client/ui/chat/Message.tsx @@ -11,6 +11,7 @@ import React from "react" import isMobileUI from "../isMobileUI.ts" import ReactJson from 'react-json-view' import User from "../../api/client_data/User.ts" +import getUrlForFileByHash from "../../getUrlForFileByHash.ts" interface Args extends React.HTMLAttributes { userId: string @@ -29,7 +30,7 @@ export default function Message({ userId, rawData, renderHTML, message, openUser useAsyncEffect(async () => { const user = await DataCaches.getUserProfile(userId) setNickName(user.nickname) - setAvatarUrl(user?.avatar) + setAvatarUrl(getUrlForFileByHash(user?.avatar_file_hash)) }, [userId]) const dropDownRef = React.useRef(null) @@ -40,7 +41,7 @@ export default function Message({ userId, rawData, renderHTML, message, openUser useEventListener(dropDownRef, 'closed', (e) => { setDropDownOpen(false) }) - + const [isDropDownOpen, setDropDownOpen] = React.useState(false) return ( @@ -114,8 +115,11 @@ export default function Message({ userId, rawData, renderHTML, message, openUser padding: "15px", alignSelf: isAtRight ? "flex-end" : "flex-start", }}> - - + + { + // @ts-ignore 这是可以正常工作的 + + } { chat: Chat @@ -36,7 +37,7 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme display: 'flex', alignItems: 'center', }}> - diff --git a/client/ui/dialog/MyProfileDialog.tsx b/client/ui/dialog/MyProfileDialog.tsx index d9d29c7..b89862f 100644 --- a/client/ui/dialog/MyProfileDialog.tsx +++ b/client/ui/dialog/MyProfileDialog.tsx @@ -8,6 +8,7 @@ import * as CryptoJS from 'crypto-js' import data from "../../Data.ts" import Avatar from "../Avatar.tsx" import User from "../../api/client_data/User.ts" +import getUrlForFileByHash from "../../getUrlForFileByHash.ts" interface Refs { myProfileDialogRef: React.MutableRefObject @@ -50,7 +51,7 @@ export default function MyProfileDialog({ display: 'flex', alignItems: 'center', }}> - @@ -111,7 +112,7 @@ export default function MyProfileDialog({ display: 'flex', alignItems: 'center', }}> - diff --git a/client/ui/dialog/UserProfileDialog.tsx b/client/ui/dialog/UserProfileDialog.tsx index 0fc64b0..ad0ae4a 100644 --- a/client/ui/dialog/UserProfileDialog.tsx +++ b/client/ui/dialog/UserProfileDialog.tsx @@ -1,13 +1,12 @@ import * as React from 'react' -import { Button, Dialog, TextField, dialog } from "mdui" -import useEventListener from "../useEventListener.ts" -import { checkApiSuccessOrSncakbar, snackbar } from "../snackbar.ts" +import { Dialog } from "mdui" +import { checkApiSuccessOrSncakbar } from "../snackbar.ts" import Client from "../../api/Client.ts" -import * as CryptoJS from 'crypto-js' import data from "../../Data.ts" import Avatar from "../Avatar.tsx" import User from "../../api/client_data/User.ts" +import getUrlForFileByHash from "../../getUrlForFileByHash.ts" interface Refs { userProfileDialogRef: React.MutableRefObject @@ -28,7 +27,7 @@ export default function UserProfileDialog({ display: 'flex', alignItems: 'center', }}> - diff --git a/client/ui/main/ContactsListItem.tsx b/client/ui/main/ContactsListItem.tsx index 1bed435..a03e2da 100644 --- a/client/ui/main/ContactsListItem.tsx +++ b/client/ui/main/ContactsListItem.tsx @@ -1,4 +1,5 @@ import Chat from "../../api/client_data/Chat.ts" +import getUrlForFileByHash from "../../getUrlForFileByHash.ts" import Avatar from "../Avatar.tsx" import React from 'react' @@ -8,7 +9,7 @@ interface Args extends React.HTMLAttributes { } export default function ContactsListItem({ contact, ...prop }: Args) { - const { id, title, avatar } = contact + const { id, title, avatar_file_hash } = contact const ref = React.useRef(null) return ( @@ -20,7 +21,7 @@ export default function ContactsListItem({ contact, ...prop }: Args) { {title} - + ) } diff --git a/client/ui/main/RecentsListItem.tsx b/client/ui/main/RecentsListItem.tsx index f4cf7ae..391d540 100644 --- a/client/ui/main/RecentsListItem.tsx +++ b/client/ui/main/RecentsListItem.tsx @@ -2,6 +2,7 @@ import { $ } from "mdui/jq" import RecentChat from "../../api/client_data/RecentChat.ts" import Avatar from "../Avatar.tsx" import React from 'react' +import getUrlForFileByHash from "../../getUrlForFileByHash.ts" interface Args extends React.HTMLAttributes { recentChat: RecentChat @@ -10,7 +11,7 @@ interface Args extends React.HTMLAttributes { } export default function RecentsListItem({ recentChat, openChatFragment, active }: Args) { - const { id, title, avatar, content } = recentChat + const { id, title, avatar_file_hash, content } = recentChat const itemRef = React.useRef(null) React.useEffect(() => { @@ -22,7 +23,7 @@ export default function RecentsListItem({ recentChat, openChatFragment, active } marginBottom: '3px', }} onClick={() => openChatFragment(id)} active={active} ref={itemRef}> {title} - +