feat: 修改对话 ID 对话名称 对话头像

* 仅群组
This commit is contained in:
CrescentLeaf
2025-10-24 22:00:22 +08:00
parent 4807038619
commit bc7b932c5c
6 changed files with 101 additions and 7 deletions

View File

@@ -19,6 +19,7 @@ export type CallMethod =
"Chat.getInfo" |
"Chat.updateSettings" |
"Chat.setAvatar" |
"Chat.createGroup" |

View File

@@ -4,6 +4,10 @@ interface GroupSettings {
new_member_join_method?: 'disabled' | 'allowed_by_admin' | 'answered_and_allowed_by_admin'
answered_and_allowed_by_admin_question?: string
// 下面两个比较特殊, 由服务端给予
group_title: string
group_id: string
[key: string]: unknown
}

View File

@@ -195,6 +195,7 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
}
const attachFileInputRef = React.useRef<HTMLInputElement>(null)
const uploadChatAvatarRef = React.useRef<HTMLInputElement>(null)
function insertText(text: string) {
const input = inputRef.current!.shadowRoot!.querySelector('[part=input]') as HTMLTextAreaElement
@@ -224,6 +225,22 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
addFile(file.type, file.name, file)
}
})
useEventListener(uploadChatAvatarRef, 'change', async (_e) => {
const file = uploadChatAvatarRef.current!.files?.[0] as File
if (file == null) return
const re = await Client.invoke("Chat.setAvatar", {
token: data.access_token,
target: target,
avatar: file
})
if (checkApiSuccessOrSncakbar(re, "修改失败")) return
snackbar({
message: "修改成功 (刷新页面以更新)",
placement: "top",
})
})
const groupPreferenceStore = new PreferenceStore<GroupSettings>()
groupPreferenceStore.setOnUpdate(async (value, oldvalue) => {
@@ -494,9 +511,35 @@ export default function ChatFragment({ target, showReturnButton, onReturnButtonC
flexDirection: "column",
height: "100%",
}}>
<div style={{
display: 'none'
}}>
<input accept="image/*" type="file" name="上传对话头像" ref={uploadChatAvatarRef}></input>
</div>
{
chatInfo.type == 'group' && <PreferenceLayout>
<PreferenceUpdater.Provider value={groupPreferenceStore.createUpdater()}>
<PreferenceHeader
title="群组资料" />
<Preference
title="上传新的头像"
icon="image"
disabled={!chatInfo.is_admin}
onClick={() => {
uploadChatAvatarRef.current!.click()
}} />
<TextFieldPreference
title="设置群名称"
icon="edit"
id="group_title"
state={groupPreferenceStore.state.group_title || ''}
disabled={!chatInfo.is_admin} />
<TextFieldPreference
title="设置群 ID"
icon="edit"
id="group_id"
state={groupPreferenceStore.state.group_id || ''}
disabled={!chatInfo.is_admin} />
<PreferenceHeader
title="群组管理" />
<Preference