Refactor: Migrate annotations for the Meteor 3.0 api
This commit is contained in:
parent
074ce93a4f
commit
77fc5d4067
@ -1,13 +1,13 @@
|
||||
import { check } from 'meteor/check';
|
||||
import _ from "lodash";
|
||||
import _ from 'lodash';
|
||||
|
||||
export default function addAnnotation(meetingId, whiteboardId, userId, annotation, Annotations) {
|
||||
async function addAnnotation(meetingId, whiteboardId, userId, annotation, Annotations) {
|
||||
check(meetingId, String);
|
||||
check(whiteboardId, String);
|
||||
check(annotation, Object);
|
||||
|
||||
const {
|
||||
id, wbId,
|
||||
id, wbId,
|
||||
} = annotation;
|
||||
|
||||
let { annotationInfo } = annotation;
|
||||
@ -17,9 +17,9 @@ export default function addAnnotation(meetingId, whiteboardId, userId, annotatio
|
||||
id,
|
||||
};
|
||||
|
||||
const oldAnnotation = Annotations.findOne(selector);
|
||||
const oldAnnotation = await Annotations.findOneAsync(selector);
|
||||
if (oldAnnotation) {
|
||||
annotationInfo = _.merge(oldAnnotation.annotationInfo, annotationInfo)
|
||||
annotationInfo = _.merge(oldAnnotation.annotationInfo, annotationInfo);
|
||||
}
|
||||
|
||||
const modifier = {
|
||||
@ -34,3 +34,5 @@ export default function addAnnotation(meetingId, whiteboardId, userId, annotatio
|
||||
|
||||
return { selector, modifier };
|
||||
}
|
||||
|
||||
export default addAnnotation;
|
||||
|
@ -1,10 +1,9 @@
|
||||
import _ from 'lodash';
|
||||
import { check } from 'meteor/check';
|
||||
import modifyWhiteboardAccess from '/imports/api/whiteboard-multi-user/server/modifiers/modifyWhiteboardAccess';
|
||||
import clearAnnotations from '../modifiers/clearAnnotations';
|
||||
import addAnnotation from '../modifiers/addAnnotation';
|
||||
|
||||
export default function handleWhiteboardAnnotations({ header, body }, meetingId) {
|
||||
async function handleWhiteboardAnnotations({ header, body }, meetingId) {
|
||||
check(header, Object);
|
||||
if (header.userId !== 'nodeJSapp') { return false; }
|
||||
|
||||
@ -17,12 +16,14 @@ export default function handleWhiteboardAnnotations({ header, body }, meetingId)
|
||||
check(whiteboardId, String);
|
||||
check(multiUser, Array);
|
||||
|
||||
clearAnnotations(meetingId, whiteboardId);
|
||||
|
||||
_.each(annotations, (annotation) => {
|
||||
await clearAnnotations(meetingId, whiteboardId);
|
||||
// we use a for loop here instead of a map because we need to guarantee the order of the annotations.
|
||||
for (const annotation of annotations) {
|
||||
const { wbId, userId } = annotation;
|
||||
addAnnotation(meetingId, wbId, userId, annotation);
|
||||
});
|
||||
await addAnnotation(meetingId, wbId, userId, annotation);
|
||||
}
|
||||
|
||||
modifyWhiteboardAccess(meetingId, whiteboardId, multiUser);
|
||||
}
|
||||
|
||||
export default handleWhiteboardAnnotations;
|
||||
|
@ -3,7 +3,7 @@ import AnnotationsStreamer from '/imports/api/annotations/server/streamer';
|
||||
|
||||
import clearAnnotations from '../modifiers/clearAnnotations';
|
||||
|
||||
export default function handleWhiteboardCleared({ body }, meetingId) {
|
||||
export default async function handleWhiteboardCleared({ body }, meetingId) {
|
||||
check(body, {
|
||||
userId: String,
|
||||
whiteboardId: String,
|
||||
@ -14,9 +14,11 @@ export default function handleWhiteboardCleared({ body }, meetingId) {
|
||||
|
||||
if (fullClear) {
|
||||
AnnotationsStreamer(meetingId).emit('removed', { meetingId, whiteboardId });
|
||||
return clearAnnotations(meetingId, whiteboardId);
|
||||
const result = await clearAnnotations(meetingId, whiteboardId);
|
||||
return result;
|
||||
}
|
||||
|
||||
AnnotationsStreamer(meetingId).emit('removed', { meetingId, whiteboardId, userId });
|
||||
return clearAnnotations(meetingId, whiteboardId, userId);
|
||||
const result = await clearAnnotations(meetingId, whiteboardId, userId);
|
||||
return result;
|
||||
}
|
||||
|
@ -3,16 +3,16 @@ import { check } from 'meteor/check';
|
||||
import AnnotationsStreamer from '/imports/api/annotations/server/streamer';
|
||||
import removeAnnotation from '../modifiers/removeAnnotation';
|
||||
|
||||
export default function handleWhiteboardDelete({ body }, meetingId) {
|
||||
const whiteboardId = body.whiteboardId;
|
||||
export default async function handleWhiteboardDelete({ body }, meetingId) {
|
||||
const { whiteboardId } = body;
|
||||
const shapesIds = body.annotationsIds;
|
||||
|
||||
check(whiteboardId, String);
|
||||
check(shapesIds, Array);
|
||||
|
||||
//console.log("!!!!!!!!!!!! handleWhiteboardDelete !!!!!!!!!!!!!!!!!",shapesIds)
|
||||
shapesIds.map(shapeId => {
|
||||
|
||||
const result = await Promise.all(shapesIds.map(async (shapeId) => {
|
||||
AnnotationsStreamer(meetingId).emit('removed', { meetingId, whiteboardId, shapeId });
|
||||
removeAnnotation(meetingId, whiteboardId, shapeId);
|
||||
})
|
||||
await removeAnnotation(meetingId, whiteboardId, shapeId);
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ const process = () => {
|
||||
Meteor.setTimeout(process, ANNOTATION_PROCESS_INTERVAL);
|
||||
};
|
||||
|
||||
export default function handleWhiteboardSend({ envelope, header, body }, meetingId) {
|
||||
export default async function handleWhiteboardSend({ envelope, header, body }, meetingId) {
|
||||
const userId = header.userId;
|
||||
const whiteboardId = body.whiteboardId;
|
||||
const annotations = body.annotations;
|
||||
@ -43,13 +43,14 @@ export default function handleWhiteboardSend({ envelope, header, body }, meeting
|
||||
if (!annotationsQueue.hasOwnProperty(meetingId)) {
|
||||
annotationsQueue[meetingId] = [];
|
||||
}
|
||||
|
||||
annotations.forEach(annotation => {
|
||||
// we use a for loop here instead of a map because we need to guarantee the order of the annotations.
|
||||
for (const annotation of annotations) {
|
||||
annotationsQueue[meetingId].push({ meetingId, whiteboardId, userId: annotation.userId, annotation });
|
||||
if (instanceIdFromMessage === myInstanceId) {
|
||||
addAnnotation(meetingId, whiteboardId, annotation.userId, annotation);
|
||||
await addAnnotation(meetingId, whiteboardId, annotation.userId, annotation);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (queueMetrics) {
|
||||
Metrics.setAnnotationQueueLength(meetingId, annotationsQueue[meetingId].length);
|
||||
}
|
||||
|
@ -3,13 +3,14 @@ import { check } from 'meteor/check';
|
||||
import AnnotationsStreamer from '/imports/api/annotations/server/streamer';
|
||||
import removeAnnotation from '../modifiers/removeAnnotation';
|
||||
|
||||
export default function handleWhiteboardUndo({ body }, meetingId) {
|
||||
const whiteboardId = body.whiteboardId;
|
||||
export default async function handleWhiteboardUndo({ body }, meetingId) {
|
||||
const { whiteboardId } = body;
|
||||
const shapeId = body.annotationId;
|
||||
|
||||
check(whiteboardId, String);
|
||||
check(shapeId, String);
|
||||
|
||||
AnnotationsStreamer(meetingId).emit('removed', { meetingId, whiteboardId, shapeId });
|
||||
return removeAnnotation(meetingId, whiteboardId, shapeId);
|
||||
const result = await removeAnnotation(meetingId, whiteboardId, shapeId);
|
||||
return result;
|
||||
}
|
||||
|
@ -3,15 +3,15 @@ import Logger from '/imports/startup/server/logger';
|
||||
import Annotations from '/imports/api/annotations';
|
||||
import addAnnotationQuery from '/imports/api/annotations/addAnnotation';
|
||||
|
||||
export default function addAnnotation(meetingId, whiteboardId, userId, annotation) {
|
||||
export default async function addAnnotation(meetingId, whiteboardId, userId, annotation) {
|
||||
check(meetingId, String);
|
||||
check(whiteboardId, String);
|
||||
check(annotation, Object);
|
||||
|
||||
const query = addAnnotationQuery(meetingId, whiteboardId, userId, annotation, Annotations);
|
||||
const query = await addAnnotationQuery(meetingId, whiteboardId, userId, annotation, Annotations);
|
||||
|
||||
try {
|
||||
const { insertedId } = Annotations.upsert(query.selector, query.modifier);
|
||||
const { insertedId } = await Annotations.upsertAsync(query.selector, query.modifier);
|
||||
|
||||
if (insertedId) {
|
||||
Logger.info(`Added annotation id=${annotation.id} whiteboard=${whiteboardId}`);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import Annotations from '/imports/api/annotations';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default function clearAnnotations(meetingId, whiteboardId, userId) {
|
||||
export default async function clearAnnotations(meetingId, whiteboardId, userId) {
|
||||
const selector = {};
|
||||
|
||||
if (meetingId) {
|
||||
@ -17,7 +17,7 @@ export default function clearAnnotations(meetingId, whiteboardId, userId) {
|
||||
}
|
||||
|
||||
try {
|
||||
const numberAffected = Annotations.remove(selector);
|
||||
const numberAffected = await Annotations.removeAsync(selector);
|
||||
|
||||
if (numberAffected) {
|
||||
if (userId) {
|
||||
|
@ -2,7 +2,7 @@ import { check } from 'meteor/check';
|
||||
import Annotations from '/imports/api/annotations';
|
||||
import Logger from '/imports/startup/server/logger';
|
||||
|
||||
export default function removeAnnotation(meetingId, whiteboardId, shapeId) {
|
||||
export default async function removeAnnotation(meetingId, whiteboardId, shapeId) {
|
||||
check(meetingId, String);
|
||||
check(whiteboardId, String);
|
||||
check(shapeId, String);
|
||||
@ -14,7 +14,7 @@ export default function removeAnnotation(meetingId, whiteboardId, shapeId) {
|
||||
};
|
||||
|
||||
try {
|
||||
const numberAffected = Annotations.remove(selector);
|
||||
const numberAffected = await Annotations.removeAsync(selector);
|
||||
|
||||
if (numberAffected) {
|
||||
Logger.info(`Removed annotation id=${shapeId} whiteboard=${whiteboardId}`);
|
||||
|
@ -26,13 +26,13 @@ const intlMessages = defineMessages({
|
||||
|
||||
let annotationsStreamListener = null;
|
||||
|
||||
function handleAddedAnnotation({
|
||||
async function handleAddedAnnotation({
|
||||
meetingId,
|
||||
whiteboardId,
|
||||
userId,
|
||||
annotation,
|
||||
}) {
|
||||
const query = addAnnotationQuery(meetingId, whiteboardId, userId, annotation, Annotations);
|
||||
const query = await addAnnotationQuery(meetingId, whiteboardId, userId, annotation, Annotations);
|
||||
|
||||
Annotations.upsert(query.selector, query.modifier);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user