个股论坛重做
This commit is contained in:
@@ -69,7 +69,12 @@ const MessageItem: React.FC<MessageItemProps> = ({
|
||||
} = 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;
|
||||
|
||||
@@ -90,9 +90,11 @@ const TextChannel: React.FC<TextChannelProps> = ({
|
||||
getChannelAdmins(channel.id).then(admins => {
|
||||
const adminMap = new Map<string, 'super_admin' | 'owner' | 'admin' | 'moderator'>();
|
||||
admins.forEach(admin => {
|
||||
adminMap.set(admin.userId, admin.role);
|
||||
// 确保 userId 是字符串类型
|
||||
adminMap.set(String(admin.userId), admin.role);
|
||||
});
|
||||
setChannelAdminList(adminMap);
|
||||
console.log('[TextChannel] 管理员列表已加载:', adminMap);
|
||||
}).catch(console.error);
|
||||
}, [loadMessages, channel.id, loadChannelAdminStatus, setChannelAdminList]);
|
||||
|
||||
@@ -138,7 +140,8 @@ const TextChannel: React.FC<TextChannelProps> = ({
|
||||
if (!container || loadingMore || !hasMore) return;
|
||||
|
||||
if (container.scrollTop < 100 && messages.length > 0) {
|
||||
loadMessages(messages[0].id);
|
||||
// 传递第一条消息的 createdAt 时间戳,用于分页查询
|
||||
loadMessages(messages[0].createdAt);
|
||||
}
|
||||
}, [loadingMore, hasMore, messages, loadMessages]);
|
||||
|
||||
|
||||
@@ -78,7 +78,8 @@ const MemberList: React.FC<MemberListProps> = ({ channelId }) => {
|
||||
// 获取成员的管理员角色
|
||||
const getMemberRole = (userId: string): AdminRole | null => {
|
||||
// 从管理员列表中查找(已包含超级管理员)
|
||||
return channelAdminList.get(userId) || null;
|
||||
// 确保使用字符串类型的 key
|
||||
return channelAdminList.get(String(userId)) || null;
|
||||
};
|
||||
|
||||
// 过滤成员
|
||||
|
||||
@@ -135,12 +135,13 @@ export const getMessages = async (
|
||||
});
|
||||
}
|
||||
|
||||
// 查询时总是按时间降序获取(最新的在前)
|
||||
const response = await fetch(`${ES_API_BASE}/community_messages/_search`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
query,
|
||||
sort: [{ created_at: before ? 'desc' : 'asc' }],
|
||||
sort: [{ created_at: 'desc' }],
|
||||
size: limit,
|
||||
}),
|
||||
});
|
||||
@@ -174,10 +175,8 @@ export const getMessages = async (
|
||||
};
|
||||
});
|
||||
|
||||
// 如果是向前加载,需要反转顺序
|
||||
if (before) {
|
||||
items.reverse();
|
||||
}
|
||||
// 反转顺序,让最旧的在前(聊天室从上到下是时间顺序)
|
||||
items.reverse();
|
||||
|
||||
return {
|
||||
items,
|
||||
|
||||
Reference in New Issue
Block a user