Validate meeting time (#6212)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2024-08-01 15:20:41 +05:00 committed by GitHub
parent 52df4cc869
commit e1249789dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 75 additions and 31 deletions

View File

@ -16,11 +16,11 @@
import { Contact, Person } from '@hcengineering/contact' import { Contact, Person } from '@hcengineering/contact'
import { personByIdStore } from '@hcengineering/contact-resources' import { personByIdStore } from '@hcengineering/contact-resources'
import { Ref } from '@hcengineering/core' 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 { getClient } from '@hcengineering/presentation'
import { deviceOptionsStore as deviceInfo, getCurrentLocation, navigate } from '@hcengineering/ui' import { deviceOptionsStore as deviceInfo, getCurrentLocation, navigate } from '@hcengineering/ui'
import { onMount, onDestroy } from 'svelte' import { onDestroy, onMount } from 'svelte'
import { activeFloor, floors, infos, invites, myInfo, myRequests, rooms } from '../stores' import { activeFloor, floors, infos, invites, myInfo, myRequests, rooms, storePromise } from '../stores'
import { connectToMeeting, tryConnect } from '../utils' import { connectToMeeting, tryConnect } from '../utils'
import Floor from './Floor.svelte' import Floor from './Floor.svelte'
import FloorConfigure from './FloorConfigure.svelte' import FloorConfigure from './FloorConfigure.svelte'
@ -64,9 +64,11 @@
loc.query = Object.keys(query).length === 0 ? undefined : query loc.query = Object.keys(query).length === 0 ? undefined : query
navigate(loc, true) navigate(loc, true)
if (sessionId != null) { if (sessionId != null) {
await $storePromise
await connectToSession(sessionId) await connectToSession(sessionId)
} else if (meetId != null) { } else if (meetId != null) {
await connectToMeeting($personByIdStore, $myInfo, $infos, $myRequests, $invites, $rooms, meetId) await $storePromise
await connectToMeeting($personByIdStore, $myInfo, $infos, $myRequests, $invites, meetId)
} }
}) })
</script> </script>

View File

@ -31,7 +31,7 @@
} from 'livekit-client' } from 'livekit-client'
import { onDestroy, onMount, tick } from 'svelte' import { onDestroy, onMount, tick } from 'svelte'
import love from '../plugin' import love from '../plugin'
import { currentRoom, infos, invites, myInfo, myRequests } from '../stores' import { storePromise, currentRoom, infos, invites, myInfo, myRequests } from '../stores'
import { import {
awaitConnect, awaitConnect,
isConnected, isConnected,
@ -221,6 +221,8 @@
configured = true configured = true
await $storePromise
if (!$isConnected && !$isCurrentInstanceConnected) { if (!$isConnected && !$isCurrentInstanceConnected) {
const info = $infos.filter((p) => p.room === room._id) const info = $infos.filter((p) => p.room === room._id)
await tryConnect($personByIdStore, $myInfo, room, info, $myRequests, $invites) await tryConnect($personByIdStore, $myInfo, room, info, $myRequests, $invites)

View File

@ -26,7 +26,7 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: items = $rooms $: items = $rooms
.filter((p) => !isOffice(p)) .filter((p) => !isOffice(p) && p._id !== love.ids.Reception)
.map((p) => { .map((p) => {
return { return {
_id: p._id, _id: p._id,

View File

@ -64,38 +64,72 @@ function filterParticipantInfo (value: ParticipantInfo[]): ParticipantInfo[] {
return Array.from(map.values()) return Array.from(map.values())
} }
export const storePromise = writable<Promise<void>>(new Promise((resolve) => {}))
function fillStores (): void { function fillStores (): void {
const client = getClient() const client = getClient()
if (client !== undefined) { if (client !== undefined) {
const query = createQuery(true) const query = createQuery(true)
query.query(love.class.Room, {}, (res) => { const roomPromise = new Promise<void>((resolve) =>
rooms.set(res) query.query(love.class.Room, {}, (res) => {
}) rooms.set(res)
resolve()
})
)
const statusQuery = createQuery(true) const statusQuery = createQuery(true)
statusQuery.query(love.class.ParticipantInfo, {}, (res) => { const infoPromise = new Promise<void>((resolve) =>
infos.set(filterParticipantInfo(res)) statusQuery.query(love.class.ParticipantInfo, {}, (res) => {
}) infos.set(filterParticipantInfo(res))
resolve()
})
)
const floorsQuery = createQuery(true) const floorsQuery = createQuery(true)
floorsQuery.query(love.class.Floor, {}, (res) => { const floorPromise = new Promise<void>((resolve) =>
floors.set(res) floorsQuery.query(love.class.Floor, {}, (res) => {
}) floors.set(res)
resolve()
})
)
const requestsQuery = createQuery(true) const requestsQuery = createQuery(true)
requestsQuery.query( const requestPromise = new Promise<void>((resolve) =>
love.class.JoinRequest, requestsQuery.query(
{ person: (getCurrentAccount() as PersonAccount).person, status: RequestStatus.Pending }, love.class.JoinRequest,
(res) => { { person: (getCurrentAccount() as PersonAccount).person, status: RequestStatus.Pending },
myRequests.set(res) (res) => {
} myRequests.set(res)
resolve()
}
)
) )
const preferencesQuery = createQuery(true) const preferencesQuery = createQuery(true)
preferencesQuery.query(love.class.DevicesPreference, {}, (res) => { const preferencePromise = new Promise<void>((resolve) =>
myPreferences.set(res[0]) preferencesQuery.query(love.class.DevicesPreference, {}, (res) => {
$myPreferences = res[0] myPreferences.set(res[0])
}) $myPreferences = res[0]
resolve()
})
)
const invitesQuery = createQuery(true) const invitesQuery = createQuery(true)
invitesQuery.query(love.class.Invite, { status: RequestStatus.Pending }, (res) => { const invitesPromise = new Promise<void>((resolve) =>
invites.set(res) 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 { } else {
setTimeout(() => { setTimeout(() => {
fillStores() fillStores()

View File

@ -1,5 +1,5 @@
import { Analytics } from '@hcengineering/analytics' 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 contact, { getName, type Person, type PersonAccount } from '@hcengineering/contact'
import core, { import core, {
AccountRole, AccountRole,
@ -573,16 +573,21 @@ export async function connectToMeeting (
info: ParticipantInfo[], info: ParticipantInfo[],
currentRequests: JoinRequest[], currentRequests: JoinRequest[],
currentInvites: Invite[], currentInvites: Invite[],
rooms: Room[],
meetId: string meetId: string
): Promise<void> { ): Promise<void> {
const client = getClient() const client = getClient()
const meeting = await client.findOne(love.mixin.Meeting, { _id: meetId as Ref<Meeting> }) const meeting = await client.findOne(love.mixin.Meeting, { _id: meetId as Ref<Meeting> })
if (meeting === undefined) return 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 if (room === undefined) return
// check time (it should be 10 minutes before the meeting or active in roomInfo) // 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( await tryConnect(
personByIdStore, personByIdStore,
@ -775,6 +780,7 @@ export async function createMeeting (
const event = await client.findOne(calendar.class.Event, { _id }) const event = await client.findOne(calendar.class.Event, { _id })
if (event === undefined) return if (event === undefined) return
const navigateUrl = getCurrentLocation() const navigateUrl = getCurrentLocation()
navigateUrl.path[2] = loveId
navigateUrl.query = { navigateUrl.query = {
meetId: _id meetId: _id
} }