Browse Source

lvesessions logic updated , avoids overwriting participants and session details

master
Mohsen Taba 2 months ago
parent
commit
800a2dd2b4
  1. 39
      apps/course/views/live_session.py

39
apps/course/views/live_session.py

@ -51,39 +51,24 @@ class CourseLiveSessionRoomCreateAPIView(GenericAPIView):
raise AppAPIException({'message': 'Permission denied'}, status_code=403)
# 2. Setup ID and Metadata
room_id = f"room-{course.id}-imamjavad"
subject = f"{course.title} Live Session"
# 3. Database Logic - Check FIRST before calling PlugNMeet
# Strategy:
# 1. Try to find active session (ended_at is NULL)
# 2. If not found, try to find ended session with same room_id and reactivate it
# 3. If not found, create new session
session = None
needs_room_creation = False
session = CourseLiveSession.objects.filter(
course=course, ended_at__isnull=True
).first()
try:
# Try to get active session first
session = CourseLiveSession.objects.get(
course=course, room_id=room_id, ended_at__isnull=True
)
needs_room_creation = False
if session:
room_id = session.room_id
logger.info(f"[LiveSession Create] Found active session - session_id={session.id} room_id={room_id}")
except CourseLiveSession.DoesNotExist:
# No active session, check if there's an old one with same room_id
try:
session = CourseLiveSession.objects.get(
course=course, room_id=room_id
)
# Reactivate the old session and mark for room recreation
session.ended_at = None
session.started_at = timezone.now()
session.subject = subject
session.save(update_fields=['ended_at', 'started_at', 'subject', 'updated_at'])
needs_room_creation = True
logger.info(f"[LiveSession Create] Reactivated ended session - session_id={session.id} room_id={room_id}")
except CourseLiveSession.DoesNotExist:
# No session exists at all, create new one and mark for room creation
else:
# No active session, always create a new one with a dynamic room_id
import time
timestamp = int(time.time())
room_id = f"room-{course.id}-{timestamp}"
session = CourseLiveSession.objects.create(
course=course,
room_id=room_id,

Loading…
Cancel
Save