群昵称改用专门的接口读取,修好读不回已保存值的问题
上一个commit修好了"群资料"页把群名称当成个人群昵称显示的问题,但实机验证发现改完仍然显示"未设置"。
抓包确认根因:GET /groups/{topic}/members 列表接口的每一项里压根没有 group_nickname 字段(只有
acs/display_name/mentionable/role/user_id),所以任何从成员列表里读昵称的写法,不管代码逻辑对不对,
都永远拿不到值——这个文件里原有的 MyNicknameEditor 也是同样的写法,同样存在这个问题(打开编辑器时
不会回填已保存的昵称)。
真正能读到昵称的是保存用的那个路径上对应的 GET:GET /groups/{topic}/members/me/profile,返回
{nickname, version, updated_at}(server/im_http.go:4776-4782)。im-api.js 里之前只封装了 PUT,
补上了对应的 getMyGroupProfile,两处读取(群资料页预览行、昵称编辑器回填)都改成用它。
实机验证:保存"测试昵称A"后重新打开群资料页,"群昵称"正确显示"测试昵称A","群名称"独立显示
"扫码测试群"。
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
e4c6e1b246
commit
3bdb0bf40f
+29
-11
@@ -3426,6 +3426,7 @@ __webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ getMonthlyReport: function() { return /* binding */ getMonthlyReport; },
|
||||
/* harmony export */ getMonthlyReports: function() { return /* binding */ getMonthlyReports; },
|
||||
/* harmony export */ getMonthlyStatistics: function() { return /* binding */ getMonthlyStatistics; },
|
||||
/* harmony export */ getMyGroupProfile: function() { return /* binding */ getMyGroupProfile; },
|
||||
/* harmony export */ getOrganizationDepartmentMembers: function() { return /* binding */ getOrganizationDepartmentMembers; },
|
||||
/* harmony export */ getOrganizationDepartments: function() { return /* binding */ getOrganizationDepartments; },
|
||||
/* harmony export */ getOrganizationMembers: function() { return /* binding */ getOrganizationMembers; },
|
||||
@@ -4176,6 +4177,7 @@ const updateMyGroupProfile = (topic, nickname, version) => imPut('/groups/' + en
|
||||
nickname,
|
||||
version
|
||||
});
|
||||
const getMyGroupProfile = topic => imGet('/groups/' + encodeURIComponent(topic) + '/members/me/profile');
|
||||
const leaveGroup = topic => imPost('/groups/' + encodeURIComponent(topic) + '/leave', {});
|
||||
const getGroupMembers = (topic, {
|
||||
query = '',
|
||||
@@ -11154,10 +11156,12 @@ function GroupSettings({
|
||||
}
|
||||
function GroupProfile({
|
||||
topic,
|
||||
myUserId,
|
||||
onToast
|
||||
}) {
|
||||
const [group, setGroup] = react__WEBPACK_IMPORTED_MODULE_0___default().useState(() => topic && (0,_lib_use_cached_data_js__WEBPACK_IMPORTED_MODULE_5__.readCachedData)('group:' + topic) || null);
|
||||
const [loadError, setLoadError] = react__WEBPACK_IMPORTED_MODULE_0___default().useState(false);
|
||||
const [myNickname, setMyNickname] = react__WEBPACK_IMPORTED_MODULE_0___default().useState('');
|
||||
react__WEBPACK_IMPORTED_MODULE_0___default().useEffect(() => {
|
||||
if (!topic) return;
|
||||
setGroup((0,_lib_use_cached_data_js__WEBPACK_IMPORTED_MODULE_5__.readCachedData)('group:' + topic) || null);
|
||||
@@ -11169,6 +11173,12 @@ function GroupProfile({
|
||||
setLoadError(true);
|
||||
});
|
||||
}, [topic]);
|
||||
react__WEBPACK_IMPORTED_MODULE_0___default().useEffect(() => {
|
||||
if (!topic) return;
|
||||
(0,_lib_im_api_js__WEBPACK_IMPORTED_MODULE_4__.getMyGroupProfile)(topic).then(data => {
|
||||
setMyNickname(data.nickname || '');
|
||||
}).catch(() => {});
|
||||
}, [topic]);
|
||||
if (!group) return (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("div", {
|
||||
className: "group-page",
|
||||
children: [(0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(Header, {
|
||||
@@ -11184,6 +11194,7 @@ function GroupProfile({
|
||||
}, void 0, false)]
|
||||
}, void 0, true);
|
||||
const canEdit = group.permissions && group.permissions.can_edit_profile;
|
||||
const nicknameLabel = myNickname || '未设置';
|
||||
return (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("div", {
|
||||
className: "group-page",
|
||||
children: [(0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(Header, {
|
||||
@@ -11204,11 +11215,21 @@ function GroupProfile({
|
||||
}, void 0, false), (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(Icon, {
|
||||
children: "chevron_right"
|
||||
}, void 0, false)]
|
||||
}, void 0, true), (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("button", {
|
||||
type: "button",
|
||||
onClick: () => navigate('group-my-nickname', topic),
|
||||
children: [(0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("span", {
|
||||
children: "群昵称"
|
||||
}, void 0, false), (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("small", {
|
||||
children: nicknameLabel
|
||||
}, void 0, false), (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(Icon, {
|
||||
children: "chevron_right"
|
||||
}, void 0, false)]
|
||||
}, void 0, true), canEdit ? (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("button", {
|
||||
type: "button",
|
||||
onClick: () => navigate('group-nickname', topic),
|
||||
children: [(0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("span", {
|
||||
children: "群昵称"
|
||||
children: "群名称"
|
||||
}, void 0, false), (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("small", {
|
||||
children: group.name
|
||||
}, void 0, false), (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(Icon, {
|
||||
@@ -11216,7 +11237,7 @@ function GroupProfile({
|
||||
}, void 0, false)]
|
||||
}, void 0, true) : (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("div", {
|
||||
children: [(0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("span", {
|
||||
children: "群昵称"
|
||||
children: "群名称"
|
||||
}, void 0, false), (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)("small", {
|
||||
children: group.name
|
||||
}, void 0, false)]
|
||||
@@ -11254,6 +11275,7 @@ function GroupProfile({
|
||||
}
|
||||
function AvatarSheet({
|
||||
topic,
|
||||
myUserId,
|
||||
tinode,
|
||||
onToast
|
||||
}) {
|
||||
@@ -12155,19 +12177,13 @@ function GroupDescriptionEditor({
|
||||
}
|
||||
function MyNicknameEditor({
|
||||
topic,
|
||||
myUserId,
|
||||
onToast
|
||||
}) {
|
||||
const [value, setValue] = react__WEBPACK_IMPORTED_MODULE_0___default().useState('');
|
||||
react__WEBPACK_IMPORTED_MODULE_0___default().useEffect(() => {
|
||||
if (!topic || !myUserId) return;
|
||||
(0,_lib_im_api_js__WEBPACK_IMPORTED_MODULE_4__.getGroupMembers)(topic, {
|
||||
query: ''
|
||||
}).then(data => {
|
||||
const me = (data.items || []).find(m => m.user_id === myUserId);
|
||||
if (me) setValue(me.group_nickname || '');
|
||||
}).catch(() => {});
|
||||
}, [topic, myUserId]);
|
||||
if (!topic) return;
|
||||
(0,_lib_im_api_js__WEBPACK_IMPORTED_MODULE_4__.getMyGroupProfile)(topic).then(data => setValue(data.nickname || '')).catch(() => {});
|
||||
}, [topic]);
|
||||
const save = () => {
|
||||
(0,_lib_im_api_js__WEBPACK_IMPORTED_MODULE_4__.updateMyGroupProfile)(topic, value.trim(), 0).then(() => {
|
||||
onToast('保存成功');
|
||||
@@ -12243,9 +12259,11 @@ function GroupManagementView({
|
||||
onToast: setToast
|
||||
}, void 0, false);else if (view === 'group-profile') content = (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(GroupProfile, {
|
||||
topic: topic,
|
||||
myUserId: myUserId,
|
||||
onToast: setToast
|
||||
}, void 0, false);else if (view === 'group-avatar') content = (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(AvatarSheet, {
|
||||
topic: topic,
|
||||
myUserId: myUserId,
|
||||
tinode: tinode,
|
||||
onToast: setToast
|
||||
}, void 0, false);else if (view === 'group-nickname') content = (0,react_jsx_dev_runtime__WEBPACK_IMPORTED_MODULE_6__.jsxDEV)(GroupNameEditor, {
|
||||
|
||||
Reference in New Issue
Block a user