refactor: avatar_file_hash instead of avatar
This commit is contained in:
@@ -4,7 +4,7 @@ export default class Chat {
|
|||||||
declare type: ChatType
|
declare type: ChatType
|
||||||
declare id: string
|
declare id: string
|
||||||
declare title: string
|
declare title: string
|
||||||
declare avatar?: string
|
declare avatar_file_hash?: string
|
||||||
declare settings?: { [key: string]: unknown }
|
declare settings?: { [key: string]: unknown }
|
||||||
|
|
||||||
declare is_member: boolean
|
declare is_member: boolean
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ export default class User {
|
|||||||
declare id: string
|
declare id: string
|
||||||
declare username?: string
|
declare username?: string
|
||||||
declare nickname: string
|
declare nickname: string
|
||||||
declare avatar?: string
|
declare avatar_file_hash?: string
|
||||||
}
|
}
|
||||||
|
|||||||
3
client/getUrlForFileByHash.ts
Normal file
3
client/getUrlForFileByHash.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export default function getUrlForFileByHash(file_hash?: string, defaultUrl?: string) {
|
||||||
|
return file_hash ? "uploaded_files/" + file_hash: defaultUrl
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ import AddContactDialog from './dialog/AddContactDialog.tsx'
|
|||||||
import CreateGroupDialog from './dialog/CreateGroupDialog.tsx'
|
import CreateGroupDialog from './dialog/CreateGroupDialog.tsx'
|
||||||
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
||||||
import DataCaches from "../api/DataCaches.ts"
|
import DataCaches from "../api/DataCaches.ts"
|
||||||
|
import getUrlForFileByHash from "../getUrlForFileByHash.ts"
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace React {
|
namespace React {
|
||||||
@@ -160,7 +161,7 @@ export default function App() {
|
|||||||
|
|
||||||
<mdui-navigation-rail contained value="Recents" ref={navigationRailRef}>
|
<mdui-navigation-rail contained value="Recents" ref={navigationRailRef}>
|
||||||
<mdui-button-icon slot="top">
|
<mdui-button-icon slot="top">
|
||||||
<Avatar src={myUserProfileCache?.avatar} text={myUserProfileCache?.nickname} avatarRef={openMyProfileDialogButtonRef} />
|
<Avatar src={getUrlForFileByHash(myUserProfileCache?.avatar_file_hash)} text={myUserProfileCache?.nickname} avatarRef={openMyProfileDialogButtonRef} />
|
||||||
</mdui-button-icon>
|
</mdui-button-icon>
|
||||||
|
|
||||||
<mdui-navigation-rail-item icon="watch_later--outlined" active-icon="watch_later--filled" value="Recents"></mdui-navigation-rail-item>
|
<mdui-navigation-rail-item icon="watch_later--outlined" active-icon="watch_later--filled" value="Recents"></mdui-navigation-rail-item>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import AddContactDialog from './dialog/AddContactDialog.tsx'
|
|||||||
import CreateGroupDialog from './dialog/CreateGroupDialog.tsx'
|
import CreateGroupDialog from './dialog/CreateGroupDialog.tsx'
|
||||||
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
import UserProfileDialog from "./dialog/UserProfileDialog.tsx"
|
||||||
import DataCaches from "../api/DataCaches.ts"
|
import DataCaches from "../api/DataCaches.ts"
|
||||||
|
import getUrlForFileByHash from "../getUrlForFileByHash.ts"
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
namespace React {
|
namespace React {
|
||||||
@@ -200,7 +201,7 @@ export default function AppMobile() {
|
|||||||
}}></div>
|
}}></div>
|
||||||
<mdui-button-icon icon="settings"></mdui-button-icon>
|
<mdui-button-icon icon="settings"></mdui-button-icon>
|
||||||
<mdui-button-icon>
|
<mdui-button-icon>
|
||||||
<Avatar src={myUserProfileCache?.avatar} text={myUserProfileCache?.nickname} avatarRef={openMyProfileDialogButtonRef} />
|
<Avatar src={getUrlForFileByHash(myUserProfileCache?.avatar_file_hash)} text={myUserProfileCache?.nickname} avatarRef={openMyProfileDialogButtonRef} />
|
||||||
</mdui-button-icon>
|
</mdui-button-icon>
|
||||||
</mdui-top-app-bar>
|
</mdui-top-app-bar>
|
||||||
{
|
{
|
||||||
@@ -226,7 +227,7 @@ export default function AppMobile() {
|
|||||||
<ContactsList
|
<ContactsList
|
||||||
openChatInfoDialog={openChatInfoDialog}
|
openChatInfoDialog={openChatInfoDialog}
|
||||||
addContactDialogRef={addContactDialogRef as any}
|
addContactDialogRef={addContactDialogRef as any}
|
||||||
createGroupDialogRef={createGroupDialogRef}
|
createGroupDialogRef={createGroupDialogRef as any}
|
||||||
display={navigationItemSelected == "Contacts"} />
|
display={navigationItemSelected == "Contacts"} />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import React from "react"
|
|||||||
import isMobileUI from "../isMobileUI.ts"
|
import isMobileUI from "../isMobileUI.ts"
|
||||||
import ReactJson from 'react-json-view'
|
import ReactJson from 'react-json-view'
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
userId: string
|
userId: string
|
||||||
@@ -29,7 +30,7 @@ export default function Message({ userId, rawData, renderHTML, message, openUser
|
|||||||
useAsyncEffect(async () => {
|
useAsyncEffect(async () => {
|
||||||
const user = await DataCaches.getUserProfile(userId)
|
const user = await DataCaches.getUserProfile(userId)
|
||||||
setNickName(user.nickname)
|
setNickName(user.nickname)
|
||||||
setAvatarUrl(user?.avatar)
|
setAvatarUrl(getUrlForFileByHash(user?.avatar_file_hash))
|
||||||
}, [userId])
|
}, [userId])
|
||||||
|
|
||||||
const dropDownRef = React.useRef<Dropdown>(null)
|
const dropDownRef = React.useRef<Dropdown>(null)
|
||||||
@@ -40,7 +41,7 @@ export default function Message({ userId, rawData, renderHTML, message, openUser
|
|||||||
useEventListener(dropDownRef, 'closed', (e) => {
|
useEventListener(dropDownRef, 'closed', (e) => {
|
||||||
setDropDownOpen(false)
|
setDropDownOpen(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
const [isDropDownOpen, setDropDownOpen] = React.useState(false)
|
const [isDropDownOpen, setDropDownOpen] = React.useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -114,8 +115,11 @@ export default function Message({ userId, rawData, renderHTML, message, openUser
|
|||||||
padding: "15px",
|
padding: "15px",
|
||||||
alignSelf: isAtRight ? "flex-end" : "flex-start",
|
alignSelf: isAtRight ? "flex-end" : "flex-start",
|
||||||
}}>
|
}}>
|
||||||
<mdui-dialog close-on-overlay-click close-on-esc ref={messageJsonDialogRef}>
|
<mdui-dialog close-on-overlay-click close-on-esc fullscreen ref={messageJsonDialogRef}>
|
||||||
<ReactJson src={message} />
|
{
|
||||||
|
// @ts-ignore 这是可以正常工作的
|
||||||
|
<ReactJson src={message} />
|
||||||
|
}
|
||||||
</mdui-dialog>
|
</mdui-dialog>
|
||||||
<mdui-dropdown trigger="manual" ref={dropDownRef} open={isDropDownOpen}>
|
<mdui-dropdown trigger="manual" ref={dropDownRef} open={isDropDownOpen}>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { Dialog } from "mdui"
|
|||||||
import Avatar from "../Avatar.tsx"
|
import Avatar from "../Avatar.tsx"
|
||||||
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
|
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
chat: Chat
|
chat: Chat
|
||||||
@@ -36,7 +37,7 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
}}>
|
}}>
|
||||||
<Avatar src={chat?.avatar as string} text={chat?.nickname as string} style={{
|
<Avatar src={getUrlForFileByHash(chat?.avatar_file_hash as string)} text={chat?.nickname as string} style={{
|
||||||
width: '50px',
|
width: '50px',
|
||||||
height: '50px',
|
height: '50px',
|
||||||
}} />
|
}} />
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import * as CryptoJS from 'crypto-js'
|
|||||||
import data from "../../Data.ts"
|
import data from "../../Data.ts"
|
||||||
import Avatar from "../Avatar.tsx"
|
import Avatar from "../Avatar.tsx"
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
|
|
||||||
interface Refs {
|
interface Refs {
|
||||||
myProfileDialogRef: React.MutableRefObject<Dialog>
|
myProfileDialogRef: React.MutableRefObject<Dialog>
|
||||||
@@ -50,7 +51,7 @@ export default function MyProfileDialog({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
}}>
|
}}>
|
||||||
<Avatar src={user?.avatar} text={user?.nickname} style={{
|
<Avatar src={getUrlForFileByHash(user?.avatar_file_hash)} text={user?.nickname} style={{
|
||||||
width: '50px',
|
width: '50px',
|
||||||
height: '50px',
|
height: '50px',
|
||||||
}} />
|
}} />
|
||||||
@@ -111,7 +112,7 @@ export default function MyProfileDialog({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
}}>
|
}}>
|
||||||
<Avatar src={user?.avatar} text={user?.nickname} avatarRef={editAvatarButtonRef} style={{
|
<Avatar src={getUrlForFileByHash(user?.avatar_file_hash)} text={user?.nickname} avatarRef={editAvatarButtonRef} style={{
|
||||||
width: '50px',
|
width: '50px',
|
||||||
height: '50px',
|
height: '50px',
|
||||||
}} />
|
}} />
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { Button, Dialog, TextField, dialog } from "mdui"
|
import { Dialog } from "mdui"
|
||||||
import useEventListener from "../useEventListener.ts"
|
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
|
||||||
import { checkApiSuccessOrSncakbar, snackbar } from "../snackbar.ts"
|
|
||||||
import Client from "../../api/Client.ts"
|
import Client from "../../api/Client.ts"
|
||||||
|
|
||||||
import * as CryptoJS from 'crypto-js'
|
|
||||||
import data from "../../Data.ts"
|
import data from "../../Data.ts"
|
||||||
import Avatar from "../Avatar.tsx"
|
import Avatar from "../Avatar.tsx"
|
||||||
import User from "../../api/client_data/User.ts"
|
import User from "../../api/client_data/User.ts"
|
||||||
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
|
|
||||||
interface Refs {
|
interface Refs {
|
||||||
userProfileDialogRef: React.MutableRefObject<Dialog>
|
userProfileDialogRef: React.MutableRefObject<Dialog>
|
||||||
@@ -28,7 +27,7 @@ export default function UserProfileDialog({
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
}}>
|
}}>
|
||||||
<Avatar src={user?.avatar} text={user?.nickname} style={{
|
<Avatar src={getUrlForFileByHash(user?.avatar_file_hash)} text={user?.nickname} style={{
|
||||||
width: '50px',
|
width: '50px',
|
||||||
height: '50px',
|
height: '50px',
|
||||||
}} />
|
}} />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Chat from "../../api/client_data/Chat.ts"
|
import Chat from "../../api/client_data/Chat.ts"
|
||||||
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
import Avatar from "../Avatar.tsx"
|
import Avatar from "../Avatar.tsx"
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ interface Args extends React.HTMLAttributes<HTMLElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ContactsListItem({ contact, ...prop }: Args) {
|
export default function ContactsListItem({ contact, ...prop }: Args) {
|
||||||
const { id, title, avatar } = contact
|
const { id, title, avatar_file_hash } = contact
|
||||||
const ref = React.useRef<HTMLElement>(null)
|
const ref = React.useRef<HTMLElement>(null)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -20,7 +21,7 @@ export default function ContactsListItem({ contact, ...prop }: Args) {
|
|||||||
<span style={{
|
<span style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
}}>{title}</span>
|
}}>{title}</span>
|
||||||
<Avatar src={avatar as string} text={title} slot="icon" />
|
<Avatar src={getUrlForFileByHash(avatar_file_hash as string)} text={title} slot="icon" />
|
||||||
</mdui-list-item>
|
</mdui-list-item>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { $ } from "mdui/jq"
|
|||||||
import RecentChat from "../../api/client_data/RecentChat.ts"
|
import RecentChat from "../../api/client_data/RecentChat.ts"
|
||||||
import Avatar from "../Avatar.tsx"
|
import Avatar from "../Avatar.tsx"
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import getUrlForFileByHash from "../../getUrlForFileByHash.ts"
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
recentChat: RecentChat
|
recentChat: RecentChat
|
||||||
@@ -10,7 +11,7 @@ interface Args extends React.HTMLAttributes<HTMLElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function RecentsListItem({ recentChat, openChatFragment, active }: Args) {
|
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<HTMLElement>(null)
|
const itemRef = React.useRef<HTMLElement>(null)
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -22,7 +23,7 @@ export default function RecentsListItem({ recentChat, openChatFragment, active }
|
|||||||
marginBottom: '3px',
|
marginBottom: '3px',
|
||||||
}} onClick={() => openChatFragment(id)} active={active} ref={itemRef}>
|
}} onClick={() => openChatFragment(id)} active={active} ref={itemRef}>
|
||||||
{title}
|
{title}
|
||||||
<Avatar src={avatar} text={title} slot="icon" />
|
<Avatar src={getUrlForFileByHash(avatar_file_hash as string)} text={title} slot="icon" />
|
||||||
<span slot="description"
|
<span slot="description"
|
||||||
style={{
|
style={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ export default class ChatApi extends BaseApi {
|
|||||||
user_id: user?.bean.id,
|
user_id: user?.bean.id,
|
||||||
reason: v.reason,
|
reason: v.reason,
|
||||||
title: user!.getNickName(),
|
title: user!.getNickName(),
|
||||||
avatar: user!.getAvatarFileHash() ? "uploaded_files/" + user!.getAvatarFileHash() : null,
|
avatar_file_hash: user!.getAvatarFileHash() ? user!.getAvatarFileHash() : null,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
@@ -421,7 +421,7 @@ export default class ChatApi extends BaseApi {
|
|||||||
id: args.target as string,
|
id: args.target as string,
|
||||||
type: chat.bean.type,
|
type: chat.bean.type,
|
||||||
title: chat.getTitle(mine),
|
title: chat.getTitle(mine),
|
||||||
avatar: chat.getAvatarFileHash(mine) ? "uploaded_files/" + chat.getAvatarFileHash(mine) : undefined,
|
avatar_file_hash: chat.getAvatarFileHash(mine) ? chat.getAvatarFileHash(mine) : undefined,
|
||||||
settings: JSON.parse(chat.bean.settings),
|
settings: JSON.parse(chat.bean.settings),
|
||||||
is_member: true,
|
is_member: true,
|
||||||
is_admin: true,
|
is_admin: true,
|
||||||
@@ -436,7 +436,7 @@ export default class ChatApi extends BaseApi {
|
|||||||
id: args.target as string,
|
id: args.target as string,
|
||||||
type: chat.bean.type,
|
type: chat.bean.type,
|
||||||
title: chat.getTitle(),
|
title: chat.getTitle(),
|
||||||
avatar: chat.getAvatarFileHash() ? "uploaded_files/" + chat.getAvatarFileHash() : undefined,
|
avatar_file_hash: chat.getAvatarFileHash() ? chat.getAvatarFileHash() : undefined,
|
||||||
settings: JSON.parse(chat.bean.settings),
|
settings: JSON.parse(chat.bean.settings),
|
||||||
is_member: UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id),
|
is_member: UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id),
|
||||||
is_admin: chat.checkUserIsAdmin(token.author),
|
is_admin: chat.checkUserIsAdmin(token.author),
|
||||||
|
|||||||
@@ -231,7 +231,7 @@ export default class UserApi extends BaseApi {
|
|||||||
data: {
|
data: {
|
||||||
username: user!.getUserName(),
|
username: user!.getUserName(),
|
||||||
nickname: user!.getNickName(),
|
nickname: user!.getNickName(),
|
||||||
avatar: user!.getAvatarFileHash() ? "uploaded_files/" + user!.getAvatarFileHash() : null,
|
avatar_file_hash: user!.getAvatarFileHash() ? user!.getAvatarFileHash() : null,
|
||||||
id: token.author,
|
id: token.author,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,7 +258,7 @@ export default class UserApi extends BaseApi {
|
|||||||
content,
|
content,
|
||||||
id: chatId,
|
id: chatId,
|
||||||
title: chat?.getTitle(user) || "未知",
|
title: chat?.getTitle(user) || "未知",
|
||||||
avatar: chat?.getAvatarFileHash(user) ? "uploaded_files/" + chat?.getAvatarFileHash(user) : undefined
|
avatar_file_hash: chat?.getAvatarFileHash(user) ? chat?.getAvatarFileHash(user) : undefined
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ export default class UserApi extends BaseApi {
|
|||||||
id,
|
id,
|
||||||
type: chat?.bean.type,
|
type: chat?.bean.type,
|
||||||
title: chat?.getTitle(user) || "未知",
|
title: chat?.getTitle(user) || "未知",
|
||||||
avatar: chat?.getAvatarFileHash(user) ? "uploaded_files/" + chat?.getAvatarFileHash(user) : undefined
|
avatar_file_hash: chat?.getAvatarFileHash(user) ? chat?.getAvatarFileHash(user) : undefined
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -366,7 +366,7 @@ export default class UserApi extends BaseApi {
|
|||||||
data: {
|
data: {
|
||||||
username: user!.getUserName(),
|
username: user!.getUserName(),
|
||||||
nickname: user!.getNickName(),
|
nickname: user!.getNickName(),
|
||||||
avatar: user!.getAvatarFileHash() ? "uploaded_files/" + user!.getAvatarFileHash() : null,
|
avatar_file_hash: user!.getAvatarFileHash() ? user!.getAvatarFileHash() : null,
|
||||||
id: user.bean.id,
|
id: user.bean.id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user