Fix group-profile nickname preview showing group name instead of my own nickname
GroupProfile's "群昵称" preview row showed group.name -- the group's own display name -- instead
of the current user's personal nickname within that group (a real, distinct concept, correctly
handled by the existing MyNicknameEditor/group-my-nickname page, just not wired into this preview
row). Ported the substance of a bug dev independently found and fixed in their own reimplementation
of this same page ("show saved group nickname", found while evaluating what from dev's post-fork
commits was worth bringing over). Reuses the same getGroupMembers+filter-by-myUserId approach
MyNicknameEditor already uses in this file (there's no working "me" shortcut on the
member-profile-by-id endpoint that would let this be fetched more directly -- confirmed by reading
server/im_http.go's routing, which never special-cases that literal string).
Also renamed the adjacent "群昵称"->"群名称" label for the group's own display name field, since
having two rows both labeled "群昵称" (one for my personal nickname, one for the group's name) is
exactly the confusion that caused this bug in the first place.
Evaluated the rest of dev's post-fork commits (9 commits fixing this same page's nickname-save
reliability, plus the wholesale chapter-view reimplementation) for anything else worth porting:
the version-conflict retry logic they built doesn't apply here since this branch already sends
version:0 (confirmed server/im_http.go:4793 treats <=0 as "skip the check" -- the exact mechanism
their fix was working around a different way), and their nickname maxLength bump (11->20) is
already exceeded by this branch's existing 32, which matches the real backend limit
(server/im_http.go:4789). Nothing else from dev's branch was found applicable.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
2c77a8e229
commit
e4c6e1b246
@@ -393,28 +393,44 @@ function GroupSettings({topic, myUserId, tinode, onToast}) {
|
|||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GroupProfile({topic, onToast}) {
|
function GroupProfile({topic, myUserId, onToast}) {
|
||||||
// Shares 'group:'+topic with the nickname/description editors' own getGroup(topic) calls -- opening
|
// Shares 'group:'+topic with the nickname/description editors' own getGroup(topic) calls -- opening
|
||||||
// this once warms the cache for either of those too.
|
// this once warms the cache for either of those too.
|
||||||
const [group, setGroup] = React.useState(() => (topic && readCachedData('group:' + topic)) || null);
|
const [group, setGroup] = React.useState(() => (topic && readCachedData('group:' + topic)) || null);
|
||||||
const [loadError, setLoadError] = React.useState(false);
|
const [loadError, setLoadError] = React.useState(false);
|
||||||
|
// "群昵称" here means "my nickname within this group" (see MyNicknameEditor below), not the group's
|
||||||
|
// own name -- confirmed live this preview row was showing group.name instead, since it's easy to
|
||||||
|
// conflate the two. Reuses the same getGroupMembers+filter approach MyNicknameEditor already uses
|
||||||
|
// (there's no working "me" shortcut on the member-profile-by-id endpoint to fetch this more directly).
|
||||||
|
const [myNickname, setMyNickname] = React.useState('');
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!topic) return;
|
if (!topic) return;
|
||||||
setGroup(readCachedData('group:' + topic) || null);
|
setGroup(readCachedData('group:' + topic) || null);
|
||||||
getGroup(topic).then(g => { writeCachedData('group:' + topic, g); setGroup(g); }).catch(() => { onToast('加载失败'); setLoadError(true); });
|
getGroup(topic).then(g => { writeCachedData('group:' + topic, g); setGroup(g); }).catch(() => { onToast('加载失败'); setLoadError(true); });
|
||||||
}, [topic]);
|
}, [topic]);
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!topic || !myUserId) return;
|
||||||
|
getGroupMembers(topic, {query: ''}).then(data => {
|
||||||
|
const me = (data.items || []).find(m => m.user_id === myUserId);
|
||||||
|
if (me) setMyNickname(me.group_nickname || '');
|
||||||
|
}).catch(() => {});
|
||||||
|
}, [topic, myUserId]);
|
||||||
if (!group) return <div className="group-page"><Header title="群资料" back="group-settings" backTopic={topic} /><main className="group-profile"><p className="group-inline-empty">{loadError ? '群组信息加载失败' : '加载中…'}</p></main></div>;
|
if (!group) return <div className="group-page"><Header title="群资料" back="group-settings" backTopic={topic} /><main className="group-profile"><p className="group-inline-empty">{loadError ? '群组信息加载失败' : '加载中…'}</p></main></div>;
|
||||||
const canEdit = group.permissions && group.permissions.can_edit_profile;
|
const canEdit = group.permissions && group.permissions.can_edit_profile;
|
||||||
|
const nicknameLabel = myNickname || '未设置';
|
||||||
return <div className="group-page">
|
return <div className="group-page">
|
||||||
<Header title="群资料" back="group-settings" backTopic={topic} />
|
<Header title="群资料" back="group-settings" backTopic={topic} />
|
||||||
<main className="group-profile">
|
<main className="group-profile">
|
||||||
<button type="button" className="group-profile-avatar" disabled={!canEdit} onClick={() => canEdit && navigate('group-avatar', topic)}>
|
<button type="button" className="group-profile-avatar" disabled={!canEdit} onClick={() => canEdit && navigate('group-avatar', topic)}>
|
||||||
<Avatar item={group} /><span>群头像</span><Icon>chevron_right</Icon>
|
<Avatar item={group} /><span>群头像</span><Icon>chevron_right</Icon>
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" onClick={() => navigate('group-my-nickname', topic)}>
|
||||||
|
<span>群昵称</span><small>{nicknameLabel}</small><Icon>chevron_right</Icon>
|
||||||
|
</button>
|
||||||
{canEdit ? <button type="button" onClick={() => navigate('group-nickname', topic)}>
|
{canEdit ? <button type="button" onClick={() => navigate('group-nickname', topic)}>
|
||||||
<span>群昵称</span><small>{group.name}</small><Icon>chevron_right</Icon>
|
<span>群名称</span><small>{group.name}</small><Icon>chevron_right</Icon>
|
||||||
</button> :
|
</button> :
|
||||||
<div><span>群昵称</span><small>{group.name}</small></div>}
|
<div><span>群名称</span><small>{group.name}</small></div>}
|
||||||
{canEdit ? <button type="button" onClick={() => navigate('group-description', topic)}>
|
{canEdit ? <button type="button" onClick={() => navigate('group-description', topic)}>
|
||||||
<span>群简介</span><small>{group.description || '群主很懒,还没有群简介'}</small><Icon>chevron_right</Icon>
|
<span>群简介</span><small>{group.description || '群主很懒,还没有群简介'}</small><Icon>chevron_right</Icon>
|
||||||
</button> :
|
</button> :
|
||||||
@@ -425,7 +441,7 @@ function GroupProfile({topic, onToast}) {
|
|||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function AvatarSheet({topic, tinode, onToast}) {
|
function AvatarSheet({topic, myUserId, tinode, onToast}) {
|
||||||
const inputRef = React.useRef(null);
|
const inputRef = React.useRef(null);
|
||||||
const [uploading, setUploading] = React.useState(false);
|
const [uploading, setUploading] = React.useState(false);
|
||||||
const pick = () => inputRef.current && inputRef.current.click();
|
const pick = () => inputRef.current && inputRef.current.click();
|
||||||
@@ -897,8 +913,8 @@ export default function GroupManagementView({view, hashParams, myUserId, tinode,
|
|||||||
else if (view === 'group-join-requests') content = <JoinRequests topic={topic} onToast={setToast} />;
|
else if (view === 'group-join-requests') content = <JoinRequests topic={topic} onToast={setToast} />;
|
||||||
else if (view === 'group-announcement-detail') content = <Announcement topic={topic} myRole={myRole} fromChat={hashParams && hashParams.from === 'chat'} onToast={setToast} />;
|
else if (view === 'group-announcement-detail') content = <Announcement topic={topic} myRole={myRole} fromChat={hashParams && hashParams.from === 'chat'} onToast={setToast} />;
|
||||||
else if (view === 'group-settings') content = <GroupSettings topic={topic} myUserId={myUserId} tinode={tinode} onToast={setToast} />;
|
else if (view === 'group-settings') content = <GroupSettings topic={topic} myUserId={myUserId} tinode={tinode} onToast={setToast} />;
|
||||||
else if (view === 'group-profile') content = <GroupProfile topic={topic} onToast={setToast} />;
|
else if (view === 'group-profile') content = <GroupProfile topic={topic} myUserId={myUserId} onToast={setToast} />;
|
||||||
else if (view === 'group-avatar') content = <AvatarSheet topic={topic} tinode={tinode} onToast={setToast} />;
|
else if (view === 'group-avatar') content = <AvatarSheet topic={topic} myUserId={myUserId} tinode={tinode} onToast={setToast} />;
|
||||||
else if (view === 'group-nickname') content = <GroupNameEditor topic={topic} onToast={setToast} />;
|
else if (view === 'group-nickname') content = <GroupNameEditor topic={topic} onToast={setToast} />;
|
||||||
else if (view === 'group-description') content = <GroupDescriptionEditor topic={topic} onToast={setToast} />;
|
else if (view === 'group-description') content = <GroupDescriptionEditor topic={topic} onToast={setToast} />;
|
||||||
else if (view === 'group-my-nickname') content = <MyNicknameEditor topic={topic} myUserId={myUserId} onToast={setToast} />;
|
else if (view === 'group-my-nickname') content = <MyNicknameEditor topic={topic} myUserId={myUserId} onToast={setToast} />;
|
||||||
|
|||||||
Reference in New Issue
Block a user