mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 02:35:58 +08:00
Merge branch 'feat/cloud-sync-saika' into feat/datacenter-dev
This commit is contained in:
@@ -416,13 +416,14 @@ export class DataCenter {
|
|||||||
/**
|
/**
|
||||||
* accept invitation
|
* accept invitation
|
||||||
* @param {string} inviteCode
|
* @param {string} inviteCode
|
||||||
|
* @returns {Promise<Permission | null>} permission
|
||||||
*/
|
*/
|
||||||
async acceptInvitation(inviteCode: string, providerStr = 'affine') {
|
async acceptInvitation(inviteCode: string, providerStr = 'affine') {
|
||||||
const provider = this.providerMap.get(providerStr);
|
const provider = this.providerMap.get(providerStr);
|
||||||
if (provider) {
|
if (provider) {
|
||||||
return await provider.acceptInvitation(inviteCode);
|
return await provider.acceptInvitation(inviteCode);
|
||||||
}
|
}
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMessage(cb: (message: Message) => void) {
|
onMessage(cb: (message: Message) => void) {
|
||||||
|
|||||||
@@ -102,10 +102,19 @@ export class AffineProvider extends BaseProvider {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handlerAffineListMessage({ ws_details, metadata }: ChannelMessage) {
|
private async _handlerAffineListMessage({
|
||||||
|
ws_details,
|
||||||
|
metadata,
|
||||||
|
}: ChannelMessage) {
|
||||||
this._logger('receive server message');
|
this._logger('receive server message');
|
||||||
Object.entries(ws_details).forEach(async ([id, detail]) => {
|
const addedWorkspaces: WorkspaceUnit[] = [];
|
||||||
|
const removeWorkspaceList = this._workspaces.list().map(w => w.id);
|
||||||
|
for (const [id, detail] of Object.entries(ws_details)) {
|
||||||
const { name, avatar } = metadata[id];
|
const { name, avatar } = metadata[id];
|
||||||
|
const index = removeWorkspaceList.indexOf(id);
|
||||||
|
if (index !== -1) {
|
||||||
|
removeWorkspaceList.splice(index, 1);
|
||||||
|
}
|
||||||
assert(name);
|
assert(name);
|
||||||
const workspace = {
|
const workspace = {
|
||||||
name: name,
|
name: name,
|
||||||
@@ -122,15 +131,20 @@ export class AffineProvider extends BaseProvider {
|
|||||||
syncMode: 'core' as SyncMode,
|
syncMode: 'core' as SyncMode,
|
||||||
};
|
};
|
||||||
if (this._workspaces.get(id)) {
|
if (this._workspaces.get(id)) {
|
||||||
|
// update workspaces
|
||||||
this._workspaces.update(id, workspace);
|
this._workspaces.update(id, workspace);
|
||||||
} else {
|
} else {
|
||||||
const workspaceUnit = await loadWorkspaceUnit(
|
const workspaceUnit = await loadWorkspaceUnit(
|
||||||
{ id, ...workspace },
|
{ id, ...workspace },
|
||||||
this._apis
|
this._apis
|
||||||
);
|
);
|
||||||
this._workspaces.add(workspaceUnit);
|
addedWorkspaces.push(workspaceUnit);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
// add workspaces
|
||||||
|
this._workspaces.add(addedWorkspaces);
|
||||||
|
// remove workspaces
|
||||||
|
this._workspaces.remove(removeWorkspaceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getWebsocketProvider(workspace: BlocksuiteWorkspace) {
|
private _getWebsocketProvider(workspace: BlocksuiteWorkspace) {
|
||||||
@@ -386,7 +400,7 @@ export class AffineProvider extends BaseProvider {
|
|||||||
return this._apis.getWorkspaceMembers({ id });
|
return this._apis.getWorkspaceMembers({ id });
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async acceptInvitation(invitingCode: string): Promise<void> {
|
public override async acceptInvitation(invitingCode: string) {
|
||||||
await this._apis.acceptInviting({ invitingCode });
|
return await this._apis.acceptInviting({ invitingCode });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,13 +197,13 @@ export interface AcceptInvitingParams {
|
|||||||
|
|
||||||
export async function acceptInviting(
|
export async function acceptInviting(
|
||||||
params: AcceptInvitingParams
|
params: AcceptInvitingParams
|
||||||
): Promise<void> {
|
): Promise<Permission> {
|
||||||
await bareClient
|
try {
|
||||||
.post(`api/invitation/${params.invitingCode}`)
|
return bareClient.post(`api/invitation/${params.invitingCode}`).json();
|
||||||
.catch(error => {
|
} catch (error) {
|
||||||
sendMessage(messageCode.acceptInvitingFailed);
|
sendMessage(messageCode.acceptInvitingFailed);
|
||||||
throw new RequestError('accept inviting failed', error);
|
throw new RequestError('accept inviting failed', error);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadBlob(params: { blob: Blob }): Promise<string> {
|
export async function uploadBlob(params: { blob: Blob }): Promise<string> {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { Logger, User } from '../types';
|
|||||||
import type { WorkspaceUnitCollectionScope } from '../workspace-unit-collection';
|
import type { WorkspaceUnitCollectionScope } from '../workspace-unit-collection';
|
||||||
import type { WorkspaceUnitCtorParams, WorkspaceUnit } from '../workspace-unit';
|
import type { WorkspaceUnitCtorParams, WorkspaceUnit } from '../workspace-unit';
|
||||||
import { Member } from './affine/apis';
|
import { Member } from './affine/apis';
|
||||||
|
import { Permission } from './affine/apis/workspace.js';
|
||||||
|
|
||||||
const defaultLogger = () => {
|
const defaultLogger = () => {
|
||||||
return;
|
return;
|
||||||
@@ -233,8 +234,10 @@ export class BaseProvider {
|
|||||||
* @param {string} inviteCode
|
* @param {string} inviteCode
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async acceptInvitation(inviteCode: string): Promise<void> {
|
public async acceptInvitation(
|
||||||
|
inviteCode: string
|
||||||
|
): Promise<Permission | null> {
|
||||||
inviteCode;
|
inviteCode;
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export interface WorkspaceUnitCollectionScope {
|
|||||||
get: (workspaceId: string) => WorkspaceUnit | undefined;
|
get: (workspaceId: string) => WorkspaceUnit | undefined;
|
||||||
list: () => WorkspaceUnit[];
|
list: () => WorkspaceUnit[];
|
||||||
add: (workspace: WorkspaceUnit | WorkspaceUnit[]) => void;
|
add: (workspace: WorkspaceUnit | WorkspaceUnit[]) => void;
|
||||||
remove: (workspaceId: string) => boolean;
|
remove: (workspaceId: string | string[]) => boolean;
|
||||||
clear: () => void;
|
clear: () => void;
|
||||||
update: (
|
update: (
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
@@ -18,7 +18,7 @@ export interface WorkspaceUnitCollectionScope {
|
|||||||
|
|
||||||
export interface WorkspaceUnitCollectionChangeEvent {
|
export interface WorkspaceUnitCollectionChangeEvent {
|
||||||
added?: WorkspaceUnit[];
|
added?: WorkspaceUnit[];
|
||||||
deleted?: WorkspaceUnit;
|
deleted?: WorkspaceUnit[];
|
||||||
updated?: WorkspaceUnit;
|
updated?: WorkspaceUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,16 +62,22 @@ export class WorkspaceUnitCollection {
|
|||||||
const workspaceUnits = Array.isArray(workspaceUnit)
|
const workspaceUnits = Array.isArray(workspaceUnit)
|
||||||
? workspaceUnit
|
? workspaceUnit
|
||||||
: [workspaceUnit];
|
: [workspaceUnit];
|
||||||
|
let added = false;
|
||||||
|
|
||||||
workspaceUnits.forEach(workspaceUnit => {
|
workspaceUnits.forEach(workspaceUnit => {
|
||||||
if (this._workspaceUnitMap.has(workspaceUnit.id)) {
|
if (this._workspaceUnitMap.has(workspaceUnit.id)) {
|
||||||
// FIXME: multiple add same workspace
|
// FIXME: multiple add same workspace
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
added = true;
|
||||||
this._workspaceUnitMap.set(workspaceUnit.id, workspaceUnit);
|
this._workspaceUnitMap.set(workspaceUnit.id, workspaceUnit);
|
||||||
scopedWorkspaceIds.add(workspaceUnit.id);
|
scopedWorkspaceIds.add(workspaceUnit.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!added) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._events.emit('change', [
|
this._events.emit('change', [
|
||||||
{
|
{
|
||||||
added: workspaceUnits,
|
added: workspaceUnits,
|
||||||
@@ -79,27 +85,39 @@ export class WorkspaceUnitCollection {
|
|||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const remove = (workspaceId: string) => {
|
const remove = (workspaceId: string | string[]) => {
|
||||||
if (!scopedWorkspaceIds.has(workspaceId)) {
|
const workspaceIds = Array.isArray(workspaceId)
|
||||||
return true;
|
? workspaceId
|
||||||
}
|
: [workspaceId];
|
||||||
|
const workspaceUnits: WorkspaceUnit[] = [];
|
||||||
|
|
||||||
const workspaceUnit = this._workspaceUnitMap.get(workspaceId);
|
workspaceIds.forEach(workspaceId => {
|
||||||
if (workspaceUnit) {
|
if (!scopedWorkspaceIds.has(workspaceId)) {
|
||||||
const ret = this._workspaceUnitMap.delete(workspaceId);
|
return;
|
||||||
// If deletion failed, return.
|
|
||||||
if (!ret) {
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
const workspaceUnit = this._workspaceUnitMap.get(workspaceId);
|
||||||
|
if (workspaceUnit) {
|
||||||
|
const ret = this._workspaceUnitMap.delete(workspaceId);
|
||||||
|
// If deletion failed, return.
|
||||||
|
if (!ret) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
scopedWorkspaceIds.delete(workspaceId);
|
workspaceUnits.push(workspaceUnit);
|
||||||
|
scopedWorkspaceIds.delete(workspaceId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this._events.emit('change', [
|
if (!workspaceUnits.length) {
|
||||||
{
|
return false;
|
||||||
deleted: workspaceUnit,
|
|
||||||
} as WorkspaceUnitCollectionChangeEvent,
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._events.emit('change', [
|
||||||
|
{
|
||||||
|
deleted: workspaceUnits,
|
||||||
|
} as WorkspaceUnitCollectionChangeEvent,
|
||||||
|
]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user