From 5816840af60f97a34318a52a5276482cab392496 Mon Sep 17 00:00:00 2001 From: bobzel Date: Fri, 16 Oct 2020 15:48:54 -0400 Subject: updated user initialization code to not generate server traffic when creating a new account. set user accounts to update their cache 2.5s after login. --- src/server/websocket.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/server/websocket.ts') diff --git a/src/server/websocket.ts b/src/server/websocket.ts index e5692a7dd..490760441 100644 --- a/src/server/websocket.ts +++ b/src/server/websocket.ts @@ -207,9 +207,12 @@ export namespace WebSocket { } } + function GetRefFieldLocal([id, callback]: [string, (result?: Transferable) => void]) { + return Database.Instance.getDocument(id, callback); + } function GetRefField([id, callback]: [string, (result?: Transferable) => void]) { process.stdout.write(`.`); - Database.Instance.getDocument(id, callback); + GetRefFieldLocal([id, callback]); } function GetRefFields([ids, callback]: [string[], (result?: Transferable[]) => void]) { @@ -311,9 +314,9 @@ export namespace WebSocket { function UpdateField(socket: Socket, diff: Diff) { - if (diff.diff.$addToSet) return GetRefField([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own - if (diff.diff.$remFromSet) return GetRefField([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own - return GetRefField([diff.id, (result?: Transferable) => SetField(socket, diff, result)]); + if (diff.diff.$addToSet) return GetRefFieldLocal([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own + if (diff.diff.$remFromSet) return GetRefFieldLocal([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own + return GetRefFieldLocal([diff.id, (result?: Transferable) => SetField(socket, diff, result)]); } function SetField(socket: Socket, diff: Diff, curListItems?: Transferable) { Database.Instance.update(diff.id, diff.diff, -- cgit v1.2.3-70-g09d2 From 37fc6beb4662be195b8aa551cc1042b04f2c24a8 Mon Sep 17 00:00:00 2001 From: bobzel Date: Sat, 17 Oct 2020 22:01:53 -0400 Subject: fixed rubberbadning ink shapes not to get cutoff. fixed animating annotations. fixed ink masks. fixed warnings. --- src/client/views/InkingStroke.tsx | 4 +--- src/client/views/collections/CollectionMenu.tsx | 2 +- .../collectionFreeForm/CollectionFreeFormView.tsx | 6 ++++-- src/client/views/nodes/PresBox.tsx | 12 ++++++------ src/client/views/pdf/PDFViewer.tsx | 6 +++++- src/server/websocket.ts | 4 ++-- 6 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/server/websocket.ts') diff --git a/src/client/views/InkingStroke.tsx b/src/client/views/InkingStroke.tsx index 186406424..7e424d8f0 100644 --- a/src/client/views/InkingStroke.tsx +++ b/src/client/views/InkingStroke.tsx @@ -38,7 +38,7 @@ export class InkingStroke extends ViewBoxBaseComponent pair.layout).slice().sort((doc1, doc2) => NumCast(doc1.zIndex) - NumCast(doc2.zIndex)); zsorted.forEach((doc, index) => doc.zIndex = doc.isInkMask ? 5000 : index + 1); - const dropPos = [NumCast(docDragData.droppedDocuments[0].x), NumCast(docDragData.droppedDocuments[0].y)]; + const dvals = CollectionFreeFormDocumentView.getValues(refDoc, NumCast(refDoc.activeFrame, 1000)); + const dropPos = this.Document._currentFrame !== undefined ? [dvals.x, dvals.y] : [NumCast(refDoc.x), NumCast(refDoc.y)]; for (let i = 0; i < docDragData.droppedDocuments.length; i++) { const d = docDragData.droppedDocuments[i]; const layoutDoc = Doc.Layout(d); diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx index 3b7794815..01a7bed8c 100644 --- a/src/client/views/nodes/PresBox.tsx +++ b/src/client/views/nodes/PresBox.tsx @@ -288,7 +288,7 @@ export class PresBox extends ViewBoxBaseComponent const willZoom = false; const openInTab = () => { collectionDocView ? collectionDocView.props.addDocTab(activeItem, "replace") : this.props.addDocTab(activeItem, "replace:left"); - } + }; // If openDocument is selected then it should open the document for the user if (activeItem.openDocument) { openInTab(); @@ -299,10 +299,10 @@ export class PresBox extends ViewBoxBaseComponent } else if (docToJump === curDoc) { //checking if curDoc has navigation open if (curDoc.presMovement === PresMovement.Pan && targetDoc) { - await DocumentManager.Instance.jumpToDocument(targetDoc, false, () => { openInTab() }, srcContext); // documents open in new tab instead of on right + await DocumentManager.Instance.jumpToDocument(targetDoc, false, openInTab, srcContext); // documents open in new tab instead of on right } else if ((curDoc.presMovement === PresMovement.Zoom || curDoc.presMovement === PresMovement.Jump) && targetDoc) { //awaiting jump so that new scale can be found, since jumping is async - await DocumentManager.Instance.jumpToDocument(targetDoc, true, () => { openInTab() }, srcContext); // documents open in new tab instead of on right + await DocumentManager.Instance.jumpToDocument(targetDoc, true, openInTab, srcContext); // documents open in new tab instead of on right } } else { //awaiting jump so that new scale can be found, since jumping is async @@ -442,7 +442,7 @@ export class PresBox extends ViewBoxBaseComponent } } }; - this.layoutDoc.presStatus = PresStatus.Auto; + this.layoutDoc.presStatus = PresStatus.Autoplay; this.startPresentation(startSlide); this.gotoDocument(startSlide, this.itemIndex); load(); @@ -450,7 +450,7 @@ export class PresBox extends ViewBoxBaseComponent @action pauseAutoPres = () => { - if (this.layoutDoc.presStatus === PresStatus.Auto) { + if (this.layoutDoc.presStatus === PresStatus.Autoplay) { if (this._presTimer) clearTimeout(this._presTimer); this.layoutDoc.presStatus = PresStatus.Manual; this.layoutDoc.presLoop = false; @@ -611,7 +611,7 @@ export class PresBox extends ViewBoxBaseComponent return true; } childLayoutTemplate = () => this.rootDoc._viewType !== CollectionViewType.Stacking ? undefined : this.presElement; - removeDocument = (doc: Doc) => { return Doc.RemoveDocFromList(this.dataDoc, this.fieldKey, doc); }; + removeDocument = (doc: Doc) => Doc.RemoveDocFromList(this.dataDoc, this.fieldKey, doc); getTransform = () => this.props.ScreenToLocalTransform().translate(-5, -65);// listBox padding-left and pres-box-cont minHeight panelHeight = () => this.props.PanelHeight() - 40; active = (outsideReaction?: boolean) => ((Doc.GetSelectedTool() === InkTool.None && !this.layoutDoc._isBackground) && diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index d278612b1..76b218972 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -730,7 +730,11 @@ export class PDFViewer extends ViewBoxAnnotatableComponent this._pageSizes.length && this._pageSizes[0] ? this._pageSizes[0].width : Doc.NativeWidth(this.Document); @computed get overlayLayer() { return
+ style={{ + pointerEvents: SnappingManager.GetIsDragging() ? "all" : undefined, + mixBlendMode: this.allAnnotations.some(anno => anno.mixBlendMode) ? "hard-light" : undefined, + transform: `scale(${this._zoomed})` + }}> !curList.some((curItem: any) => curItem.fieldId ? curItem.fieldId === newItem.fieldId : curItem.heading ? curItem.heading === newItem.heading : curItem === newItem))]; + const curList = (curListItems as any)?.fields?.[updatefield.replace("fields.", "")]?.fields.filter((item: any) => item !== undefined) || []; + diff.diff.$set[updatefield].fields = [...curList, ...newListItems.filter((newItem: any) => newItem && !curList.some((curItem: any) => curItem.fieldId ? curItem.fieldId === newItem.fieldId : curItem.heading ? curItem.heading === newItem.heading : curItem === newItem))]; const sendBack = diff.diff.length !== diff.diff.$set[updatefield].fields.length; delete diff.diff.length; Database.Instance.update(diff.id, diff.diff, -- cgit v1.2.3-70-g09d2 From 52161a48a9d5f0732e6fe741a8a9a7c2b6dac49e Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 20 Oct 2020 13:43:15 -0400 Subject: fixed concurrency problem when adding/deleting from lists in rapid succession. was causing presentation lists to do strange things when deleting multiple documents at once. --- src/client/views/nodes/PresBox.tsx | 16 ++++----- src/server/websocket.ts | 74 ++++++++++++++++++++++++++------------ 2 files changed, 60 insertions(+), 30 deletions(-) (limited to 'src/server/websocket.ts') diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx index 01a7bed8c..677d612b6 100644 --- a/src/client/views/nodes/PresBox.tsx +++ b/src/client/views/nodes/PresBox.tsx @@ -710,14 +710,14 @@ export class PresBox extends ViewBoxBaseComponent handled = true; } if (e.keyCode === 8) { // delete selected items if (this.layoutDoc.presStatus === "edit") { - await Promise.all(this._selectedArray.map((doc, i): boolean => { - const removed: boolean = this.removeDocument(doc); - console.log("Is removed? : " + i + " | " + removed); - return removed; - })); - action(() => this._selectedArray = []); - action(() => this._eleArray = []); - action(() => this._dragArray = []); + runInAction(() => { + for (const doc of this._selectedArray) { + this.removeDocument(doc); + } + this._selectedArray = []; + this._eleArray = []; + this._dragArray = []; + }); handled = true; } } if (handled) { diff --git a/src/server/websocket.ts b/src/server/websocket.ts index 6ceb9e29f..72e973da3 100644 --- a/src/server/websocket.ts +++ b/src/server/websocket.ts @@ -285,12 +285,14 @@ export namespace WebSocket { Database.Instance.update(diff.id, diff.diff, () => { if (sendBack) { + console.log("RET BACK"); const id = socket.id; socket.id = ""; socket.broadcast.emit(MessageStore.UpdateField.Message, diff); socket.id = id; } else socket.broadcast.emit(MessageStore.UpdateField.Message, diff); }, false); + dispatchNextOp(diff.id); } function remFromListField(socket: Socket, diff: Diff, curListItems?: Transferable): void { @@ -304,47 +306,75 @@ export namespace WebSocket { Database.Instance.update(diff.id, diff.diff, () => { if (sendBack) { + console.log("SEND BACK"); const id = socket.id; socket.id = ""; socket.broadcast.emit(MessageStore.UpdateField.Message, diff); socket.id = id; } else socket.broadcast.emit(MessageStore.UpdateField.Message, diff); }, false); + dispatchNextOp(diff.id); } + const pendingOps = new Map(); + + function dispatchNextOp(id: string) { + const next = pendingOps.get(id)!.shift(); + if (next) { + const { diff, socket } = next; + if (diff.diff.$addToSet) { + return GetRefFieldLocal([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own + } + if (diff.diff.$remFromSet) { + return GetRefFieldLocal([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own + } + return GetRefFieldLocal([diff.id, (result?: Transferable) => SetField(socket, diff, result)]); + } + } function UpdateField(socket: Socket, diff: Diff) { - if (diff.diff.$addToSet) return GetRefFieldLocal([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own - if (diff.diff.$remFromSet) return GetRefFieldLocal([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own + if (pendingOps.has(diff.id)) { + pendingOps.get(diff.id)!.push({ diff, socket }); + return true; + } + if (diff.diff.$addToSet) { + pendingOps.set(diff.id, [{ diff, socket }]); + return GetRefFieldLocal([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own + } + if (diff.diff.$remFromSet) { + pendingOps.set(diff.id, [{ diff, socket }]); + return GetRefFieldLocal([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own + } + pendingOps.set(diff.id, [{ diff, socket }]); return GetRefFieldLocal([diff.id, (result?: Transferable) => SetField(socket, diff, result)]); } function SetField(socket: Socket, diff: Diff, curListItems?: Transferable) { Database.Instance.update(diff.id, diff.diff, () => socket.broadcast.emit(MessageStore.UpdateField.Message, diff), false); const docfield = diff.diff.$set || diff.diff.$unset; - if (!docfield) { - return; - } - const update: any = { id: diff.id }; - let dynfield = false; - for (let key in docfield) { - if (!key.startsWith("fields.")) continue; - dynfield = true; - const val = docfield[key]; - key = key.substring(7); - Object.values(suffixMap).forEach(suf => { update[key + getSuffix(suf)] = { set: null }; }); - const term = ToSearchTerm(val); - if (term !== undefined) { - const { suffix, value } = term; - update[key + suffix] = { set: value }; - if (key.endsWith('lastModified')) { - update["lastModified" + suffix] = value; + if (docfield) { + const update: any = { id: diff.id }; + let dynfield = false; + for (let key in docfield) { + if (!key.startsWith("fields.")) continue; + dynfield = true; + const val = docfield[key]; + key = key.substring(7); + Object.values(suffixMap).forEach(suf => { update[key + getSuffix(suf)] = { set: null }; }); + const term = ToSearchTerm(val); + if (term !== undefined) { + const { suffix, value } = term; + update[key + suffix] = { set: value }; + if (key.endsWith('lastModified')) { + update["lastModified" + suffix] = value; + } } } + if (dynfield) { + Search.updateDocument(update); + } } - if (dynfield) { - Search.updateDocument(update); - } + dispatchNextOp(diff.id); } function DeleteField(socket: Socket, id: string) { -- cgit v1.2.3-70-g09d2 From 047779e1dde284098ca211d8b4bc5c44f2b68b75 Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 20 Oct 2020 15:27:52 -0400 Subject: Fixed. bug from last push. --- src/server/websocket.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'src/server/websocket.ts') diff --git a/src/server/websocket.ts b/src/server/websocket.ts index 72e973da3..34ef3d8b3 100644 --- a/src/server/websocket.ts +++ b/src/server/websocket.ts @@ -330,6 +330,7 @@ export namespace WebSocket { } return GetRefFieldLocal([diff.id, (result?: Transferable) => SetField(socket, diff, result)]); } + if (!pendingOps.get(id)!.length) pendingOps.delete(id); } function UpdateField(socket: Socket, diff: Diff) { -- cgit v1.2.3-70-g09d2 From 21989281937891b89c8cd4bfeb53027a7d14640e Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 20 Oct 2020 22:08:34 -0400 Subject: fixed list operation synchronizatoin on server and made preselementbox change --- src/client/views/presentationview/PresElementBox.tsx | 2 +- src/server/websocket.ts | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src/server/websocket.ts') diff --git a/src/client/views/presentationview/PresElementBox.tsx b/src/client/views/presentationview/PresElementBox.tsx index 9e1a7b615..6fde7c2ac 100644 --- a/src/client/views/presentationview/PresElementBox.tsx +++ b/src/client/views/presentationview/PresElementBox.tsx @@ -175,7 +175,7 @@ export class PresElementBox extends ViewBoxBaseComponent= 1) { const doc = document.createElement('div'); doc.className = "presItem-multiDrag"; - doc.innerText = "Move " + dragArray.length + " slides"; + doc.innerText = "Move " + PresBox.Instance._selectedArray.length + " slides"; doc.style.position = 'absolute'; doc.style.top = (e.clientY) + 'px'; doc.style.left = (e.clientX - 50) + 'px'; diff --git a/src/server/websocket.ts b/src/server/websocket.ts index 34ef3d8b3..7d111f359 100644 --- a/src/server/websocket.ts +++ b/src/server/websocket.ts @@ -291,8 +291,8 @@ export namespace WebSocket { socket.broadcast.emit(MessageStore.UpdateField.Message, diff); socket.id = id; } else socket.broadcast.emit(MessageStore.UpdateField.Message, diff); + dispatchNextOp(diff.id); }, false); - dispatchNextOp(diff.id); } function remFromListField(socket: Socket, diff: Diff, curListItems?: Transferable): void { @@ -312,8 +312,8 @@ export namespace WebSocket { socket.broadcast.emit(MessageStore.UpdateField.Message, diff); socket.id = id; } else socket.broadcast.emit(MessageStore.UpdateField.Message, diff); + dispatchNextOp(diff.id); }, false); - dispatchNextOp(diff.id); } const pendingOps = new Map(); @@ -338,15 +338,13 @@ export namespace WebSocket { pendingOps.get(diff.id)!.push({ diff, socket }); return true; } + pendingOps.set(diff.id, [{ diff, socket }]); if (diff.diff.$addToSet) { - pendingOps.set(diff.id, [{ diff, socket }]); return GetRefFieldLocal([diff.id, (result?: Transferable) => addToListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own } if (diff.diff.$remFromSet) { - pendingOps.set(diff.id, [{ diff, socket }]); return GetRefFieldLocal([diff.id, (result?: Transferable) => remFromListField(socket, diff, result)]); // would prefer to have Mongo handle list additions direclty, but for now handle it on our own } - pendingOps.set(diff.id, [{ diff, socket }]); return GetRefFieldLocal([diff.id, (result?: Transferable) => SetField(socket, diff, result)]); } function SetField(socket: Socket, diff: Diff, curListItems?: Transferable) { -- cgit v1.2.3-70-g09d2