fix: client not saving avatar blob on first creating workspace (#974)

This commit is contained in:
lin onetwo 2023-02-14 15:47:10 +08:00 committed by GitHub
parent b69eb3437b
commit 79506f1ce2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -10,10 +10,11 @@ import {
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store'; import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
import { IPCBlobProvider } from './blocksuite-provider/blob.js'; import { IPCBlobProvider } from './blocksuite-provider/blob.js';
import type { WorkspaceUnit } from 'src/workspace-unit.js'; import type { WorkspaceUnit } from 'src/workspace-unit.js';
import { createWorkspaceUnit, loadWorkspaceUnit } from '../local/utils.js'; import { loadWorkspaceUnit } from '../local/utils.js';
import { WorkspaceWithPermission } from './ipc/types/workspace.js'; import { WorkspaceWithPermission } from './ipc/types/workspace.js';
import { applyUpdate } from '../../utils/index.js'; import { applyUpdate } from '../../utils/index.js';
import { User } from 'src/types/index.js'; import { User } from 'src/types/index.js';
import { createWorkspaceUnit } from './utils.js';
/** /**
* init - createUser - create first workspace and ydoc - loadWorkspace - return the first workspace - wrapWorkspace - #initDocFromIPC - applyUpdate - on('update') - updateYDocument * init - createUser - create first workspace and ydoc - loadWorkspace - return the first workspace - wrapWorkspace - #initDocFromIPC - applyUpdate - on('update') - updateYDocument

View File

@ -0,0 +1,25 @@
import { WorkspaceUnit } from '../../workspace-unit.js';
import type { WorkspaceUnitCtorParams } from '../../workspace-unit';
import { createBlocksuiteWorkspace } from '../../utils/index.js';
import { setDefaultAvatar } from '../utils.js';
import { IPCBlobProvider } from './blocksuite-provider/blob.js';
export const createWorkspaceUnit = async (params: WorkspaceUnitCtorParams) => {
const workspaceUnit = new WorkspaceUnit(params);
const blocksuiteWorkspace = createBlocksuiteWorkspace(workspaceUnit.id, {
blobOptionsGetter: (k: string) => undefined,
});
blocksuiteWorkspace.meta.setName(workspaceUnit.name);
(await blocksuiteWorkspace.blobs)?.setProvider(
await IPCBlobProvider.init(workspaceUnit.id)
);
if (!workspaceUnit.avatar) {
await setDefaultAvatar(blocksuiteWorkspace);
workspaceUnit.update({ avatar: blocksuiteWorkspace.meta.avatar });
}
workspaceUnit.setBlocksuiteWorkspace(blocksuiteWorkspace);
return workspaceUnit;
};