|
|
@@ -9,7 +9,7 @@ interface IMToggleMuteButtonProps {
|
|
|
}
|
|
|
|
|
|
export const IMToggleMuteButton: React.FC<IMToggleMuteButtonProps> = ({ userId, userName }) => {
|
|
|
- const { role, muteStudentIM, unmuteStudentIM, classId, imGroupManager } = useClassroomContext();
|
|
|
+ const { role, muteStudentIM, unmuteStudentIM, classId, checkMuteStatus } = useClassroomContext();
|
|
|
const [isMuted, setIsMuted] = useState(false);
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
|
|
@@ -18,22 +18,21 @@ export const IMToggleMuteButton: React.FC<IMToggleMuteButtonProps> = ({ userId,
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- // 查询用户禁言状态
|
|
|
- const checkMuteStatus = async () => {
|
|
|
- if (!imGroupManager || !classId) return;
|
|
|
-
|
|
|
- try {
|
|
|
- const muteStatus = await imGroupManager.listMuteUsers({ groupId: classId });
|
|
|
- setIsMuted(muteStatus.muteUserList.includes(userId));
|
|
|
- } catch (error) {
|
|
|
- console.error('查询禁言状态失败:', error);
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
// 组件挂载时查询禁言状态
|
|
|
useEffect(() => {
|
|
|
- checkMuteStatus();
|
|
|
- }, [userId, classId, imGroupManager]);
|
|
|
+ const fetchMuteStatus = async () => {
|
|
|
+ if (!classId) return;
|
|
|
+
|
|
|
+ try {
|
|
|
+ const muted = await checkMuteStatus(userId);
|
|
|
+ setIsMuted(muted);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('查询禁言状态失败:', error);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ fetchMuteStatus();
|
|
|
+ }, [userId, classId, checkMuteStatus]);
|
|
|
|
|
|
const handleToggleMute = async () => {
|
|
|
if (loading) return;
|