diff --git a/plugins/love-resources/src/components/ControlExt.svelte b/plugins/love-resources/src/components/ControlExt.svelte index e4cefc9f43..103d4c5787 100644 --- a/plugins/love-resources/src/components/ControlExt.svelte +++ b/plugins/love-resources/src/components/ControlExt.svelte @@ -162,7 +162,7 @@ function checkRequests (requests: JoinRequest[], $myInfo: ParticipantInfo | undefined): void { if (activeRequest !== undefined) { // try to find active request, if it not exists close popup - if (requests.find((r) => r._id === activeRequest?._id) === undefined) { + if (requests.find((r) => r._id === activeRequest?._id && r.room === $myInfo?.room) === undefined) { closePopup(joinRequestCategory) activeRequest = undefined } diff --git a/server-plugins/love-resources/src/index.ts b/server-plugins/love-resources/src/index.ts index 9917a80f36..41e2a834c4 100644 --- a/server-plugins/love-resources/src/index.ts +++ b/server-plugins/love-resources/src/index.ts @@ -136,7 +136,7 @@ export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise { void removeUserInfo(status.user, control) - }, 5000) + }, 20000) return [] } } @@ -166,6 +166,32 @@ async function roomJoinHandler (info: ParticipantInfo, control: TriggerControl, } } +async function rejectJoinRequests ( + info: ParticipantInfo, + control: TriggerControl, + roomInfos: RoomInfo[] +): Promise { + const res: Tx[] = [] + const oldRoomInfo = roomInfos.find((ri) => ri.persons.includes(info.person)) + if (oldRoomInfo !== undefined) { + const restPersons = oldRoomInfo.persons.filter((p) => p !== info.person) + if (restPersons.length === 0) { + const requests = await control.findAll(love.class.JoinRequest, { + room: oldRoomInfo.room, + status: RequestStatus.Pending + }) + for (const request of requests) { + res.push( + control.txFactory.createTxUpdateDoc(love.class.JoinRequest, love.space.Rooms, request._id, { + status: RequestStatus.Rejected + }) + ) + } + } + } + return res +} + function setDefaultRoomAccess (info: ParticipantInfo, roomInfos: RoomInfo[], control: TriggerControl): Tx[] { const res: Tx[] = [] const oldRoomInfo = roomInfos.find((ri) => ri.persons.includes(info.person)) @@ -209,6 +235,7 @@ export async function OnParticipantInfo (tx: Tx, control: TriggerControl): Promi const info = (await control.findAll(love.class.ParticipantInfo, { _id: actualTx.objectId }, { limit: 1 }))[0] if (info === undefined) return [] const res: Tx[] = [] + res.push(...(await rejectJoinRequests(info, control, roomInfos))) res.push(...setDefaultRoomAccess(info, roomInfos, control)) res.push(...(await roomJoinHandler(info, control, roomInfos))) return res