updating to have statuses for rooms
This commit is contained in:
@@ -7,7 +7,7 @@ import {
|
||||
serverTimestamp,
|
||||
setDoc,
|
||||
} from "firebase/firestore";
|
||||
import Room from "../models/room";
|
||||
import Room, { RoomStatus } from "../models/room";
|
||||
import { Collections } from "./collections";
|
||||
|
||||
export default class RoomService {
|
||||
@@ -21,10 +21,20 @@ export default class RoomService {
|
||||
}
|
||||
|
||||
async updateMembersInRoom(roomId: string, newMembersInRoom: string[]) {
|
||||
// if the room is going to be empty, then change status accordingly
|
||||
var status: RoomStatus = RoomStatus.live;
|
||||
if (newMembersInRoom.length == 0) {
|
||||
status = RoomStatus.empty;
|
||||
}
|
||||
|
||||
const docRef = doc(this.db, Collections.rooms, roomId);
|
||||
await setDoc(
|
||||
docRef,
|
||||
{ membersInRoom: newMembersInRoom, lastUpdatedDate: serverTimestamp() },
|
||||
{
|
||||
status,
|
||||
membersInRoom: newMembersInRoom,
|
||||
lastUpdatedDate: serverTimestamp(),
|
||||
},
|
||||
{ merge: true }
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user