个股论坛重做

This commit is contained in:
2026-01-06 13:45:06 +08:00
parent eb7751169d
commit eb50b14b7b
4 changed files with 17 additions and 9 deletions

View File

@@ -69,7 +69,12 @@ const MessageItem: React.FC<MessageItemProps> = ({
} = useAdmin(); } = useAdmin();
// 获取消息作者的管理员角色(包括超级管理员) // 获取消息作者的管理员角色(包括超级管理员)
const authorRole = getUserAdminRole(message.authorId); // 确保 authorId 是字符串类型,因为管理员列表使用字符串作为 key
const authorIdStr = String(message.authorId);
const authorRole = getUserAdminRole(authorIdStr);
// Debug 日志(可以之后移除)
// console.log(`[MessageItem] authorId=${authorIdStr}, authorRole=${authorRole}`);
// 获取显示的角色徽章 // 获取显示的角色徽章
const roleBadge = authorRole ? ROLE_BADGE_CONFIG[authorRole] : null; const roleBadge = authorRole ? ROLE_BADGE_CONFIG[authorRole] : null;

View File

@@ -90,9 +90,11 @@ const TextChannel: React.FC<TextChannelProps> = ({
getChannelAdmins(channel.id).then(admins => { getChannelAdmins(channel.id).then(admins => {
const adminMap = new Map<string, 'super_admin' | 'owner' | 'admin' | 'moderator'>(); const adminMap = new Map<string, 'super_admin' | 'owner' | 'admin' | 'moderator'>();
admins.forEach(admin => { admins.forEach(admin => {
adminMap.set(admin.userId, admin.role); // 确保 userId 是字符串类型
adminMap.set(String(admin.userId), admin.role);
}); });
setChannelAdminList(adminMap); setChannelAdminList(adminMap);
console.log('[TextChannel] 管理员列表已加载:', adminMap);
}).catch(console.error); }).catch(console.error);
}, [loadMessages, channel.id, loadChannelAdminStatus, setChannelAdminList]); }, [loadMessages, channel.id, loadChannelAdminStatus, setChannelAdminList]);
@@ -138,7 +140,8 @@ const TextChannel: React.FC<TextChannelProps> = ({
if (!container || loadingMore || !hasMore) return; if (!container || loadingMore || !hasMore) return;
if (container.scrollTop < 100 && messages.length > 0) { if (container.scrollTop < 100 && messages.length > 0) {
loadMessages(messages[0].id); // 传递第一条消息的 createdAt 时间戳,用于分页查询
loadMessages(messages[0].createdAt);
} }
}, [loadingMore, hasMore, messages, loadMessages]); }, [loadingMore, hasMore, messages, loadMessages]);

View File

@@ -78,7 +78,8 @@ const MemberList: React.FC<MemberListProps> = ({ channelId }) => {
// 获取成员的管理员角色 // 获取成员的管理员角色
const getMemberRole = (userId: string): AdminRole | null => { const getMemberRole = (userId: string): AdminRole | null => {
// 从管理员列表中查找(已包含超级管理员) // 从管理员列表中查找(已包含超级管理员)
return channelAdminList.get(userId) || null; // 确保使用字符串类型的 key
return channelAdminList.get(String(userId)) || null;
}; };
// 过滤成员 // 过滤成员

View File

@@ -135,12 +135,13 @@ export const getMessages = async (
}); });
} }
// 查询时总是按时间降序获取(最新的在前)
const response = await fetch(`${ES_API_BASE}/community_messages/_search`, { const response = await fetch(`${ES_API_BASE}/community_messages/_search`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({
query, query,
sort: [{ created_at: before ? 'desc' : 'asc' }], sort: [{ created_at: 'desc' }],
size: limit, size: limit,
}), }),
}); });
@@ -174,10 +175,8 @@ export const getMessages = async (
}; };
}); });
// 如果是向前加载,需要反转顺序 // 反转顺序,让最旧的在前(聊天室从上到下是时间顺序)
if (before) {
items.reverse(); items.reverse();
}
return { return {
items, items,