feat: 从对话详情打开用户详情
This commit is contained in:
@@ -16,7 +16,10 @@ export type CallMethod =
|
|||||||
"User.getMyRecentChats" |
|
"User.getMyRecentChats" |
|
||||||
|
|
||||||
"Chat.getInfo" |
|
"Chat.getInfo" |
|
||||||
|
|
||||||
"Chat.getIdForPrivate" |
|
"Chat.getIdForPrivate" |
|
||||||
|
"Chat.getAnotherUserIdFromPrivate" |
|
||||||
|
|
||||||
"Chat.sendMessage" |
|
"Chat.sendMessage" |
|
||||||
"Chat.getMessageHistory" |
|
"Chat.getMessageHistory" |
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,12 @@ export default function App() {
|
|||||||
loginInputAccountRef={loginInputAccountRef}
|
loginInputAccountRef={loginInputAccountRef}
|
||||||
loginInputPasswordRef={loginInputPasswordRef} />
|
loginInputPasswordRef={loginInputPasswordRef} />
|
||||||
|
|
||||||
|
<ChatInfoDialog
|
||||||
|
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||||
|
openChatFragment={openChatFragment}
|
||||||
|
openUserInfoDialog={openUserInfoDialog}
|
||||||
|
chat={chatInfo} />
|
||||||
|
|
||||||
<MyProfileDialog
|
<MyProfileDialog
|
||||||
myProfileDialogRef={myProfileDialogRef as any}
|
myProfileDialogRef={myProfileDialogRef as any}
|
||||||
user={myUserProfileCache} />
|
user={myUserProfileCache} />
|
||||||
@@ -143,11 +149,6 @@ export default function App() {
|
|||||||
openChatFragment={openChatFragment}
|
openChatFragment={openChatFragment}
|
||||||
user={userInfo} />
|
user={userInfo} />
|
||||||
|
|
||||||
<ChatInfoDialog
|
|
||||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
|
||||||
openChatFragment={openChatFragment}
|
|
||||||
chat={chatInfo} />
|
|
||||||
|
|
||||||
<AddContactDialog
|
<AddContactDialog
|
||||||
addContactDialogRef={addContactDialogRef} />
|
addContactDialogRef={addContactDialogRef} />
|
||||||
|
|
||||||
|
|||||||
@@ -156,6 +156,15 @@ export default function AppMobile() {
|
|||||||
loginInputAccountRef={loginInputAccountRef}
|
loginInputAccountRef={loginInputAccountRef}
|
||||||
loginInputPasswordRef={loginInputPasswordRef} />
|
loginInputPasswordRef={loginInputPasswordRef} />
|
||||||
|
|
||||||
|
<ChatInfoDialog
|
||||||
|
chatInfoDialogRef={chatInfoDialogRef as any}
|
||||||
|
openUserInfoDialog={openUserInfoDialog}
|
||||||
|
openChatFragment={(id) => {
|
||||||
|
setCurrentChatId(id)
|
||||||
|
setIsShowChatFragment(true)
|
||||||
|
}}
|
||||||
|
chat={chatInfo} />
|
||||||
|
|
||||||
<MyProfileDialog
|
<MyProfileDialog
|
||||||
myProfileDialogRef={myProfileDialogRef as any}
|
myProfileDialogRef={myProfileDialogRef as any}
|
||||||
user={myUserProfileCache} />
|
user={myUserProfileCache} />
|
||||||
@@ -164,14 +173,6 @@ export default function AppMobile() {
|
|||||||
openChatFragment={openChatFragment}
|
openChatFragment={openChatFragment}
|
||||||
user={userInfo} />
|
user={userInfo} />
|
||||||
|
|
||||||
<ChatInfoDialog
|
|
||||||
chatInfoDialogRef={chatInfoDialogRef as any}
|
|
||||||
openChatFragment={(id) => {
|
|
||||||
setCurrentChatId(id)
|
|
||||||
setIsShowChatFragment(true)
|
|
||||||
}}
|
|
||||||
chat={chatInfo} />
|
|
||||||
|
|
||||||
<AddContactDialog
|
<AddContactDialog
|
||||||
addContactDialogRef={addContactDialogRef} />
|
addContactDialogRef={addContactDialogRef} />
|
||||||
|
|
||||||
|
|||||||
@@ -4,16 +4,18 @@ import useAsyncEffect from "../useAsyncEffect.ts"
|
|||||||
import Client from "../../api/Client.ts"
|
import Client from "../../api/Client.ts"
|
||||||
import data from "../../Data.ts"
|
import data from "../../Data.ts"
|
||||||
import { Dialog } from "mdui"
|
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"
|
||||||
|
|
||||||
interface Args extends React.HTMLAttributes<HTMLElement> {
|
interface Args extends React.HTMLAttributes<HTMLElement> {
|
||||||
chat: Chat
|
chat: Chat
|
||||||
openChatFragment: (id: string) => void
|
openChatFragment: (id: string) => void
|
||||||
chatInfoDialogRef: React.MutableRefObject<Dialog>
|
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 [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
|
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>
|
</div>
|
||||||
<mdui-divider style={{
|
<mdui-divider style={{
|
||||||
marginTop: "10px",
|
marginTop: "10px",
|
||||||
marginBottom: "10px",
|
|
||||||
}}></mdui-divider>
|
}}></mdui-divider>
|
||||||
|
|
||||||
<mdui-list>
|
<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={() => {
|
<mdui-list-item icon="chat" rounded onClick={() => {
|
||||||
chatInfoDialogRef.current!.open = false
|
chatInfoDialogRef.current!.open = false
|
||||||
openChatFragment(chat.id)
|
openChatFragment(chat.id)
|
||||||
}}>對話</mdui-list-item>
|
}}>打开此对话</mdui-list-item>
|
||||||
</mdui-list>
|
</mdui-list>
|
||||||
</mdui-dialog>
|
</mdui-dialog>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,7 +16,10 @@ export type CallMethod =
|
|||||||
"User.getMyRecentChats" |
|
"User.getMyRecentChats" |
|
||||||
|
|
||||||
"Chat.getInfo" |
|
"Chat.getInfo" |
|
||||||
|
|
||||||
"Chat.getIdForPrivate" |
|
"Chat.getIdForPrivate" |
|
||||||
|
"Chat.getAnotherUserIdFromPrivate" |
|
||||||
|
|
||||||
"Chat.sendMessage" |
|
"Chat.sendMessage" |
|
||||||
"Chat.getMessageHistory" |
|
"Chat.getMessageHistory" |
|
||||||
|
|
||||||
|
|||||||
@@ -197,9 +197,9 @@ export default class ChatApi extends BaseApi {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
/**
|
/**
|
||||||
* 獲取對話訊息
|
* 获取私聊的 ChatId
|
||||||
* @param token 令牌
|
* @param token 令牌
|
||||||
* @param target 目標對用户
|
* @param target 目標用户
|
||||||
*/
|
*/
|
||||||
this.registerEvent("Chat.getIdForPrivate", (args, { deviceId }) => {
|
this.registerEvent("Chat.getIdForPrivate", (args, { deviceId }) => {
|
||||||
if (this.checkArgsMissing(args, ['token', 'target'])) return {
|
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: "非私聊对话",
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user