mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 23:07:02 +08:00
feat: add publish workspace
This commit is contained in:
@@ -3,7 +3,7 @@ import { Workspace } from '@blocksuite/store';
|
||||
import { BaseProvider } from './provider/base';
|
||||
import { LocalProvider } from './provider/local/local';
|
||||
import { AffineProvider } from './provider';
|
||||
import { Workspace as WS, WorkspaceMeta } from 'src/types';
|
||||
import type { Workspace as WS, WorkspaceMeta } from 'src/types';
|
||||
import assert from 'assert';
|
||||
import { getLogger } from './logger';
|
||||
import { BlockSchema } from '@blocksuite/blocks/models';
|
||||
@@ -136,6 +136,7 @@ export class DataCenter {
|
||||
/**
|
||||
* get user info by provider id
|
||||
* @param {string} providerId the provider name of workspace
|
||||
* @returns {Promise<User>}
|
||||
*/
|
||||
public async getUserInfo(providerId = 'affine') {
|
||||
// XXX: maybe return all user info
|
||||
@@ -146,6 +147,7 @@ export class DataCenter {
|
||||
|
||||
/**
|
||||
* listen workspaces list change
|
||||
* @param {Function} callback callback function
|
||||
*/
|
||||
public async onWorkspacesChange(callback: (workspaces: WS[]) => void) {
|
||||
this.workspaces.onWorkspacesChange(callback);
|
||||
@@ -171,7 +173,7 @@ export class DataCenter {
|
||||
w.doc.meta.setAvatar(avatar);
|
||||
update.avatar = avatar;
|
||||
}
|
||||
this.workspaces.updateWorkspaceMeta(w.room, update);
|
||||
this.workspaces.updateWorkspaceInfo(w.room, update);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,13 +186,19 @@ export class DataCenter {
|
||||
assert(workspaceInfo, 'Workspace not found');
|
||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||
if (provider) {
|
||||
provider.close(workspaceId);
|
||||
provider.leave(workspaceId);
|
||||
await provider.close(workspaceId);
|
||||
await provider.leave(workspaceId);
|
||||
}
|
||||
}
|
||||
|
||||
public async setWorkspacePublish() {
|
||||
// TODO: set workspace publish
|
||||
public async setWorkspacePublish(workspaceId: string, isPublish: boolean) {
|
||||
const workspaceInfo = this.workspaces.getWorkspace(workspaceId);
|
||||
assert(workspaceInfo, 'Workspace not found');
|
||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||
if (provider) {
|
||||
await provider.publish(workspaceId, isPublish);
|
||||
this.workspaces.updateWorkspaceInfo(workspaceId, { isPublish });
|
||||
}
|
||||
}
|
||||
|
||||
public async inviteMember(id: string, email: string) {
|
||||
@@ -198,7 +206,7 @@ export class DataCenter {
|
||||
assert(workspaceInfo, 'Workspace not found');
|
||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||
if (provider) {
|
||||
provider.invite(id, email);
|
||||
await provider.invite(id, email);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +219,7 @@ export class DataCenter {
|
||||
assert(workspaceInfo, 'Workspace not found');
|
||||
const provider = this.providerMap.get(workspaceInfo.provider);
|
||||
if (provider) {
|
||||
provider.removeMember(permissionId);
|
||||
await provider.removeMember(permissionId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,7 +235,7 @@ export class DataCenter {
|
||||
assert(currentWorkspace, 'Workspace not found');
|
||||
const provider = this.providerMap.get(currentWorkspace.provider);
|
||||
assert(provider, 'Provider not found');
|
||||
provider.close(currentWorkspace.id);
|
||||
await provider.close(currentWorkspace.id);
|
||||
}
|
||||
|
||||
private async _transWorkspaceProvider(
|
||||
@@ -261,7 +269,7 @@ export class DataCenter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable workspace cloud flag
|
||||
* Enable workspace cloud
|
||||
* @param {string} id ID of workspace.
|
||||
*/
|
||||
public async enableWorkspaceCloud(
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
inviteMember,
|
||||
removeMember,
|
||||
createWorkspace,
|
||||
updateWorkspace,
|
||||
} from './apis/workspace';
|
||||
import { BaseProvider } from '../base';
|
||||
import { User, Workspace as WS, WorkspaceMeta } from '../../types';
|
||||
@@ -235,4 +236,8 @@ export class AffineProvider extends BaseProvider {
|
||||
this._logger('Local data loaded');
|
||||
return nw;
|
||||
}
|
||||
|
||||
public override async publish(id: string, isPublish: boolean): Promise<void> {
|
||||
await updateWorkspace({ id, public: isPublish });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,12 @@ export class BaseProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
public async publish(id: string, isPublish: boolean): Promise<void> {
|
||||
id;
|
||||
isPublish;
|
||||
return;
|
||||
}
|
||||
|
||||
public async createWorkspace(
|
||||
meta: WorkspaceMeta
|
||||
): Promise<Workspace | undefined> {
|
||||
|
||||
@@ -91,10 +91,10 @@ export class Workspaces extends Observable<string> {
|
||||
return this._workspaces.some(w => w.id === id);
|
||||
}
|
||||
|
||||
public updateWorkspaceMeta(id: string, meta: Partial<WS>) {
|
||||
public updateWorkspaceInfo(id: string, info: Partial<WS>) {
|
||||
const index = this._workspaces.findIndex(w => w.id === id);
|
||||
if (index >= 0) {
|
||||
this._workspaces[index] = { ...this._workspaces[index], ...meta };
|
||||
this._workspaces[index] = { ...this._workspaces[index], ...info };
|
||||
this._updateWorkspaces(this._workspaces);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user