|
|
@@ -706,6 +706,20 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
setIsPrivateClass(false);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 权限自动提升检查:仅对老师角色且非创建者/非管理员的用户进行权限提升
|
|
|
+ if (role === Role.Teacher && groupInfo) {
|
|
|
+ const isCreator = groupInfo.creator === userId;
|
|
|
+ const isAdmin = groupInfo.admins?.includes(userId) || false;
|
|
|
+
|
|
|
+ console.debug('权限检查结果:', { isCreator, isAdmin, creator: groupInfo.creator, admins: groupInfo.admins });
|
|
|
+
|
|
|
+ // 如果不是创建者且不是管理员,则进行权限提升
|
|
|
+ if (!isCreator && !isAdmin) {
|
|
|
+ console.debug('检测到需要权限提升的场景');
|
|
|
+ await autoPromoteToAdmin(gm!, classId, groupInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
console.error('获取群组信息失败:', err);
|
|
|
}
|
|
|
@@ -1463,10 +1477,70 @@ export const useClassroom = ({ user }:{ user : User }) => {
|
|
|
// 检查如果没有视频流则隐藏视频区域
|
|
|
const hideVideoAreaIfNoStreams = () => {
|
|
|
if (!aliRtcEngine.current) return;
|
|
|
-
|
|
|
+
|
|
|
setShowVideo(false);
|
|
|
};
|
|
|
|
|
|
+ // 权限自动提升功能
|
|
|
+ const autoPromoteToAdmin = async (
|
|
|
+ groupManager: ImGroupManager,
|
|
|
+ classId: string,
|
|
|
+ groupInfo: AliVCInteraction.ImGroupInfo
|
|
|
+ ): Promise<void> => {
|
|
|
+ try {
|
|
|
+ console.debug('开始自动权限提升流程');
|
|
|
+
|
|
|
+ // 显示权限提升提示
|
|
|
+ showToast('info', '正在获取管理员权限...');
|
|
|
+
|
|
|
+ // 检查当前用户是否已经是创建者或管理员
|
|
|
+ const isCreator = groupInfo.creator === userId;
|
|
|
+ const isAdmin = groupInfo.admins?.includes(userId) || false;
|
|
|
+
|
|
|
+ if (isCreator || isAdmin) {
|
|
|
+ console.debug('用户已经是创建者或管理员,无需权限提升');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建新的管理员列表(包含当前用户)
|
|
|
+ const currentAdmins = groupInfo.admins || [];
|
|
|
+ const newAdmins = [...currentAdmins, userId];
|
|
|
+
|
|
|
+ console.debug('权限提升参数:', {
|
|
|
+ currentAdmins,
|
|
|
+ newAdmins,
|
|
|
+ userId
|
|
|
+ });
|
|
|
+
|
|
|
+ // 调用modifyGroup API添加管理员权限
|
|
|
+ await groupManager.modifyGroup({
|
|
|
+ groupId: classId,
|
|
|
+ admins: newAdmins,
|
|
|
+ forceUpdateAdmins: true
|
|
|
+ });
|
|
|
+
|
|
|
+ console.debug('权限提升成功');
|
|
|
+ showToast('success', '权限获取成功');
|
|
|
+
|
|
|
+ } catch (error: any) {
|
|
|
+ console.error('权限提升失败:', error);
|
|
|
+
|
|
|
+ // 权限提升失败时的优雅降级
|
|
|
+ const errorMessage = error.message || '未知错误';
|
|
|
+ console.debug('权限提升失败详情:', errorMessage);
|
|
|
+
|
|
|
+ // 显示友好的失败提示,但不影响课堂加入流程
|
|
|
+ showToast('info', '权限获取失败,但课堂已成功加入');
|
|
|
+
|
|
|
+ // 记录错误日志但不抛出异常,确保课堂加入流程继续
|
|
|
+ console.error('管理员权限自动提升失败,但课堂加入流程继续:', {
|
|
|
+ classId,
|
|
|
+ userId,
|
|
|
+ error: errorMessage
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
const answerHandUp = async (studentId: string): Promise<void> => {
|
|
|
if (!imMessageManager.current || !classId || role !== Role.Teacher) return;
|
|
|
|