mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-30 05:34:21 +03:00
feat: load workspace in ipc provider
This commit is contained in:
parent
6c784184b1
commit
a76fadb1bc
@ -50,6 +50,7 @@ pub enum IWorkspaceParameters {
|
||||
CreateWorkspace(CreateWorkspace),
|
||||
GetWorkspace(GetWorkspace),
|
||||
GetWorkspaces(GetWorkspaces),
|
||||
GetWorkspaceResult(GetWorkspaceResult),
|
||||
GetWorkspacesResult(GetWorkspacesResult),
|
||||
UpdateWorkspace(UpdateWorkspace),
|
||||
CreateWorkspaceResult(CreateWorkspaceResult),
|
||||
|
@ -13,7 +13,7 @@ export enum WorkspaceType {
|
||||
export enum PermissionType {
|
||||
Read = 0,
|
||||
Write = 1,
|
||||
Admin = 2,
|
||||
Admin = 10,
|
||||
Owner = 99,
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,12 @@ import { ConfigStore } from 'src/store.js';
|
||||
import { User, Workspace as WS, WorkspaceMeta, Logger } from '../../types';
|
||||
import { getDefaultHeadImgBlob } from 'src/utils/index.js';
|
||||
import { IPCBlobProvider } from './blocksuite-provider/blob.js';
|
||||
import { PermissionType, WorkspaceDetail } from '../affine/apis/workspace.js';
|
||||
|
||||
export class TauriIPCProvider extends LocalProvider {
|
||||
static id = 'tauri-ipc';
|
||||
#ipc = ipcMethods;
|
||||
private _workspacesCache: Map<string, Workspace> = new Map();
|
||||
|
||||
constructor(params: ProviderConstructorParams) {
|
||||
super(params);
|
||||
@ -134,8 +136,10 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
|
||||
override async loadWorkspaces() {
|
||||
// TODO: get user id here
|
||||
const workspacesList = await this.#ipc.getWorkspaces({ user_id: 0 });
|
||||
const workspaces: WS[] = workspacesList.workspaces.map(w => {
|
||||
const { workspaces: workspacesList } = await this.#ipc.getWorkspaces({
|
||||
user_id: 0,
|
||||
});
|
||||
const workspaces: WS[] = workspacesList.map(w => {
|
||||
return {
|
||||
...w,
|
||||
memberCount: 0,
|
||||
@ -152,8 +156,8 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
this._workspacesCache.set(id, workspace);
|
||||
if (workspace) {
|
||||
return new Promise<Workspace>(resolve => {
|
||||
downloadWorkspace(id).then(data => {
|
||||
applyUpdate(workspace.doc, new Uint8Array(data));
|
||||
this.#ipc.getYDocument({ id }).then(({ update }) => {
|
||||
Y.applyUpdate(workspace.doc, new Uint8Array(update));
|
||||
resolve(workspace);
|
||||
});
|
||||
});
|
||||
@ -171,16 +175,37 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
};
|
||||
}
|
||||
});
|
||||
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 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 this.#ipc.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) {
|
||||
@ -188,12 +213,12 @@ export class TauriIPCProvider extends LocalProvider {
|
||||
if (workspaceDetail) {
|
||||
const { owner, member_count } = workspaceDetail;
|
||||
const currentWorkspace = workspaces.find(w => w.id === id);
|
||||
if (currentWorkspace) {
|
||||
if (currentWorkspace && owner) {
|
||||
currentWorkspace.owner = {
|
||||
id: owner.id,
|
||||
name: owner.name,
|
||||
avatar: owner.avatar_url,
|
||||
email: owner.email,
|
||||
id: owner.id!,
|
||||
name: owner.name!,
|
||||
avatar: owner.avatar_url!,
|
||||
email: owner.email!,
|
||||
};
|
||||
currentWorkspace.memberCount = member_count;
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import {
|
||||
import {
|
||||
CreateWorkspace,
|
||||
CreateWorkspaceResult,
|
||||
GetWorkspace,
|
||||
GetWorkspaceResult,
|
||||
GetWorkspaces,
|
||||
GetWorkspacesResult,
|
||||
} from './types/workspace';
|
||||
@ -26,8 +28,14 @@ export const createWorkspace = async (parameters: CreateWorkspace) =>
|
||||
await invoke<CreateWorkspaceResult>('create_workspace', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
export const getWorkspaces = async (parameters: GetWorkspaces) =>
|
||||
await invoke<GetWorkspacesResult>('create_workspace', {
|
||||
await invoke<GetWorkspacesResult>('get_workspaces', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
export const getWorkspace = async (parameters: GetWorkspace) =>
|
||||
await invoke<GetWorkspaceResult>('get_workspace', {
|
||||
parameters,
|
||||
});
|
||||
|
||||
|
@ -32,6 +32,16 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["GetWorkspaceResult"],
|
||||
"properties": {
|
||||
"GetWorkspaceResult": {
|
||||
"$ref": "#/definitions/GetWorkspaceResult"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"required": ["GetWorkspacesResult"],
|
||||
@ -99,6 +109,15 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"GetWorkspaceResult": {
|
||||
"type": "object",
|
||||
"required": ["workspace"],
|
||||
"properties": {
|
||||
"workspace": {
|
||||
"$ref": "#/definitions/WorkspaceDetail"
|
||||
}
|
||||
}
|
||||
},
|
||||
"GetWorkspaces": {
|
||||
"type": "object",
|
||||
"required": ["user_id"],
|
||||
@ -122,20 +141,8 @@
|
||||
}
|
||||
},
|
||||
"PermissionType": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
"type": "integer",
|
||||
"enum": [0, 1, 10, 99]
|
||||
},
|
||||
"UpdateWorkspace": {
|
||||
"type": "object",
|
||||
@ -150,15 +157,65 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"WorkspaceType": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "null"
|
||||
"User": {
|
||||
"type": "object",
|
||||
"required": ["created_at", "email", "id", "name"],
|
||||
"properties": {
|
||||
"avatar_url": {
|
||||
"type": ["string", "null"]
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
"created_at": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"WorkspaceDetail": {
|
||||
"type": "object",
|
||||
"required": ["created_at", "id", "member_count", "public", "type"],
|
||||
"properties": {
|
||||
"created_at": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"member_count": {
|
||||
"type": "integer",
|
||||
"format": "int64"
|
||||
},
|
||||
"owner": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/definitions/User"
|
||||
},
|
||||
{
|
||||
"type": "null"
|
||||
}
|
||||
]
|
||||
},
|
||||
"public": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/WorkspaceType"
|
||||
}
|
||||
}
|
||||
},
|
||||
"WorkspaceType": {
|
||||
"type": "integer",
|
||||
"enum": [0, 1]
|
||||
},
|
||||
"WorkspaceWithPermission": {
|
||||
"type": "object",
|
||||
|
@ -15,6 +15,9 @@ export type IWorkspaceParameters =
|
||||
| {
|
||||
GetWorkspaces: GetWorkspaces;
|
||||
}
|
||||
| {
|
||||
GetWorkspaceResult: GetWorkspaceResult;
|
||||
}
|
||||
| {
|
||||
GetWorkspacesResult: GetWorkspacesResult;
|
||||
}
|
||||
@ -24,8 +27,8 @@ export type IWorkspaceParameters =
|
||||
| {
|
||||
CreateWorkspaceResult: CreateWorkspaceResult;
|
||||
};
|
||||
export type PermissionType = null | null | null | null;
|
||||
export type WorkspaceType = null | null;
|
||||
export type WorkspaceType = 0 | 1;
|
||||
export type PermissionType = 0 | 1 | 10 | 99;
|
||||
|
||||
export interface CreateWorkspace {
|
||||
/**
|
||||
@ -43,6 +46,27 @@ export interface GetWorkspaces {
|
||||
user_id: number;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface GetWorkspaceResult {
|
||||
workspace: WorkspaceDetail;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface WorkspaceDetail {
|
||||
created_at: number;
|
||||
id: string;
|
||||
member_count: number;
|
||||
owner?: User | null;
|
||||
public: boolean;
|
||||
type: WorkspaceType;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface User {
|
||||
avatar_url?: string | null;
|
||||
created_at: number;
|
||||
email: string;
|
||||
id: number;
|
||||
name: string;
|
||||
[k: string]: unknown;
|
||||
}
|
||||
export interface GetWorkspacesResult {
|
||||
workspaces: WorkspaceWithPermission[];
|
||||
[k: string]: unknown;
|
||||
|
Loading…
Reference in New Issue
Block a user