mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-21 03:56:23 +08:00
feat: ipc get_workspace
This commit is contained in:
@@ -132,10 +132,79 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
return nw;
|
||||
}
|
||||
|
||||
async getWorkspaces(
|
||||
config: Readonly<ConfigStore<boolean>>
|
||||
): Promise<Map<string, boolean> | undefined> {
|
||||
const entries = await config.entries();
|
||||
return new Map(entries);
|
||||
override async loadWorkspaces() {
|
||||
// TODO: get user id here
|
||||
const workspacesList = await this.#ipc.getWorkspaces({ user_id: 0 });
|
||||
const workspaces: WS[] = workspacesList.workspaces.map(w => {
|
||||
return {
|
||||
...w,
|
||||
memberCount: 0,
|
||||
name: '',
|
||||
provider: 'affine',
|
||||
};
|
||||
});
|
||||
const workspaceInstances = workspaces.map(({ id }) => {
|
||||
const workspace =
|
||||
this._workspacesCache.get(id) ||
|
||||
new Workspace({
|
||||
room: id,
|
||||
}).register(BlockSchema);
|
||||
this._workspacesCache.set(id, workspace);
|
||||
if (workspace) {
|
||||
return new Promise<Workspace>(resolve => {
|
||||
downloadWorkspace(id).then(data => {
|
||||
applyUpdate(workspace.doc, new Uint8Array(data));
|
||||
resolve(workspace);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
});
|
||||
|
||||
(await Promise.all(workspaceInstances)).forEach((workspace, i) => {
|
||||
if (workspace) {
|
||||
workspaces[i] = {
|
||||
...workspaces[i],
|
||||
name: workspace.doc.meta.name,
|
||||
avatar: workspace.doc.meta.avatar,
|
||||
};
|
||||
}
|
||||
});
|
||||
const getDetailList = workspacesList.map(w => {
|
||||
const { id } = w;
|
||||
return new Promise<{ id: string; detail: WorkspaceDetail | null }>(
|
||||
resolve => {
|
||||
getWorkspaceDetail({ id }).then(data => {
|
||||
resolve({ id, detail: data || null });
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,16 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["GetWorkspace"],
|
||||
"properties": {
|
||||
"GetWorkspace": {
|
||||
"$ref": "#/definitions/GetWorkspace"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["GetWorkspaces"],
|
||||
@@ -80,6 +90,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"GetWorkspace": {
|
||||
"type": "object",
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"GetWorkspaces": {
|
||||
"type": "object",
|
||||
"required": ["user_id"],
|
||||
@@ -103,8 +122,20 @@
|
||||
}
|
||||
},
|
||||
"PermissionType": {
|
||||
"type": "string",
|
||||
"enum": ["Read", "Write", "Admin", "Owner"]
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"UpdateWorkspace": {
|
||||
"type": "object",
|
||||
@@ -120,8 +151,14 @@
|
||||
}
|
||||
},
|
||||
"WorkspaceType": {
|
||||
"type": "string",
|
||||
"enum": ["Private", "Normal"]
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"WorkspaceWithPermission": {
|
||||
"type": "object",
|
||||
|
||||
@@ -9,6 +9,9 @@ export type IWorkspaceParameters =
|
||||
| {
|
||||
CreateWorkspace: CreateWorkspace;
|
||||
}
|
||||
| {
|
||||
GetWorkspace: GetWorkspace;
|
||||
}
|
||||
| {
|
||||
GetWorkspaces: GetWorkspaces;
|
||||
}
|
||||
@@ -21,8 +24,8 @@ export type IWorkspaceParameters =
|
||||
| {
|
||||
CreateWorkspaceResult: CreateWorkspaceResult;
|
||||
};
|
||||
export type PermissionType = 'Read' | 'Write' | 'Admin' | 'Owner';
|
||||
export type WorkspaceType = 'Private' | 'Normal';
|
||||
export type PermissionType = null | null | null | null;
|
||||
export type WorkspaceType = null | null;
|
||||
|
||||
export interface CreateWorkspace {
|
||||
/**
|
||||
@@ -32,6 +35,10 @@ export interface CreateWorkspace {
|
||||
user_id: number;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface GetWorkspace {
|
||||
id: string;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface GetWorkspaces {
|
||||
user_id: number;
|
||||
[k: string]: unknown;
|
||||
|
||||
Reference in New Issue
Block a user