Add support for document subscriptions to websockets
This commit is contained in:
@@ -11,6 +11,7 @@ import FileOperation from "~/models/FileOperation";
|
|||||||
import Group from "~/models/Group";
|
import Group from "~/models/Group";
|
||||||
import Pin from "~/models/Pin";
|
import Pin from "~/models/Pin";
|
||||||
import Star from "~/models/Star";
|
import Star from "~/models/Star";
|
||||||
|
import Subscription from "~/models/Subscription";
|
||||||
import Team from "~/models/Team";
|
import Team from "~/models/Team";
|
||||||
import withStores from "~/components/withStores";
|
import withStores from "~/components/withStores";
|
||||||
import {
|
import {
|
||||||
@@ -84,6 +85,7 @@ class WebsocketProvider extends React.Component<Props> {
|
|||||||
policies,
|
policies,
|
||||||
presence,
|
presence,
|
||||||
views,
|
views,
|
||||||
|
subscriptions,
|
||||||
fileOperations,
|
fileOperations,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
if (!auth.token) {
|
if (!auth.token) {
|
||||||
@@ -380,6 +382,20 @@ class WebsocketProvider extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.socket.on(
|
||||||
|
"subscriptions.create",
|
||||||
|
(event: PartialWithId<Subscription>) => {
|
||||||
|
subscriptions.add(event);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.socket.on(
|
||||||
|
"subscriptions.delete",
|
||||||
|
(event: WebsocketEntityDeletedEvent) => {
|
||||||
|
subscriptions.remove(event.modelId);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// received a message from the API server that we should request
|
// received a message from the API server that we should request
|
||||||
// to join a specific room. Forward that to the ws server.
|
// to join a specific room. Forward that to the ws server.
|
||||||
this.socket.on("join", (event: any) => {
|
this.socket.on("join", (event: any) => {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
Pin,
|
Pin,
|
||||||
Star,
|
Star,
|
||||||
Team,
|
Team,
|
||||||
|
Subscription,
|
||||||
} from "@server/models";
|
} from "@server/models";
|
||||||
import {
|
import {
|
||||||
presentCollection,
|
presentCollection,
|
||||||
@@ -19,6 +20,7 @@ import {
|
|||||||
presentGroup,
|
presentGroup,
|
||||||
presentPin,
|
presentPin,
|
||||||
presentStar,
|
presentStar,
|
||||||
|
presentSubscription,
|
||||||
presentTeam,
|
presentTeam,
|
||||||
} from "@server/presenters";
|
} from "@server/presenters";
|
||||||
import { Event } from "../../types";
|
import { Event } from "../../types";
|
||||||
@@ -532,6 +534,22 @@ export default class WebsocketsProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "subscriptions.create": {
|
||||||
|
const subscription = await Subscription.findByPk(event.modelId);
|
||||||
|
if (!subscription) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return socketio
|
||||||
|
.to(`user-${event.userId}`)
|
||||||
|
.emit(event.name, presentSubscription(subscription));
|
||||||
|
}
|
||||||
|
|
||||||
|
case "subscriptions.delete": {
|
||||||
|
return socketio.to(`user-${event.userId}`).emit(event.name, {
|
||||||
|
modelId: event.modelId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
case "teams.update": {
|
case "teams.update": {
|
||||||
const team = await Team.scope("withDomains").findByPk(event.teamId);
|
const team = await Team.scope("withDomains").findByPk(event.teamId);
|
||||||
if (!team) {
|
if (!team) {
|
||||||
|
|||||||
Reference in New Issue
Block a user