diff --git a/server/migrations/20211026034900-collaborative-revisions.js b/server/migrations/20211026034900-collaborative-revisions.js new file mode 100644 index 0000000000..47460bddba --- /dev/null +++ b/server/migrations/20211026034900-collaborative-revisions.js @@ -0,0 +1,13 @@ +"use strict"; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.addColumn("revisions", "state", { + type: Sequelize.BLOB, + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.removeColumn("revisions", "state"); + }, +}; diff --git a/server/models/Revision.js b/server/models/Revision.js index 6e6f4d95cd..dc15900c31 100644 --- a/server/models/Revision.js +++ b/server/models/Revision.js @@ -1,5 +1,6 @@ // @flow import MarkdownSerializer from "slate-md-serializer"; +import * as Y from "yjs"; import { DataTypes, sequelize } from "../sequelize"; const serializer = new MarkdownSerializer(); @@ -12,6 +13,7 @@ const Revision = sequelize.define("revision", { }, version: DataTypes.SMALLINT, editorVersion: DataTypes.STRING, + state: DataTypes.BLOB, title: DataTypes.STRING, text: DataTypes.TEXT, }); @@ -45,8 +47,17 @@ Revision.findLatest = function (documentId) { }; Revision.createFromDocument = function (document, options) { + let snapshot; + + if (document.state) { + const ydoc = new Y.Doc(); + Y.applyUpdate(ydoc, document.state); + snapshot = Buffer.from(Y.encodeSnapshot(Y.snapshot(ydoc))); + } + return Revision.create( { + state: snapshot, title: document.title, text: document.text, userId: document.lastModifiedById, diff --git a/server/queues/processors/debouncer.js b/server/queues/processors/debouncer.js index 76227c8757..d6dd2a37d1 100644 --- a/server/queues/processors/debouncer.js +++ b/server/queues/processors/debouncer.js @@ -3,6 +3,9 @@ import { Document } from "../../models"; import { globalEventQueue } from "../../queues"; import type { Event } from "../../types"; +const delay = + process.env.NODE_ENV === "development" ? 1 * 60 * 1000 : 5 * 60 * 1000; + export default class DebounceProcessor { async on(event: Event) { switch (event.name) { @@ -13,7 +16,7 @@ export default class DebounceProcessor { name: "documents.update.delayed", }, { - delay: 5 * 60 * 1000, + delay, } ); break; diff --git a/shared/i18n/locales/en_US/translation.json b/shared/i18n/locales/en_US/translation.json index 6a79d13df3..06a14f0c68 100644 --- a/shared/i18n/locales/en_US/translation.json +++ b/shared/i18n/locales/en_US/translation.json @@ -8,7 +8,18 @@ "Development": "Development", "Open document": "Open document", "New document": "New document", + "Star": "Star", + "Unstar": "Unstar", + "Download": "Download", + "Download document": "Download document", + "Duplicate": "Duplicate", + "Duplicate document": "Duplicate document", + "Document duplicated": "Document duplicated", + "Print": "Print", + "Print document": "Print document", "Import document": "Import document", + "Templatize": "Templatize", + "Create template": "Create template", "Home": "Home", "Search": "Search", "Drafts": "Drafts", @@ -198,8 +209,6 @@ "Export": "Export", "Integrations": "Integrations", "Installation": "Installation", - "Unstar": "Unstar", - "Star": "Star", "Previous page": "Previous page", "Next page": "Next page", "Could not import file": "Could not import file", @@ -218,7 +227,6 @@ "Sort in sidebar": "Sort in sidebar", "Alphabetical sort": "Alphabetical sort", "Manual sort": "Manual sort", - "Document duplicated": "Document duplicated", "Document restored": "Document restored", "Document unpublished": "Document unpublished", "Document options": "Document options", @@ -227,15 +235,11 @@ "Unpin": "Unpin", "Pin to collection": "Pin to collection", "New nested document": "New nested document", - "Create template": "Create template", - "Duplicate": "Duplicate", "Unpublish": "Unpublish", "Permanently delete": "Permanently delete", "Move": "Move", "Enable embeds": "Enable embeds", "Disable embeds": "Disable embeds", - "Download": "Download", - "Print": "Print", "Move {{ documentName }}": "Move {{ documentName }}", "Permanently delete {{ documentName }}": "Permanently delete {{ documentName }}", "Export options": "Export options",