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