From e1249789dc74ea31d4c8aabd25a8693151ae95a8 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Thu, 1 Aug 2024 15:20:41 +0500 Subject: [PATCH] Validate meeting time (#6212) Signed-off-by: Denis Bykhov --- .../love-resources/src/components/Hall.svelte | 10 ++- .../love-resources/src/components/Room.svelte | 4 +- .../src/components/RoomSelector.svelte | 2 +- plugins/love-resources/src/stores.ts | 78 +++++++++++++------ plugins/love-resources/src/utils.ts | 12 ++- 5 files changed, 75 insertions(+), 31 deletions(-) diff --git a/plugins/love-resources/src/components/Hall.svelte b/plugins/love-resources/src/components/Hall.svelte index b1a8b48fc4..ab54f7836a 100644 --- a/plugins/love-resources/src/components/Hall.svelte +++ b/plugins/love-resources/src/components/Hall.svelte @@ -16,11 +16,11 @@ import { Contact, Person } from '@hcengineering/contact' import { personByIdStore } from '@hcengineering/contact-resources' import { Ref } from '@hcengineering/core' - import love, { Floor as FloorType, Meeting, Office, Room, RoomInfo, isOffice } from '@hcengineering/love' + import love, { Floor as FloorType, Office, Room, RoomInfo, isOffice } from '@hcengineering/love' import { getClient } from '@hcengineering/presentation' import { deviceOptionsStore as deviceInfo, getCurrentLocation, navigate } from '@hcengineering/ui' - import { onMount, onDestroy } from 'svelte' - import { activeFloor, floors, infos, invites, myInfo, myRequests, rooms } from '../stores' + import { onDestroy, onMount } from 'svelte' + import { activeFloor, floors, infos, invites, myInfo, myRequests, rooms, storePromise } from '../stores' import { connectToMeeting, tryConnect } from '../utils' import Floor from './Floor.svelte' import FloorConfigure from './FloorConfigure.svelte' @@ -64,9 +64,11 @@ loc.query = Object.keys(query).length === 0 ? undefined : query navigate(loc, true) if (sessionId != null) { + await $storePromise await connectToSession(sessionId) } else if (meetId != null) { - await connectToMeeting($personByIdStore, $myInfo, $infos, $myRequests, $invites, $rooms, meetId) + await $storePromise + await connectToMeeting($personByIdStore, $myInfo, $infos, $myRequests, $invites, meetId) } }) diff --git a/plugins/love-resources/src/components/Room.svelte b/plugins/love-resources/src/components/Room.svelte index cfd07e4d4a..e06d5d4725 100644 --- a/plugins/love-resources/src/components/Room.svelte +++ b/plugins/love-resources/src/components/Room.svelte @@ -31,7 +31,7 @@ } from 'livekit-client' import { onDestroy, onMount, tick } from 'svelte' import love from '../plugin' - import { currentRoom, infos, invites, myInfo, myRequests } from '../stores' + import { storePromise, currentRoom, infos, invites, myInfo, myRequests } from '../stores' import { awaitConnect, isConnected, @@ -221,6 +221,8 @@ configured = true + await $storePromise + if (!$isConnected && !$isCurrentInstanceConnected) { const info = $infos.filter((p) => p.room === room._id) await tryConnect($personByIdStore, $myInfo, room, info, $myRequests, $invites) diff --git a/plugins/love-resources/src/components/RoomSelector.svelte b/plugins/love-resources/src/components/RoomSelector.svelte index 570b4f96c6..36d15c39c3 100644 --- a/plugins/love-resources/src/components/RoomSelector.svelte +++ b/plugins/love-resources/src/components/RoomSelector.svelte @@ -26,7 +26,7 @@ const dispatch = createEventDispatcher() $: items = $rooms - .filter((p) => !isOffice(p)) + .filter((p) => !isOffice(p) && p._id !== love.ids.Reception) .map((p) => { return { _id: p._id, diff --git a/plugins/love-resources/src/stores.ts b/plugins/love-resources/src/stores.ts index 14ae588ceb..323d36a9b8 100644 --- a/plugins/love-resources/src/stores.ts +++ b/plugins/love-resources/src/stores.ts @@ -64,38 +64,72 @@ function filterParticipantInfo (value: ParticipantInfo[]): ParticipantInfo[] { return Array.from(map.values()) } +export const storePromise = writable>(new Promise((resolve) => {})) + function fillStores (): void { const client = getClient() if (client !== undefined) { const query = createQuery(true) - query.query(love.class.Room, {}, (res) => { - rooms.set(res) - }) + const roomPromise = new Promise((resolve) => + query.query(love.class.Room, {}, (res) => { + rooms.set(res) + resolve() + }) + ) const statusQuery = createQuery(true) - statusQuery.query(love.class.ParticipantInfo, {}, (res) => { - infos.set(filterParticipantInfo(res)) - }) + const infoPromise = new Promise((resolve) => + statusQuery.query(love.class.ParticipantInfo, {}, (res) => { + infos.set(filterParticipantInfo(res)) + resolve() + }) + ) const floorsQuery = createQuery(true) - floorsQuery.query(love.class.Floor, {}, (res) => { - floors.set(res) - }) + const floorPromise = new Promise((resolve) => + floorsQuery.query(love.class.Floor, {}, (res) => { + floors.set(res) + resolve() + }) + ) const requestsQuery = createQuery(true) - requestsQuery.query( - love.class.JoinRequest, - { person: (getCurrentAccount() as PersonAccount).person, status: RequestStatus.Pending }, - (res) => { - myRequests.set(res) - } + const requestPromise = new Promise((resolve) => + requestsQuery.query( + love.class.JoinRequest, + { person: (getCurrentAccount() as PersonAccount).person, status: RequestStatus.Pending }, + (res) => { + myRequests.set(res) + resolve() + } + ) ) const preferencesQuery = createQuery(true) - preferencesQuery.query(love.class.DevicesPreference, {}, (res) => { - myPreferences.set(res[0]) - $myPreferences = res[0] - }) + const preferencePromise = new Promise((resolve) => + preferencesQuery.query(love.class.DevicesPreference, {}, (res) => { + myPreferences.set(res[0]) + $myPreferences = res[0] + resolve() + }) + ) const invitesQuery = createQuery(true) - invitesQuery.query(love.class.Invite, { status: RequestStatus.Pending }, (res) => { - invites.set(res) - }) + const invitesPromise = new Promise((resolve) => + invitesQuery.query(love.class.Invite, { status: RequestStatus.Pending }, (res) => { + invites.set(res) + resolve() + }) + ) + storePromise.set( + new Promise((resolve) => { + void Promise.all([ + roomPromise, + infoPromise, + floorPromise, + requestPromise, + preferencePromise, + invitesPromise + ]).then(() => { + resolve() + }) + }) + ) } else { setTimeout(() => { fillStores() diff --git a/plugins/love-resources/src/utils.ts b/plugins/love-resources/src/utils.ts index 14ae6de8a6..2c3d7ff42f 100644 --- a/plugins/love-resources/src/utils.ts +++ b/plugins/love-resources/src/utils.ts @@ -1,5 +1,5 @@ import { Analytics } from '@hcengineering/analytics' -import calendar, { type Event } from '@hcengineering/calendar' +import calendar, { getAllEvents, type Event } from '@hcengineering/calendar' import contact, { getName, type Person, type PersonAccount } from '@hcengineering/contact' import core, { AccountRole, @@ -573,16 +573,21 @@ export async function connectToMeeting ( info: ParticipantInfo[], currentRequests: JoinRequest[], currentInvites: Invite[], - rooms: Room[], meetId: string ): Promise { const client = getClient() const meeting = await client.findOne(love.mixin.Meeting, { _id: meetId as Ref }) if (meeting === undefined) return - const room = rooms.find((p) => p._id === meeting.room) + const room = await client.findOne(love.class.Room, { _id: meeting.room }) if (room === undefined) return // check time (it should be 10 minutes before the meeting or active in roomInfo) + const now = new Date() + const res = getAllEvents([meeting], now.setMinutes(now.getMinutes() - 10), new Date().getTime()) + if (res.length === 0) { + console.log('Meeting is not active') + return + } await tryConnect( personByIdStore, @@ -775,6 +780,7 @@ export async function createMeeting ( const event = await client.findOne(calendar.class.Event, { _id }) if (event === undefined) return const navigateUrl = getCurrentLocation() + navigateUrl.path[2] = loveId navigateUrl.query = { meetId: _id }