fix: merge issue

This commit is contained in:
linonetwo 2023-01-12 17:22:13 +08:00
parent 1a82fdb8b3
commit 1b3bdda061
4 changed files with 54 additions and 194 deletions

View File

@ -28,6 +28,7 @@
"dependencies": {
"@blocksuite/blocks": "0.3.1-20230109032243-37ad3ba",
"@blocksuite/store": "0.3.1-20230109032243-37ad3ba",
"@tauri-apps/api": "^1.2.0",
"debug": "^4.3.4",
"encoding": "^0.1.13",
"firebase": "^9.15.0",
@ -36,7 +37,8 @@
"ky-universal": "^0.11.0",
"lib0": "^0.2.58",
"swr": "^2.0.0",
"y-protocols": "^1.0.5"
"y-protocols": "^1.0.5",
"yjs": "^13.5.44"
},
"peerDependencies": {
"@blocksuite/blocks": "0.3.1-*",

View File

@ -6,17 +6,15 @@ import * as ipcMethods from './ipc/methods.js';
import {
CreateWorkspaceInfoParams,
ProviderConstructorParams,
WorkspaceMeta0,
} from '../base.js';
import { BlockSchema } from '@blocksuite/blocks/models';
import { Workspace as BlocksuiteWorkspace } from '@blocksuite/store';
import { IPCBlobProvider } from './blocksuite-provider/blob.js';
import type { WorkspaceDetail } from '../affine/apis/workspace.js';
import { setDefaultAvatar } from '../utils.js';
import { WorkspaceUnit } from 'src/workspace-unit.js';
import { createWorkspaceUnit, loadWorkspaceUnit } from '../local/utils.js';
import { WorkspaceWithPermission } from './ipc/types/workspace.js';
export class TauriIPCProvider extends LocalProvider {
static id = 'tauri-ipc';
private _workspacesCache: Map<string, BlocksuiteWorkspace> = new Map();
/**
* // TODO: We only have one user in this version of app client. But may support switch user later.
*/
@ -78,27 +76,6 @@ export class TauriIPCProvider extends LocalProvider {
await super.clear();
}
public override async createWorkspaceInfo(
meta: CreateWorkspaceInfoParams
): Promise<WorkspaceMeta0> {
const { id } = await ipcMethods.createWorkspace({
name: meta.name,
// TODO: get userID here
user_id: this.#defaultUserID,
});
const workspaceInfo: WorkspaceMeta0 = {
name: meta.name,
id: id,
avatar: '',
owner: await this.getUserInfo(),
memberCount: 1,
provider: this.id,
syncMode: 'all',
};
return workspaceInfo;
}
override async warpWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace) {
const { doc, room } = blocksuiteWorkspace;
assert(room);
@ -111,131 +88,47 @@ export class TauriIPCProvider extends LocalProvider {
}
public override async createWorkspace(
blocksuiteWorkspace: BlocksuiteWorkspace,
meta: WorkspaceMeta0
): Promise<BlocksuiteWorkspace | undefined> {
const workspaceId = blocksuiteWorkspace.room;
assert(workspaceId, 'Blocksuite Workspace without room(workspaceId).');
this._logger('Creating affine workspace');
meta: CreateWorkspaceInfoParams
): Promise<WorkspaceUnit | undefined> {
this._logger('Creating client app workspace');
const workspaceInfo: WorkspaceMeta0 = {
const { id } = await ipcMethods.createWorkspace({
name: meta.name,
id: workspaceId,
avatar: '',
owner: undefined,
memberCount: 1,
provider: this.id,
syncMode: 'all',
};
if (!blocksuiteWorkspace.meta.avatar) {
await setDefaultAvatar(blocksuiteWorkspace);
workspaceInfo.avatar = blocksuiteWorkspace.meta.avatar;
}
this._workspaces.add(workspaceInfo);
return blocksuiteWorkspace;
}
override async loadWorkspaces() {
const { workspaces: workspacesList } = await ipcMethods.getWorkspaces({
// TODO: get userID here
user_id: this.#defaultUserID,
});
const workspaces: WorkspaceMeta0[] = workspacesList.map(w => {
return {
...w,
memberCount: 0,
name: '',
provider: this.id,
syncMode: 'all',
};
const workspaceUnit = await createWorkspaceUnit({
name: meta.name,
id,
published: false,
avatar: '',
owner: undefined,
syncMode: 'core',
memberCount: 1,
provider: this.id,
});
const workspaceInstances = workspaces.map(({ id, name, avatar }) => {
const workspace =
this._workspacesCache.get(id) ||
new BlocksuiteWorkspace({
room: id,
}).register(BlockSchema);
this._workspacesCache.set(id, workspace);
if (workspace) {
workspace.meta.setName(name);
if (avatar) {
workspace.meta.setAvatar(avatar);
}
return new Promise<BlocksuiteWorkspace>(resolve => {
ipcMethods.getYDocument({ id }).then(({ update }) => {
Y.applyUpdate(workspace.doc, new Uint8Array(update));
resolve(workspace);
});
this._workspaces.add(workspaceUnit);
return workspaceUnit;
}
override async loadWorkspaces(): Promise<WorkspaceUnit[]> {
const { workspaces } = await ipcMethods.getWorkspaces({
user_id: this.#defaultUserID,
});
const workspaceUnits = await Promise.all(
workspaces.map((meta: WorkspaceWithPermission) => {
return loadWorkspaceUnit({
...meta,
memberCount: 1,
// TODO: load name here
name: '',
provider: this.id,
syncMode: 'all',
});
} else {
return Promise.resolve(null);
}
});
(await Promise.all(workspaceInstances)).forEach((workspace, i) => {
if (workspace) {
workspaces[i] = {
...workspaces[i],
name: workspace.meta.name,
avatar: workspace.meta.avatar,
};
}
});
const getDetailList = workspacesList.map(
async (
workspaceWithPermission
): Promise<{
id: string;
detail:
| (Omit<WorkspaceDetail, 'owner'> & {
owner?: Partial<WorkspaceDetail['owner']>;
})
| null;
}> => {
const { id, permission, created_at } = workspaceWithPermission;
const { workspace } = await ipcMethods.getWorkspace({ id });
return {
id,
detail: {
...workspace,
owner: workspace.owner
? {
...workspace.owner,
create_at: String(created_at),
avatar_url: workspace.owner.avatar_url ?? undefined,
id: String(workspace.owner.id),
}
: undefined,
permission_type: permission,
create_at: created_at,
},
};
}
})
);
const ownerList = await Promise.all(getDetailList);
(await Promise.all(ownerList)).forEach(detail => {
if (detail) {
const { id, detail: workspaceDetail } = detail;
if (workspaceDetail) {
const { owner, member_count } = workspaceDetail;
const currentWorkspace = workspaces.find(w => w.id === id);
if (currentWorkspace && owner) {
currentWorkspace.owner = {
id: owner.id!,
name: owner.name!,
avatar: owner.avatar_url!,
email: owner.email!,
};
currentWorkspace.memberCount = member_count;
}
}
}
});
workspaces.forEach(workspace => {
this._workspaces.add(workspace);
});
return workspaces;
this._workspaces.add(workspaceUnits);
return workspaceUnits;
}
}

View File

@ -11,6 +11,13 @@ import { getLogger } from '../logger';
// provider: string;
// };
declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/ban-types
__TAURI_IPC__: Function;
}
}
export type User = {
name: string;
id: string;

View File

@ -235,6 +235,7 @@ importers:
'@blocksuite/blocks': 0.3.1-20230109032243-37ad3ba
'@blocksuite/store': 0.3.1-20230109032243-37ad3ba
'@playwright/test': ^1.29.1
'@tauri-apps/api': ^1.2.0
'@types/debug': ^4.1.7
debug: ^4.3.4
encoding: ^0.1.13
@ -247,9 +248,11 @@ importers:
swr: ^2.0.0
typescript: ^4.8.4
y-protocols: ^1.0.5
yjs: ^13.5.44
dependencies:
'@blocksuite/blocks': 0.3.1-20230109032243-37ad3ba
'@blocksuite/store': 0.3.1-20230109032243-37ad3ba
'@blocksuite/blocks': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44
'@blocksuite/store': 0.3.1-20230109032243-37ad3ba_yjs@13.5.44
'@tauri-apps/api': 1.2.0
debug: 4.3.4
encoding: 0.1.13
firebase: 9.15.0_encoding@0.1.13
@ -259,6 +262,7 @@ importers:
lib0: 0.2.58
swr: 2.0.0
y-protocols: 1.0.5
yjs: 13.5.44
devDependencies:
'@playwright/test': 1.29.1
'@types/debug': 4.1.7
@ -1611,26 +1615,6 @@ packages:
resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==}
dev: true
/@blocksuite/blocks/0.3.1-20230109032243-37ad3ba:
resolution: {integrity: sha512-UTlbk0Is7TMRBbvUyM2nivbqM/TLwRj1qArMYbOmvDGUNYadWo68cTwv/Ej2WwiKn22q4/4JHryGsv3gTCRz1Q==}
dependencies:
'@blocksuite/phasor': 0.3.1-20230109032243-37ad3ba
'@blocksuite/store': 0.3.1-20230109032243-37ad3ba
'@tldraw/intersect': 1.8.0
autosize: 5.0.2
highlight.js: 11.7.0
hotkeys-js: 3.10.1
lit: 2.5.0
perfect-freehand: 1.2.0
quill: 1.3.7
quill-cursors: 4.0.0
transitivePeerDependencies:
- bufferutil
- supports-color
- utf-8-validate
- yjs
dev: false
/@blocksuite/blocks/0.3.1-20230109032243-37ad3ba_yjs@13.5.44:
resolution: {integrity: sha512-UTlbk0Is7TMRBbvUyM2nivbqM/TLwRj1qArMYbOmvDGUNYadWo68cTwv/Ej2WwiKn22q4/4JHryGsv3gTCRz1Q==}
dependencies:
@ -1676,12 +1660,6 @@ packages:
react: 18.2.0
dev: false
/@blocksuite/phasor/0.3.1-20230109032243-37ad3ba:
resolution: {integrity: sha512-mL1gSQ3rzrjdQSbWPtgyMXpbbl266UUjw26d0aIjkOh+iMMI6rWtmKWDoiDkO7tejIjwSNQ4w5zJOjJRIj+mSA==}
peerDependencies:
yjs: ^13
dev: false
/@blocksuite/phasor/0.3.1-20230109032243-37ad3ba_yjs@13.5.44:
resolution: {integrity: sha512-mL1gSQ3rzrjdQSbWPtgyMXpbbl266UUjw26d0aIjkOh+iMMI6rWtmKWDoiDkO7tejIjwSNQ4w5zJOjJRIj+mSA==}
peerDependencies:
@ -1690,26 +1668,6 @@ packages:
yjs: 13.5.44
dev: false
/@blocksuite/store/0.3.1-20230109032243-37ad3ba:
resolution: {integrity: sha512-zOUz19jfhuhsUkx9BGEQPZWbPyD/AgX0LB7ShVRdd3YM73x25hD6tPLLz1HEV2b69XokC0P9oSru4aNomm4jkg==}
peerDependencies:
yjs: ^13
dependencies:
'@types/flexsearch': 0.7.3
'@types/quill': 1.3.10
buffer: 6.0.3
flexsearch: 0.7.21
idb-keyval: 6.2.0
ky: 0.33.1
lib0: 0.2.58
y-protocols: 1.0.5
y-webrtc: 10.2.3
transitivePeerDependencies:
- bufferutil
- supports-color
- utf-8-validate
dev: false
/@blocksuite/store/0.3.1-20230109032243-37ad3ba_yjs@13.5.44:
resolution: {integrity: sha512-zOUz19jfhuhsUkx9BGEQPZWbPyD/AgX0LB7ShVRdd3YM73x25hD6tPLLz1HEV2b69XokC0P9oSru4aNomm4jkg==}
peerDependencies: