mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 03:03:24 +08:00
Load WhatsApp accessGrant into bot settings (4.9.1-ops.7).
Settings button only forwarded accessPolicy, so the graded ACL page always opened empty; also refresh grant from connection.status on mount. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
93672dfd91
commit
a4508a7caa
7 changed files with 110 additions and 8 deletions
|
|
@ -221,12 +221,47 @@ export function AccessGrantSettingsPage({ channel, account, rpcCall, onSaved })
|
|||
const [saving, setSaving] = React.useState(false);
|
||||
const [feedback, setFeedback] = React.useState(null);
|
||||
const [newGroupJid, setNewGroupJid] = React.useState('');
|
||||
const [loadingGrant, setLoadingGrant] = React.useState(!initialGrant);
|
||||
|
||||
React.useEffect(() => {
|
||||
setDraft(cloneGrant(normalizeAccessGrant(account?.accessGrant), ownerPhone));
|
||||
setGroupSessionScope(normalizeGroupSessionScope(account?.groupSessionScope));
|
||||
}, [account?.botId, initialKey, account?.groupSessionScope, ownerPhone]);
|
||||
|
||||
// Settings open payload historically omitted accessGrant; always refresh from status.
|
||||
React.useEffect(() => {
|
||||
if (typeof rpcCall !== 'function' || !account?.botId) return undefined;
|
||||
let cancelled = false;
|
||||
setLoadingGrant(true);
|
||||
void (async () => {
|
||||
try {
|
||||
const value = unwrapRpcResult(await rpcCall('connection.status', {}));
|
||||
if (cancelled) return;
|
||||
const bot = Array.isArray(value?.bots)
|
||||
? value.bots.find((entry) => entry?.botId === account.botId)
|
||||
: null;
|
||||
const grant = normalizeAccessGrant(bot?.accessGrant);
|
||||
if (grant) {
|
||||
setDraft(cloneGrant(grant, ownerPhone));
|
||||
onSaved?.(grant);
|
||||
}
|
||||
if (bot?.groupSessionScope) {
|
||||
setGroupSessionScope(normalizeGroupSessionScope(bot.groupSessionScope));
|
||||
}
|
||||
} catch (error) {
|
||||
if (!cancelled) {
|
||||
setFeedback({
|
||||
tone: 'error',
|
||||
message: error?.message || '无法读取访问授权,请返回刷新后重试。',
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) setLoadingGrant(false);
|
||||
}
|
||||
})();
|
||||
return () => { cancelled = true; };
|
||||
}, [account?.botId, rpcCall, ownerPhone]);
|
||||
|
||||
const contacts = draft.contacts ?? [];
|
||||
const knownGroupJids = React.useMemo(() => {
|
||||
const set = new Set(Object.keys(draft.groups ?? {}));
|
||||
|
|
@ -319,6 +354,9 @@ export function AccessGrantSettingsPage({ channel, account, rpcCall, onSaved })
|
|||
className: 'dim-accessPage',
|
||||
onSubmit: (event) => void save(event),
|
||||
},
|
||||
loadingGrant
|
||||
? h('div', { className: 'dim-accessState', 'aria-busy': 'true' }, '正在读取分级访问设置…')
|
||||
: null,
|
||||
h('p', { className: 'dim-accessUsersEmpty' },
|
||||
'WhatsApp 按电话号码授权:全局管理员管私聊;群管理员只批本群。成员不可跨群、有群权也不自动获得私聊权。'),
|
||||
h(AdminPhones, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue