Separate documents.update event
This commit is contained in:
@@ -5,6 +5,7 @@ import { observer } from "mobx-react";
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { io, Socket } from "socket.io-client";
|
import { io, Socket } from "socket.io-client";
|
||||||
import RootStore from "~/stores/RootStore";
|
import RootStore from "~/stores/RootStore";
|
||||||
|
import Document from "~/models/Document";
|
||||||
import FileOperation from "~/models/FileOperation";
|
import FileOperation from "~/models/FileOperation";
|
||||||
import Pin from "~/models/Pin";
|
import Pin from "~/models/Pin";
|
||||||
import Star from "~/models/Star";
|
import Star from "~/models/Star";
|
||||||
@@ -232,6 +233,19 @@ class SocketProvider extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.socket.on(
|
||||||
|
"documents.update",
|
||||||
|
(event: PartialWithId<Document> & { title: string; url: string }) => {
|
||||||
|
const document = documents.get(event.id);
|
||||||
|
document?.updateFromJson(event);
|
||||||
|
|
||||||
|
if (event.collectionId) {
|
||||||
|
const collection = collections.get(event.collectionId);
|
||||||
|
collection?.updateDocument(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
this.socket.on("documents.delete", (event: WebsocketEntityDeletedEvent) => {
|
this.socket.on("documents.delete", (event: WebsocketEntityDeletedEvent) => {
|
||||||
const document = documents.get(event.modelId);
|
const document = documents.get(event.modelId);
|
||||||
|
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export default class Collection extends ParanoidModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
updateDocument(document: Document) {
|
updateDocument(document: Pick<Document, "id" | "title" | "url">) {
|
||||||
const travelNodes = (nodes: NavigationNode[]) =>
|
const travelNodes = (nodes: NavigationNode[]) =>
|
||||||
nodes.forEach((node) => {
|
nodes.forEach((node) => {
|
||||||
if (node.id === document.id) {
|
if (node.id === document.id) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
Team,
|
Team,
|
||||||
} from "@server/models";
|
} from "@server/models";
|
||||||
import {
|
import {
|
||||||
|
presentDocument,
|
||||||
presentFileOperation,
|
presentFileOperation,
|
||||||
presentPin,
|
presentPin,
|
||||||
presentStar,
|
presentStar,
|
||||||
@@ -101,15 +102,9 @@ export default class WebsocketsProcessor {
|
|||||||
const channel = document.publishedAt
|
const channel = document.publishedAt
|
||||||
? `collection-${document.collectionId}`
|
? `collection-${document.collectionId}`
|
||||||
: `user-${event.actorId}`;
|
: `user-${event.actorId}`;
|
||||||
return socketio.to(channel).emit("entities", {
|
|
||||||
event: event.name,
|
const data = await presentDocument(document);
|
||||||
documentIds: [
|
return socketio.to(channel).emit(event.name, data);
|
||||||
{
|
|
||||||
id: document.id,
|
|
||||||
updatedAt: document.updatedAt,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case "documents.create": {
|
case "documents.create": {
|
||||||
|
|||||||
Reference in New Issue
Block a user