mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-02 13:52:40 +00:00
Fix love join (#6209)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
c55e6f00b0
commit
e1e6d6427e
@ -31,7 +31,6 @@ import love, {
|
|||||||
ParticipantInfo,
|
ParticipantInfo,
|
||||||
RequestStatus,
|
RequestStatus,
|
||||||
RoomAccess,
|
RoomAccess,
|
||||||
RoomInfo,
|
|
||||||
isOffice,
|
isOffice,
|
||||||
loveId
|
loveId
|
||||||
} from '@hcengineering/love'
|
} from '@hcengineering/love'
|
||||||
@ -149,7 +148,8 @@ export async function OnUserStatus (tx: Tx, control: TriggerControl): Promise<Tx
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
async function roomJoinHandler (info: ParticipantInfo, control: TriggerControl, roomInfos: RoomInfo[]): Promise<Tx[]> {
|
async function roomJoinHandler (info: ParticipantInfo, control: TriggerControl): Promise<Tx[]> {
|
||||||
|
const roomInfos = await control.queryFind(love.class.RoomInfo, {})
|
||||||
const roomInfo = roomInfos.find((ri) => ri.room === info.room)
|
const roomInfo = roomInfos.find((ri) => ri.room === info.room)
|
||||||
if (roomInfo !== undefined) {
|
if (roomInfo !== undefined) {
|
||||||
roomInfo.persons.push(info.person)
|
roomInfo.persons.push(info.person)
|
||||||
@ -171,12 +171,9 @@ async function roomJoinHandler (info: ParticipantInfo, control: TriggerControl,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rejectJoinRequests (
|
async function rejectJoinRequests (info: ParticipantInfo, control: TriggerControl): Promise<Tx[]> {
|
||||||
info: ParticipantInfo,
|
|
||||||
control: TriggerControl,
|
|
||||||
roomInfos: RoomInfo[]
|
|
||||||
): Promise<Tx[]> {
|
|
||||||
const res: Tx[] = []
|
const res: Tx[] = []
|
||||||
|
const roomInfos = await control.queryFind(love.class.RoomInfo, {})
|
||||||
const oldRoomInfo = roomInfos.find((ri) => ri.persons.includes(info.person))
|
const oldRoomInfo = roomInfos.find((ri) => ri.persons.includes(info.person))
|
||||||
if (oldRoomInfo !== undefined) {
|
if (oldRoomInfo !== undefined) {
|
||||||
const restPersons = oldRoomInfo.persons.filter((p) => p !== info.person)
|
const restPersons = oldRoomInfo.persons.filter((p) => p !== info.person)
|
||||||
@ -197,21 +194,15 @@ async function rejectJoinRequests (
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
function setDefaultRoomAccess (info: ParticipantInfo, roomInfos: RoomInfo[], control: TriggerControl): Tx[] {
|
async function setDefaultRoomAccess (info: ParticipantInfo, control: TriggerControl): Promise<Tx[]> {
|
||||||
const res: Tx[] = []
|
const res: Tx[] = []
|
||||||
|
const roomInfos = await control.queryFind(love.class.RoomInfo, {})
|
||||||
const oldRoomInfo = roomInfos.find((ri) => ri.persons.includes(info.person))
|
const oldRoomInfo = roomInfos.find((ri) => ri.persons.includes(info.person))
|
||||||
if (oldRoomInfo !== undefined) {
|
if (oldRoomInfo !== undefined) {
|
||||||
oldRoomInfo.persons = oldRoomInfo.persons.filter((p) => p !== info.person)
|
oldRoomInfo.persons = oldRoomInfo.persons.filter((p) => p !== info.person)
|
||||||
if (oldRoomInfo.persons.length === 0) {
|
if (oldRoomInfo.persons.length === 0) {
|
||||||
res.push(control.txFactory.createTxRemoveDoc(oldRoomInfo._class, oldRoomInfo.space, oldRoomInfo._id))
|
res.push(control.txFactory.createTxRemoveDoc(oldRoomInfo._class, oldRoomInfo.space, oldRoomInfo._id))
|
||||||
} else {
|
|
||||||
res.push(
|
|
||||||
control.txFactory.createTxUpdateDoc(love.class.RoomInfo, core.space.Workspace, oldRoomInfo._id, {
|
|
||||||
persons: oldRoomInfo.persons
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (oldRoomInfo.persons.length === 0) {
|
|
||||||
const resetAccessTx = control.txFactory.createTxUpdateDoc(
|
const resetAccessTx = control.txFactory.createTxUpdateDoc(
|
||||||
oldRoomInfo.isOffice ? love.class.Office : love.class.Room,
|
oldRoomInfo.isOffice ? love.class.Office : love.class.Room,
|
||||||
core.space.Workspace,
|
core.space.Workspace,
|
||||||
@ -221,22 +212,27 @@ function setDefaultRoomAccess (info: ParticipantInfo, roomInfos: RoomInfo[], con
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
res.push(resetAccessTx)
|
res.push(resetAccessTx)
|
||||||
|
} else {
|
||||||
|
res.push(
|
||||||
|
control.txFactory.createTxUpdateDoc(love.class.RoomInfo, core.space.Workspace, oldRoomInfo._id, {
|
||||||
|
persons: oldRoomInfo.persons
|
||||||
|
})
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function OnParticipantInfo (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
export async function OnParticipantInfo (tx: Tx, control: TriggerControl): Promise<Tx[]> {
|
||||||
const roomInfos = await control.queryFind(love.class.RoomInfo, {})
|
|
||||||
const actualTx = TxProcessor.extractTx(tx) as TxCUD<ParticipantInfo>
|
const actualTx = TxProcessor.extractTx(tx) as TxCUD<ParticipantInfo>
|
||||||
if (actualTx._class === core.class.TxCreateDoc) {
|
if (actualTx._class === core.class.TxCreateDoc) {
|
||||||
const info = TxProcessor.createDoc2Doc(actualTx as TxCreateDoc<ParticipantInfo>)
|
const info = TxProcessor.createDoc2Doc(actualTx as TxCreateDoc<ParticipantInfo>)
|
||||||
return await roomJoinHandler(info, control, roomInfos)
|
return await roomJoinHandler(info, control)
|
||||||
}
|
}
|
||||||
if (actualTx._class === core.class.TxRemoveDoc) {
|
if (actualTx._class === core.class.TxRemoveDoc) {
|
||||||
const removedInfo = control.removedMap.get(actualTx.objectId) as ParticipantInfo
|
const removedInfo = control.removedMap.get(actualTx.objectId) as ParticipantInfo
|
||||||
if (removedInfo === undefined) return []
|
if (removedInfo === undefined) return []
|
||||||
return setDefaultRoomAccess(removedInfo, roomInfos, control)
|
return await setDefaultRoomAccess(removedInfo, control)
|
||||||
}
|
}
|
||||||
if (actualTx._class === core.class.TxUpdateDoc) {
|
if (actualTx._class === core.class.TxUpdateDoc) {
|
||||||
const newRoom = (actualTx as TxUpdateDoc<ParticipantInfo>).operations.room
|
const newRoom = (actualTx as TxUpdateDoc<ParticipantInfo>).operations.room
|
||||||
@ -244,9 +240,9 @@ export async function OnParticipantInfo (tx: Tx, control: TriggerControl): Promi
|
|||||||
const info = (await control.findAll(love.class.ParticipantInfo, { _id: actualTx.objectId }, { limit: 1 }))[0]
|
const info = (await control.findAll(love.class.ParticipantInfo, { _id: actualTx.objectId }, { limit: 1 }))[0]
|
||||||
if (info === undefined) return []
|
if (info === undefined) return []
|
||||||
const res: Tx[] = []
|
const res: Tx[] = []
|
||||||
res.push(...(await rejectJoinRequests(info, control, roomInfos)))
|
res.push(...(await rejectJoinRequests(info, control)))
|
||||||
res.push(...setDefaultRoomAccess(info, roomInfos, control))
|
res.push(...(await setDefaultRoomAccess(info, control)))
|
||||||
res.push(...(await roomJoinHandler(info, control, roomInfos)))
|
res.push(...(await roomJoinHandler(info, control)))
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
|
Loading…
Reference in New Issue
Block a user