From 48264edf9184bd409b443d6014a6a2c2dab0e3d1 Mon Sep 17 00:00:00 2001 From: MingLiang Wang Date: Wed, 11 Jan 2023 12:34:57 +0800 Subject: [PATCH] feat: add query members --- packages/data-center/src/datacenter.ts | 14 ++++++++++++++ packages/data-center/src/provider/affine/affine.ts | 6 +++++- packages/data-center/src/provider/base.ts | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/data-center/src/datacenter.ts b/packages/data-center/src/datacenter.ts index 76499b11e5..1221b114f3 100644 --- a/packages/data-center/src/datacenter.ts +++ b/packages/data-center/src/datacenter.ts @@ -384,6 +384,20 @@ export class DataCenter { return (await blobStorage?.set(blob)) || ''; } + /** + * get members of a workspace + * @param workspaceId + */ + async getMembers(workspaceId: string) { + const workspaceInfo = this._workspaceUnitCollection.find(workspaceId); + assert(workspaceInfo, 'Workspace not found'); + const provider = this.providerMap.get(workspaceInfo.provider); + if (provider) { + return await provider.getWorkspaceMembers(workspaceId); + } + return []; + } + onMessage(cb: (message: Message) => void) { return this._messageCenter.onMessage(cb); } diff --git a/packages/data-center/src/provider/affine/affine.ts b/packages/data-center/src/provider/affine/affine.ts index 0480a60a1b..0794ca10e9 100644 --- a/packages/data-center/src/provider/affine/affine.ts +++ b/packages/data-center/src/provider/affine/affine.ts @@ -12,7 +12,7 @@ import { storage } from './storage.js'; import assert from 'assert'; import { WebsocketProvider } from './sync.js'; // import { IndexedDBProvider } from '../local/indexeddb'; -import { getApis } from './apis/index.js'; +import { getApis, Member } from './apis/index.js'; import type { Apis, WorkspaceDetail, Callback } from './apis'; import { setDefaultAvatar } from '../utils.js'; import { MessageCode } from '../../message'; @@ -365,4 +365,8 @@ export class AffineProvider extends BaseProvider { token.clear(); storage.removeItem('token'); } + + public override async getWorkspaceMembers(id: string) { + return this._apis.getWorkspaceMembers({ id }); + } } diff --git a/packages/data-center/src/provider/base.ts b/packages/data-center/src/provider/base.ts index 6542b279f1..17834abf34 100644 --- a/packages/data-center/src/provider/base.ts +++ b/packages/data-center/src/provider/base.ts @@ -3,6 +3,7 @@ import { MessageCenter } from '../message'; import { Logger, User } from '../types'; import type { WorkspaceUnitCollectionScope } from '../workspace-unit-collection'; import type { WorkspaceUnitCtorParams } from '../workspace-unit'; +import { Member } from './affine/apis'; const defaultLogger = () => { return; @@ -213,4 +214,14 @@ export class BaseProvider { from; return to; } + + /** + * get workspace members + * @param {string} workspaceId + * @returns + */ + public getWorkspaceMembers(workspaceId: string): Promise { + workspaceId; + return Promise.resolve([]); + } }