chore: Move to prettier standard double quotes (#1309)
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
// @flow
|
||||
import type { Event } from '../events';
|
||||
import type { Event } from "../events";
|
||||
import {
|
||||
Document,
|
||||
Collection,
|
||||
Group,
|
||||
CollectionGroup,
|
||||
GroupUser,
|
||||
} from '../models';
|
||||
import { socketio } from '../';
|
||||
import { Op } from '../sequelize';
|
||||
import subHours from 'date-fns/sub_hours';
|
||||
} from "../models";
|
||||
import { socketio } from "../";
|
||||
import { Op } from "../sequelize";
|
||||
import subHours from "date-fns/sub_hours";
|
||||
|
||||
export default class Websockets {
|
||||
async on(event: Event) {
|
||||
if (process.env.WEBSOCKETS_ENABLED !== 'true' || !socketio) return;
|
||||
if (process.env.WEBSOCKETS_ENABLED !== "true" || !socketio) return;
|
||||
|
||||
switch (event.name) {
|
||||
case 'documents.publish':
|
||||
case 'documents.restore':
|
||||
case 'documents.archive':
|
||||
case 'documents.unarchive': {
|
||||
case "documents.publish":
|
||||
case "documents.restore":
|
||||
case "documents.archive":
|
||||
case "documents.unarchive": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio
|
||||
.to(`collection-${document.collectionId}`)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -41,13 +41,13 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.delete': {
|
||||
case "documents.delete": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
if (!document.publishedAt) {
|
||||
return socketio.to(`user-${document.createdById}`).emit('entities', {
|
||||
return socketio.to(`user-${document.createdById}`).emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -60,7 +60,7 @@ export default class Websockets {
|
||||
|
||||
return socketio
|
||||
.to(`collection-${document.collectionId}`)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -75,16 +75,16 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.pin':
|
||||
case 'documents.unpin':
|
||||
case 'documents.update': {
|
||||
case "documents.pin":
|
||||
case "documents.unpin":
|
||||
case "documents.update": {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio
|
||||
.to(`collection-${document.collectionId}`)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -94,10 +94,10 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.create': {
|
||||
case "documents.create": {
|
||||
const document = await Document.findByPk(event.documentId);
|
||||
|
||||
return socketio.to(`user-${event.actorId}`).emit('entities', {
|
||||
return socketio.to(`user-${event.actorId}`).emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -112,13 +112,13 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'documents.star':
|
||||
case 'documents.unstar': {
|
||||
case "documents.star":
|
||||
case "documents.unstar": {
|
||||
return socketio.to(`user-${event.actorId}`).emit(event.name, {
|
||||
documentId: event.documentId,
|
||||
});
|
||||
}
|
||||
case 'documents.move': {
|
||||
case "documents.move": {
|
||||
const documents = await Document.findAll({
|
||||
where: {
|
||||
id: event.data.documentIds,
|
||||
@@ -126,7 +126,7 @@ export default class Websockets {
|
||||
paranoid: false,
|
||||
});
|
||||
documents.forEach(document => {
|
||||
socketio.to(`collection-${document.collectionId}`).emit('entities', {
|
||||
socketio.to(`collection-${document.collectionId}`).emit("entities", {
|
||||
event: event.name,
|
||||
documentIds: [
|
||||
{
|
||||
@@ -137,14 +137,14 @@ export default class Websockets {
|
||||
});
|
||||
});
|
||||
event.data.collectionIds.forEach(collectionId => {
|
||||
socketio.to(`collection-${collectionId}`).emit('entities', {
|
||||
socketio.to(`collection-${collectionId}`).emit("entities", {
|
||||
event: event.name,
|
||||
collectionIds: [{ id: collectionId }],
|
||||
});
|
||||
});
|
||||
return;
|
||||
}
|
||||
case 'collections.create': {
|
||||
case "collections.create": {
|
||||
const collection = await Collection.findByPk(event.collectionId, {
|
||||
paranoid: false,
|
||||
});
|
||||
@@ -155,7 +155,7 @@ export default class Websockets {
|
||||
? `collection-${collection.id}`
|
||||
: `team-${collection.teamId}`
|
||||
)
|
||||
.emit('entities', {
|
||||
.emit("entities", {
|
||||
event: event.name,
|
||||
collectionIds: [
|
||||
{
|
||||
@@ -170,18 +170,18 @@ export default class Websockets {
|
||||
? `collection-${collection.id}`
|
||||
: `team-${collection.teamId}`
|
||||
)
|
||||
.emit('join', {
|
||||
.emit("join", {
|
||||
event: event.name,
|
||||
collectionId: collection.id,
|
||||
});
|
||||
}
|
||||
case 'collections.update':
|
||||
case 'collections.delete': {
|
||||
case "collections.update":
|
||||
case "collections.delete": {
|
||||
const collection = await Collection.findByPk(event.collectionId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio.to(`team-${collection.teamId}`).emit('entities', {
|
||||
return socketio.to(`team-${collection.teamId}`).emit("entities", {
|
||||
event: event.name,
|
||||
collectionIds: [
|
||||
{
|
||||
@@ -191,7 +191,7 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'collections.add_user': {
|
||||
case "collections.add_user": {
|
||||
// the user being added isn't yet in the websocket channel for the collection
|
||||
// so they need to be notified separately
|
||||
socketio.to(`user-${event.userId}`).emit(event.name, {
|
||||
@@ -208,12 +208,12 @@ export default class Websockets {
|
||||
});
|
||||
|
||||
// tell any user clients to connect to the websocket channel for the collection
|
||||
return socketio.to(`user-${event.userId}`).emit('join', {
|
||||
return socketio.to(`user-${event.userId}`).emit("join", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
}
|
||||
case 'collections.remove_user': {
|
||||
case "collections.remove_user": {
|
||||
const membershipUserIds = await Collection.membershipUserIds(
|
||||
event.collectionId
|
||||
);
|
||||
@@ -222,8 +222,8 @@ export default class Websockets {
|
||||
// Even though we just removed a user from the collection
|
||||
// the user still has access through some means
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio.to(`user-${event.userId}`).emit('collections.add_user', {
|
||||
event: 'collections.add_user',
|
||||
socketio.to(`user-${event.userId}`).emit("collections.add_user", {
|
||||
event: "collections.add_user",
|
||||
userId: event.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
@@ -231,21 +231,21 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was removed
|
||||
socketio
|
||||
.to(`collection-${event.collectionId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect from the websocket channel for the collection
|
||||
socketio.to(`user-${event.userId}`).emit('leave', {
|
||||
socketio.to(`user-${event.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'collections.add_group': {
|
||||
case "collections.add_group": {
|
||||
const group = await Group.findByPk(event.data.groupId);
|
||||
|
||||
// the users being added are not yet in the websocket channel for the collection
|
||||
@@ -253,21 +253,21 @@ export default class Websockets {
|
||||
for (const groupMembership of group.groupMemberships) {
|
||||
socketio
|
||||
.to(`user-${groupMembership.userId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: groupMembership.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to connect to the websocket channel for the collection
|
||||
socketio.to(`user-${groupMembership.userId}`).emit('join', {
|
||||
socketio.to(`user-${groupMembership.userId}`).emit("join", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'collections.remove_group': {
|
||||
case "collections.remove_group": {
|
||||
const group = await Group.findByPk(event.data.groupId);
|
||||
const membershipUserIds = await Collection.membershipUserIds(
|
||||
event.collectionId
|
||||
@@ -279,7 +279,7 @@ export default class Websockets {
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio
|
||||
.to(`user-${groupMembership.userId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: groupMembership.userId,
|
||||
collectionId: event.collectionId,
|
||||
@@ -288,14 +288,14 @@ export default class Websockets {
|
||||
// let users in the channel know they were removed
|
||||
socketio
|
||||
.to(`user-${groupMembership.userId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: groupMembership.userId,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect to the websocket channel for the collection
|
||||
socketio.to(`user-${groupMembership.userId}`).emit('leave', {
|
||||
socketio.to(`user-${groupMembership.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: event.collectionId,
|
||||
});
|
||||
@@ -303,13 +303,13 @@ export default class Websockets {
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'groups.create':
|
||||
case 'groups.update': {
|
||||
case "groups.create":
|
||||
case "groups.update": {
|
||||
const group = await Group.findByPk(event.modelId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
return socketio.to(`team-${group.teamId}`).emit('entities', {
|
||||
return socketio.to(`team-${group.teamId}`).emit("entities", {
|
||||
event: event.name,
|
||||
groupIds: [
|
||||
{
|
||||
@@ -319,7 +319,7 @@ export default class Websockets {
|
||||
],
|
||||
});
|
||||
}
|
||||
case 'groups.add_user': {
|
||||
case "groups.add_user": {
|
||||
// do an add user for every collection that the group is a part of
|
||||
const collectionGroupMemberships = await CollectionGroup.findAll({
|
||||
where: { groupId: event.modelId },
|
||||
@@ -328,7 +328,7 @@ export default class Websockets {
|
||||
for (const collectionGroup of collectionGroupMemberships) {
|
||||
// the user being added isn't yet in the websocket channel for the collection
|
||||
// so they need to be notified separately
|
||||
socketio.to(`user-${event.userId}`).emit('collections.add_user', {
|
||||
socketio.to(`user-${event.userId}`).emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
@@ -337,21 +337,21 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was added
|
||||
socketio
|
||||
.to(`collection-${collectionGroup.collectionId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to connect to the websocket channel for the collection
|
||||
return socketio.to(`user-${event.userId}`).emit('join', {
|
||||
return socketio.to(`user-${event.userId}`).emit("join", {
|
||||
event: event.name,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'groups.remove_user': {
|
||||
case "groups.remove_user": {
|
||||
const collectionGroupMemberships = await CollectionGroup.findAll({
|
||||
where: { groupId: event.modelId },
|
||||
});
|
||||
@@ -360,7 +360,7 @@ export default class Websockets {
|
||||
// if the user has any memberships remaining on the collection
|
||||
// we need to emit add instead of remove
|
||||
const collection = await Collection.scope({
|
||||
method: ['withMembership', event.userId],
|
||||
method: ["withMembership", event.userId],
|
||||
}).findByPk(collectionGroup.collectionId);
|
||||
|
||||
const hasMemberships =
|
||||
@@ -370,7 +370,7 @@ export default class Websockets {
|
||||
if (hasMemberships) {
|
||||
// the user still has access through some means...
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio.to(`user-${event.userId}`).emit('collections.add_user', {
|
||||
socketio.to(`user-${event.userId}`).emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
@@ -379,14 +379,14 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was removed
|
||||
socketio
|
||||
.to(`collection-${collectionGroup.collectionId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: event.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect from the websocket channel for the collection
|
||||
socketio.to(`user-${event.userId}`).emit('leave', {
|
||||
socketio.to(`user-${event.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
@@ -394,12 +394,12 @@ export default class Websockets {
|
||||
}
|
||||
return;
|
||||
}
|
||||
case 'groups.delete': {
|
||||
case "groups.delete": {
|
||||
const group = await Group.findByPk(event.modelId, {
|
||||
paranoid: false,
|
||||
});
|
||||
|
||||
socketio.to(`team-${group.teamId}`).emit('entities', {
|
||||
socketio.to(`team-${group.teamId}`).emit("entities", {
|
||||
event: event.name,
|
||||
groupIds: [
|
||||
{
|
||||
@@ -443,7 +443,7 @@ export default class Websockets {
|
||||
// treat this like an add, so that the client re-syncs policies
|
||||
socketio
|
||||
.to(`user-${groupUser.userId}`)
|
||||
.emit('collections.add_user', {
|
||||
.emit("collections.add_user", {
|
||||
event: event.name,
|
||||
userId: groupUser.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
@@ -452,14 +452,14 @@ export default class Websockets {
|
||||
// let everyone with access to the collection know a user was removed
|
||||
socketio
|
||||
.to(`collection-${collectionGroup.collectionId}`)
|
||||
.emit('collections.remove_user', {
|
||||
.emit("collections.remove_user", {
|
||||
event: event.name,
|
||||
userId: groupUser.userId,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
// tell any user clients to disconnect from the websocket channel for the collection
|
||||
socketio.to(`user-${groupUser.userId}`).emit('leave', {
|
||||
socketio.to(`user-${groupUser.userId}`).emit("leave", {
|
||||
event: event.name,
|
||||
collectionId: collectionGroup.collectionId,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user