mirror of
https://github.com/docmost/docmost.git
synced 2025-11-18 14:21:12 +10:00
Make colloboration module not dependant on page module
* add unloadImmediately to collab
This commit is contained in:
@ -17,6 +17,7 @@ export class CollaborationGateway {
|
||||
private hocuspocus = HocuspocusServer.configure({
|
||||
debounce: 5000,
|
||||
maxDebounce: 10000,
|
||||
unloadImmediately: false,
|
||||
extensions: [
|
||||
this.authenticationExtension,
|
||||
this.persistenceExtension,
|
||||
|
||||
@ -2,7 +2,6 @@ import { Module, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||
import { AuthModule } from '../core/auth/auth.module';
|
||||
import { AuthenticationExtension } from './extensions/authentication.extension';
|
||||
import { PersistenceExtension } from './extensions/persistence.extension';
|
||||
import { PageModule } from '../core/page/page.module';
|
||||
import { CollaborationGateway } from './collaboration.gateway';
|
||||
import { HttpAdapterHost } from '@nestjs/core';
|
||||
import { CollabWsAdapter } from './adapter/collab-ws.adapter';
|
||||
@ -17,7 +16,7 @@ import { HistoryExtension } from './extensions/history.extension';
|
||||
PersistenceExtension,
|
||||
HistoryExtension,
|
||||
],
|
||||
imports: [AuthModule, PageModule],
|
||||
imports: [AuthModule],
|
||||
})
|
||||
export class CollaborationModule implements OnModuleInit, OnModuleDestroy {
|
||||
private collabWsAdapter: CollabWsAdapter;
|
||||
|
||||
@ -4,8 +4,8 @@ import {
|
||||
onDisconnectPayload,
|
||||
} from '@hocuspocus/server';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PageService } from '../../core/page/services/page.service';
|
||||
import { PageHistoryService } from '../../core/page/services/page-history.service';
|
||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||
import { PageHistoryRepo } from '@docmost/db/repos/page/page-history.repo';
|
||||
|
||||
@Injectable()
|
||||
export class HistoryExtension implements Extension {
|
||||
@ -14,8 +14,8 @@ export class HistoryExtension implements Extension {
|
||||
lastEditTimeMap = new Map<string, number>();
|
||||
|
||||
constructor(
|
||||
private readonly pageService: PageService,
|
||||
private readonly pageHistoryService: PageHistoryService,
|
||||
private readonly pageRepo: PageRepo,
|
||||
private readonly pageHistoryRepo: PageHistoryRepo,
|
||||
) {}
|
||||
|
||||
async onChange(data: onChangePayload): Promise<void> {
|
||||
@ -53,10 +53,11 @@ export class HistoryExtension implements Extension {
|
||||
|
||||
async recordHistory(pageId: string) {
|
||||
try {
|
||||
const includeContent = true;
|
||||
const page = await this.pageService.findById(pageId, includeContent);
|
||||
const page = await this.pageRepo.findById(pageId, {
|
||||
includeContent: true,
|
||||
});
|
||||
// Todo: compare if data is the same as the previous version
|
||||
await this.pageHistoryService.saveHistory(page);
|
||||
await this.pageHistoryRepo.saveHistory(page);
|
||||
console.log(`New history created for: ${pageId}`);
|
||||
} catch (err) {
|
||||
console.error('An error occurred saving page history', err);
|
||||
|
||||
@ -4,14 +4,14 @@ import {
|
||||
onStoreDocumentPayload,
|
||||
} from '@hocuspocus/server';
|
||||
import * as Y from 'yjs';
|
||||
import { PageService } from '../../core/page/services/page.service';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { TiptapTransformer } from '@hocuspocus/transformer';
|
||||
import { jsonToText, tiptapExtensions } from '../collaboration.util';
|
||||
import { PageRepo } from '@docmost/db/repos/page/page.repo';
|
||||
|
||||
@Injectable()
|
||||
export class PersistenceExtension implements Extension {
|
||||
constructor(private readonly pageService: PageService) {}
|
||||
constructor(private readonly pageRepo: PageRepo) {}
|
||||
|
||||
async onLoadDocument(data: onLoadDocumentPayload) {
|
||||
const { documentName, document } = data;
|
||||
@ -21,7 +21,10 @@ export class PersistenceExtension implements Extension {
|
||||
return;
|
||||
}
|
||||
|
||||
const page = await this.pageService.findById(pageId, true, true);
|
||||
const page = await this.pageRepo.findById(pageId, {
|
||||
includeContent: true,
|
||||
includeYdoc: true,
|
||||
});
|
||||
|
||||
if (!page) {
|
||||
console.log('page does not exist.');
|
||||
@ -68,11 +71,14 @@ export class PersistenceExtension implements Extension {
|
||||
const textContent = jsonToText(tiptapJson);
|
||||
|
||||
try {
|
||||
await this.pageService.updateState(
|
||||
await this.pageRepo.updatePage(
|
||||
{
|
||||
content: tiptapJson,
|
||||
textContent: textContent,
|
||||
ydoc: ydocState,
|
||||
lastUpdatedById: context.user.id,
|
||||
},
|
||||
pageId,
|
||||
tiptapJson,
|
||||
textContent,
|
||||
ydocState,
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(`Failed to update page ${documentName}`);
|
||||
|
||||
Reference in New Issue
Block a user