Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/matching-service/models/RoomSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface Room extends mongoose.Document {


const roomSchema: Schema<Room> = new mongoose.Schema<Room>({
participants: [{ userId: String }],
participants: [{ type: String }],
category: { type: String, default: 'Any' },
difficulty: { type: String, default: 'Any' },
roomId: { type: String, required: true },
Expand Down
5 changes: 2 additions & 3 deletions backend/matching-service/workers/matchWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,14 @@ export async function emitMatchEvent(matchId: string) {
if (roomObject.questionId && roomObject.roomId) {
const newRoom = new Room({
participants: [
{ userId: roomObject.user1.userId },
{ userId: roomObject.user2.userId },
JSON.parse(roomObject.user1).userId,
JSON.parse(roomObject.user2).userId,
],
category: roomObject.category,
difficulty: roomObject.difficulty,
roomId: roomObject.roomId,
questionId: roomObject.questionId,
});

await newRoom.save();

await redisClient.xAdd("match_events", "*", { data });
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/domain/entities/Room.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface Room {
roomId: string;
attemptStartedAt: string;
userIdOne: { _id: string };
userIdTwo: { _id: string };
userIdOne: string;
userIdTwo: string;
questionId: string;
}
25 changes: 14 additions & 11 deletions frontend/src/presentation/pages/room/CollaborationRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ const CollaborationRoomPage: React.FC = () => {
setRoom({
roomId: roomId,
attemptStartedAt: attemptStartedAt,
userIdOne: { _id: user!._id },
userIdTwo: { _id: matchUserId },
userIdOne: user!._id,
userIdTwo: matchUserId,
questionId: questionId
});
} else {
if (!urlRoomId) return;
// Fetch room details from API
const fetchedRoom = await roomUseCases.getRoomDetails(urlRoomId);
console.log("Fetched Room", fetchedRoom)
// Ensure the current user is userIdOne
if (fetchedRoom.userIdOne._id !== user?._id) {
if (fetchedRoom.userIdOne !== user!._id) {
const temp = fetchedRoom.userIdOne;
fetchedRoom.userIdOne = fetchedRoom.userIdTwo;
fetchedRoom.userIdTwo = temp;
Expand Down Expand Up @@ -132,14 +133,16 @@ const CollaborationRoomPage: React.FC = () => {
<div className={styles.verticalSeparator} {...verticalSeparatorProps} />

<div className={styles.editorAndOutputContainer}>
<div className={styles.editorContainer}>
<CodeEditor
questionId={room.questionId}
roomId={room.roomId}
attemptStartedAt={new Date(room.attemptStartedAt)}
collaboratorId={room.userIdTwo?._id}
/>
</div>
{room.questionId && room.roomId && room.attemptStartedAt && room.userIdTwo &&
<div className={styles.editorContainer}>
<CodeEditor
questionId={room.questionId}
roomId={room.roomId}
attemptStartedAt={new Date(room.attemptStartedAt)}
collaboratorId={room.userIdTwo}
/>
</div>
}

<div className={styles.horizontalSeparator} {...horizontalSeparatorProps} />

Expand Down
Loading