feat: 从对话详情打开用户详情

This commit is contained in:
CrescentLeaf
2025-10-04 15:49:19 +08:00
parent 1fa91279e2
commit a77e22a3ea
6 changed files with 84 additions and 19 deletions

View File

@@ -16,7 +16,10 @@ export type CallMethod =
"User.getMyRecentChats" |
"Chat.getInfo" |
"Chat.getIdForPrivate" |
"Chat.getAnotherUserIdFromPrivate" |
"Chat.sendMessage" |
"Chat.getMessageHistory" |

View File

@@ -135,6 +135,12 @@ export default function App() {
loginInputAccountRef={loginInputAccountRef}
loginInputPasswordRef={loginInputPasswordRef} />
<ChatInfoDialog
chatInfoDialogRef={chatInfoDialogRef as any}
openChatFragment={openChatFragment}
openUserInfoDialog={openUserInfoDialog}
chat={chatInfo} />
<MyProfileDialog
myProfileDialogRef={myProfileDialogRef as any}
user={myUserProfileCache} />
@@ -143,11 +149,6 @@ export default function App() {
openChatFragment={openChatFragment}
user={userInfo} />
<ChatInfoDialog
chatInfoDialogRef={chatInfoDialogRef as any}
openChatFragment={openChatFragment}
chat={chatInfo} />
<AddContactDialog
addContactDialogRef={addContactDialogRef} />

View File

@@ -156,6 +156,15 @@ export default function AppMobile() {
loginInputAccountRef={loginInputAccountRef}
loginInputPasswordRef={loginInputPasswordRef} />
<ChatInfoDialog
chatInfoDialogRef={chatInfoDialogRef as any}
openUserInfoDialog={openUserInfoDialog}
openChatFragment={(id) => {
setCurrentChatId(id)
setIsShowChatFragment(true)
}}
chat={chatInfo} />
<MyProfileDialog
myProfileDialogRef={myProfileDialogRef as any}
user={myUserProfileCache} />
@@ -164,14 +173,6 @@ export default function AppMobile() {
openChatFragment={openChatFragment}
user={userInfo} />
<ChatInfoDialog
chatInfoDialogRef={chatInfoDialogRef as any}
openChatFragment={(id) => {
setCurrentChatId(id)
setIsShowChatFragment(true)
}}
chat={chatInfo} />
<AddContactDialog
addContactDialogRef={addContactDialogRef} />

View File

@@ -4,16 +4,18 @@ import useAsyncEffect from "../useAsyncEffect.ts"
import Client from "../../api/Client.ts"
import data from "../../Data.ts"
import { Dialog } from "mdui"
import Avatar from "../Avatar.tsx";
import Avatar from "../Avatar.tsx"
import { checkApiSuccessOrSncakbar } from "../snackbar.ts"
import User from "../../api/client_data/User.ts"
interface Args extends React.HTMLAttributes<HTMLElement> {
chat: Chat
openChatFragment: (id: string) => void
chatInfoDialogRef: React.MutableRefObject<Dialog>
openUserInfoDialog: (user: User | string) => void
}
export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment }: Args) {
export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragment, openUserInfoDialog }: Args) {
const [chatInfo, setChatInfo] = React.useState(null as unknown as Chat)
const isMySelf = Client.myUserProfile?.id == chatInfo?.user_a_id && Client.myUserProfile?.id == chatInfo?.user_b_id
@@ -45,14 +47,26 @@ export default function ChatInfoDialog({ chat, chatInfoDialogRef, openChatFragme
</div>
<mdui-divider style={{
marginTop: "10px",
marginBottom: "10px",
}}></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="chat" rounded onClick={() => {
chatInfoDialogRef.current!.open = false
openChatFragment(chat.id)
}}></mdui-list-item>
}}></mdui-list-item>
</mdui-list>
</mdui-dialog>
)

View File

@@ -16,7 +16,10 @@ export type CallMethod =
"User.getMyRecentChats" |
"Chat.getInfo" |
"Chat.getIdForPrivate" |
"Chat.getAnotherUserIdFromPrivate" |
"Chat.sendMessage" |
"Chat.getMessageHistory" |

View File

@@ -197,9 +197,9 @@ export default class ChatApi extends BaseApi {
}
})
/**
* 獲取對話訊息
* 获取私聊的 ChatId
* @param token 令牌
* @param target 目標用户
* @param target 目標用户
*/
this.registerEvent("Chat.getIdForPrivate", (args, { deviceId }) => {
if (this.checkArgsMissing(args, ['token', 'target'])) return {
@@ -230,5 +230,48 @@ export default class ChatApi extends BaseApi {
}
}
})
/**
* 从私聊获取对方的 UserId
* @param token 令牌
* @param target 目標对话
*/
this.registerEvent("Chat.getAnotherUserIdFromPrivate", (args, { deviceId }) => {
if (this.checkArgsMissing(args, ['token', 'target'])) return {
msg: "參數缺失",
code: 400,
}
const token = TokenManager.decode(args.token as string)
if (!this.checkToken(token, deviceId)) return {
code: 401,
msg: "令牌無效",
}
const user = User.findById(token.author) as User
const chat = Chat.findById(args.target as string)
if (chat == null) return {
code: 404,
msg: "對話不存在",
}
if (!UserChatLinker.checkUserIsLinkedToChat(token.author, chat!.bean.id)) return {
code: 400,
msg: "用戶無權訪問該對話",
}
if (chat.bean.type == 'private')
return {
code: 200,
msg: '成功',
data: {
user_id: chat.getAnotherUserForPrivate(user)?.bean.id
}
}
return {
code: 403,
msg: "非私聊对话",
}
})
}
}