Implement @everyone/@here (#8890)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina
2025-05-12 14:42:58 +07:00
committed by GitHub
parent 137260fe5b
commit 3295adee57
47 changed files with 675 additions and 351 deletions
+1
View File
@@ -37,3 +37,4 @@ export * from './txPush'
export * from './queue'
export * from './identity'
export * from './pluginConfig'
export * from './userStatus'
+1
View File
@@ -139,6 +139,7 @@ export class TriggersMiddleware extends BaseMiddleware implements Middleware {
hierarchy: this.context.hierarchy,
cache: this.cache,
communicationApi: this.context.communicationApi,
userStatusMap: this.context.userStatusMap ?? new Map(),
apply: async (ctx, tx, needResult) => {
if (needResult === true) {
return (await this.context.derived?.tx(ctx, tx)) ?? {}
+79
View File
@@ -0,0 +1,79 @@
//
// Copyright © 2025 Hardcore Engineering Inc.
//
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//
// See the License for the specific language governing permissions and
// limitations under the License.
//
import core, {
MeasureContext,
Tx,
type SessionData,
type TxApplyIf,
TxCUD,
Doc,
TxProcessor,
UserStatus,
TxCreateDoc,
TxUpdateDoc,
Ref
} from '@hcengineering/core'
import { BaseMiddleware, Middleware, TxMiddlewareResult, type PipelineContext } from '@hcengineering/server-core'
/**
* @public
*/
export class UserStatusMiddleware extends BaseMiddleware implements Middleware {
private constructor (context: PipelineContext, next?: Middleware) {
super(context, next)
}
static async create (
_: MeasureContext,
context: PipelineContext,
next: Middleware | undefined
): Promise<UserStatusMiddleware> {
return new UserStatusMiddleware(context, next)
}
tx (ctx: MeasureContext<SessionData>, txes: Tx[]): Promise<TxMiddlewareResult> {
for (const tx of txes) {
if (tx._class === core.class.TxApplyIf) {
const atx = tx as TxApplyIf
atx.txes.forEach((it) => {
this.processTx(it)
})
} else {
this.processTx(tx as TxCUD<Doc>)
}
}
return this.provideTx(ctx, txes)
}
private processTx (tx: TxCUD<Doc>): void {
if (tx._class === core.class.TxCreateDoc && tx.objectClass === core.class.UserStatus) {
const status = TxProcessor.createDoc2Doc(tx as TxCreateDoc<UserStatus>)
const map = this.context.userStatusMap ?? new Map()
map.set(status._id, { online: status.online, user: status.user })
this.context.userStatusMap = map
} else if (tx._class === core.class.TxUpdateDoc && tx.objectClass === core.class.UserStatus) {
const uTx = tx as TxUpdateDoc<UserStatus>
if ('online' in uTx.operations) {
const current = this.context.userStatusMap?.get(uTx.objectId)
const online = uTx.operations.online
if (current !== undefined && online !== undefined) {
this.context.userStatusMap?.set(uTx.objectId, { online, user: current.user })
}
}
} else if (tx._class === core.class.TxRemoveDoc && tx.objectClass === core.class.UserStatus) {
this.context.userStatusMap?.delete(tx.objectId as Ref<UserStatus>)
}
}
}