Add support for document subscriptions to websockets
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
Pin,
|
||||
Star,
|
||||
Team,
|
||||
Subscription,
|
||||
} from "@server/models";
|
||||
import {
|
||||
presentCollection,
|
||||
@@ -19,6 +20,7 @@ import {
|
||||
presentGroup,
|
||||
presentPin,
|
||||
presentStar,
|
||||
presentSubscription,
|
||||
presentTeam,
|
||||
} from "@server/presenters";
|
||||
import { Event } from "../../types";
|
||||
@@ -532,6 +534,22 @@ export default class WebsocketsProcessor {
|
||||
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": {
|
||||
const team = await Team.scope("withDomains").findByPk(event.teamId);
|
||||
if (!team) {
|
||||
|
||||
Reference in New Issue
Block a user