移除 UserProfileDialog 并入 ChatInfoDialog
This commit is contained in:
@@ -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<Dialog>(null)
|
||||
const [userInfo, setUserInfo] = React.useState(null as unknown as User)
|
||||
|
||||
const addContactDialogRef = React.useRef<Dialog>(null)
|
||||
const createGroupDialogRef = React.useRef<Dialog>(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() {
|
||||
<ChatInfoDialog
|
||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||
openChatFragment={openChatFragment}
|
||||
openUserInfoDialog={openUserInfoDialog}
|
||||
sharedFavouriteChats={sharedFavouriteChats}
|
||||
chat={chatInfo} />
|
||||
|
||||
<MyProfileDialog
|
||||
myProfileDialogRef={myProfileDialogRef as any}
|
||||
user={myUserProfileCache} />
|
||||
<UserProfileDialog
|
||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||
userProfileDialogRef={userProfileDialogRef as any}
|
||||
openChatFragment={openChatFragment}
|
||||
user={userInfo} />
|
||||
|
||||
<AddContactDialog
|
||||
addContactDialogRef={addContactDialogRef} />
|
||||
|
||||
@@ -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<Dialog>(null)
|
||||
const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat)
|
||||
|
||||
const userProfileDialogRef = React.useRef<Dialog>(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() {
|
||||
|
||||
<ChatInfoDialog
|
||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||
openUserInfoDialog={openUserInfoDialog}
|
||||
sharedFavouriteChats={sharedFavouriteChats}
|
||||
openChatFragment={(id) => {
|
||||
setCurrentChatId(id)
|
||||
@@ -178,15 +181,10 @@ export default function AppMobile() {
|
||||
<MyProfileDialog
|
||||
myProfileDialogRef={myProfileDialogRef as any}
|
||||
user={myUserProfileCache} />
|
||||
<UserProfileDialog
|
||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||
userProfileDialogRef={userProfileDialogRef as any}
|
||||
openChatFragment={openChatFragment}
|
||||
user={userInfo} />
|
||||
|
||||
<AddContactDialog
|
||||
addContactDialogRef={addContactDialogRef} />
|
||||
|
||||
|
||||
<CreateGroupDialog
|
||||
createGroupDialogRef={createGroupDialogRef} />
|
||||
|
||||
|
||||
@@ -12,29 +12,32 @@ import openImageViewer from "../openImageViewer.ts"
|
||||
import EventBus from "../../EventBus.ts"
|
||||
|
||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||
chat: Chat
|
||||
chat?: Chat
|
||||
openChatFragment: (id: string) => void
|
||||
chatInfoDialogRef: React.MutableRefObject<Dialog>
|
||||
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
|
||||
}}></mdui-divider>
|
||||
|
||||
<mdui-list>
|
||||
{
|
||||
chat?.type == 'private' &&
|
||||
<mdui-list-item icon="person" rounded onClick={async () => {
|
||||
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)
|
||||
}}>用户详情</mdui-list-item>
|
||||
}
|
||||
<mdui-list-item icon={favourited ? "favorite_border" : "favorite"} rounded onClick={() => 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: [
|
||||
|
||||
@@ -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<Dialog>
|
||||
chatInfoDialogRef: React.MutableRefObject<Dialog>
|
||||
openChatFragment: (id: string) => void
|
||||
user: User
|
||||
}
|
||||
|
||||
export default function UserProfileDialog({
|
||||
userProfileDialogRef,
|
||||
chatInfoDialogRef,
|
||||
openChatFragment,
|
||||
user
|
||||
}: Refs) {
|
||||
const avatarUrl = getUrlForFileByHash(user?.avatar_file_hash)
|
||||
return (
|
||||
<mdui-dialog close-on-overlay-click close-on-esc ref={userProfileDialogRef}>
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
}}>
|
||||
<Avatar src={avatarUrl} text={user?.nickname} style={{
|
||||
width: '50px',
|
||||
height: '50px',
|
||||
}} onClick={() => avatarUrl && openImageViewer(avatarUrl)} />
|
||||
<span style={{
|
||||
marginLeft: "15px",
|
||||
fontSize: '16.5px',
|
||||
}}>{user?.nickname}</span>
|
||||
</div>
|
||||
<mdui-divider style={{
|
||||
marginTop: "10px",
|
||||
}}></mdui-divider>
|
||||
|
||||
<mdui-list>
|
||||
{/* <mdui-list-item icon="edit" rounded>设置备注</mdui-list-item> */}
|
||||
<mdui-list-item icon="chat" rounded onClick={async () => {
|
||||
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
|
||||
}}>对话</mdui-list-item>
|
||||
</mdui-list>
|
||||
</mdui-dialog>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user