aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/DocServer.ts5
-rw-r--r--src/client/documents/Documents.ts4
-rw-r--r--src/client/util/CurrentUserUtils.ts15
-rw-r--r--src/client/views/GlobalKeyHandler.ts2
-rw-r--r--src/client/views/Main.tsx3
-rw-r--r--src/client/views/search/SearchBox.tsx2
-rw-r--r--src/server/websocket.ts11
7 files changed, 26 insertions, 16 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts
index 00f9877c3..1d7497cf8 100644
--- a/src/client/DocServer.ts
+++ b/src/client/DocServer.ts
@@ -28,13 +28,13 @@ import * as rp from 'request-promise';
export namespace DocServer {
let _cache: { [id: string]: RefField | Promise<Opt<RefField>> } = {};
- export function PRINT_CACHE() {
+ export function UPDATE_SERVER_CACHE(print: boolean = false) {
const strings: string[] = [];
Array.from(Object.keys(_cache)).forEach(key => {
const doc = _cache[key];
if (doc instanceof Doc) strings.push(StrCast(doc.author) + " " + StrCast(doc.title) + " " + StrCast(Doc.GetT(doc, "title", "string", true)));
});
- strings.sort().forEach((str, i) => console.log(i.toString() + " " + str));
+ print && strings.sort().forEach((str, i) => console.log(i.toString() + " " + str));
rp.post(Utils.prepend("/setCacheDocumentIds"), {
body: {
cacheDocumentIds: Array.from(Object.keys(_cache)).join(";"),
@@ -348,7 +348,6 @@ export namespace DocServer {
}
if (requestedIds.length) {
-
// 2) synchronously, we emit a single callback to the server requesting the serialized (i.e. represented by a string)
// fields for the given ids. This returns a promise, which, when resolved, indicates that all the JSON serialized versions of
// the fields have been returned from the server
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 45c465d84..d7c9af1a3 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -236,6 +236,8 @@ class EmptyBox {
export namespace Docs {
+ export let newAccount: boolean = false;
+
export namespace Prototypes {
type LayoutSource = { LayoutString: (key: string) => string };
@@ -392,7 +394,7 @@ export namespace Docs {
// non-guid string ids for each document prototype
const prototypeIds = Object.values(DocumentType).filter(type => type !== DocumentType.NONE).map(type => type + suffix);
// fetch the actual prototype documents from the server
- const actualProtos = await DocServer.GetRefFields(prototypeIds);
+ const actualProtos = Docs.newAccount ? {} : await DocServer.GetRefFields(prototypeIds);
// update this object to include any default values: DocumentOptions for all prototypes
prototypeIds.map(id => {
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index dcbeba8cd..f43b6df44 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -878,7 +878,7 @@ export class CurrentUserUtils {
// Sharing sidebar is where shared documents are contained
static async setupSharingSidebar(doc: Doc, sharingDocumentId: string, linkDatabaseId: string) {
if (doc.myLinkDatabase === undefined) {
- let linkDocs = await DocServer.GetRefField(linkDatabaseId);
+ let linkDocs = Docs.newAccount ? undefined : await DocServer.GetRefField(linkDatabaseId);
if (!linkDocs) {
linkDocs = new Doc(linkDatabaseId, true);
(linkDocs as Doc).author = Doc.CurrentUserEmail;
@@ -888,7 +888,7 @@ export class CurrentUserUtils {
doc.myLinkDatabase = new PrefetchProxy(linkDocs);
}
if (doc.mySharedDocs === undefined) {
- let sharedDocs = await DocServer.GetRefField(sharingDocumentId + "outer");
+ let sharedDocs = Docs.newAccount ? undefined : await DocServer.GetRefField(sharingDocumentId + "outer");
if (!sharedDocs) {
sharedDocs = Docs.Create.StackingDocument([], {
title: "My SharedDocs", childDropAction: "alias", system: true, contentPointerEvents: "none", childLimitHeight: 0, _yMargin: 50, _gridGap: 15,
@@ -1024,6 +1024,7 @@ export class CurrentUserUtils {
// Doc.AddDocToList(Cast(doc["template-notes"], Doc, null), "data", deleg);
// }
// });
+ setTimeout(() => DocServer.UPDATE_SERVER_CACHE(), 2500);
return doc;
}
@@ -1047,8 +1048,12 @@ export class CurrentUserUtils {
await rp.get(Utils.prepend("/getUserDocumentIds")).then(ids => {
const { userDocumentId, sharingDocumentId, linkDatabaseId } = JSON.parse(ids);
if (userDocumentId !== "guest") {
- return DocServer.GetRefField(userDocumentId).then(async field =>
- this.updateUserDocument(Doc.SetUserDoc(field instanceof Doc ? field : new Doc(userDocumentId, true)), sharingDocumentId, linkDatabaseId));
+ return DocServer.GetRefField(userDocumentId).then(async field => {
+ Docs.newAccount = !(field instanceof Doc);
+ await Docs.Prototypes.initialize();
+ const userDoc = Docs.newAccount ? new Doc(userDocumentId, true) : field as Doc;
+ return this.updateUserDocument(Doc.SetUserDoc(userDoc), sharingDocumentId, linkDatabaseId);
+ });
} else {
throw new Error("There should be a user id! Why does Dash think there isn't one?");
}
@@ -1108,7 +1113,7 @@ export class CurrentUserUtils {
const response = await fetch(upload, { method: "POST", body: formData });
const json = await response.json();
if (json !== "error") {
- const doc = await DocServer.GetRefField(json);
+ const doc = Docs.newAccount ? undefined : await DocServer.GetRefField(json);
if (doc instanceof Doc) {
setTimeout(() => SearchUtil.Search(`{!join from=id to=proto_i}id:link*`, true, {}).then(docs =>
docs.docs.forEach(d => LinkManager.Instance.addLink(d))), 2000); // need to give solr some time to update so that this query will find any link docs we've added.
diff --git a/src/client/views/GlobalKeyHandler.ts b/src/client/views/GlobalKeyHandler.ts
index 89292a445..fb360ee26 100644
--- a/src/client/views/GlobalKeyHandler.ts
+++ b/src/client/views/GlobalKeyHandler.ts
@@ -56,7 +56,7 @@ export class KeyManager {
public handle = action(async (e: KeyboardEvent) => {
if (e.key?.toLowerCase() === "shift" && e.ctrlKey && e.altKey) KeyManager.Instance.ShiftPressed = true;
- if (!Doc.UserDoc().noviceMode && e.key.toLocaleLowerCase() === "shift") DocServer.PRINT_CACHE();
+ if (!Doc.UserDoc().noviceMode && e.key.toLocaleLowerCase() === "shift") DocServer.UPDATE_SERVER_CACHE(true);
const keyname = e.key && e.key.toLowerCase();
this.handleGreedy(keyname);
diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx
index 3889e2d28..c256d2ebb 100644
--- a/src/client/views/Main.tsx
+++ b/src/client/views/Main.tsx
@@ -13,10 +13,11 @@ AssignAllExtensions();
(async () => {
window.location.search.includes("safe") && CollectionView.SetSafeMode(true);
const info = await CurrentUserUtils.loadCurrentUser();
- await Docs.Prototypes.initialize();
if (info.id !== "__guest__") {
// a guest will not have an id registered
await CurrentUserUtils.loadUserDocument(info.id);
+ } else {
+ await Docs.Prototypes.initialize();
}
document.getElementById('root')!.addEventListener('wheel', event => {
if (event.ctrlKey) {
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index bc00e93a5..3872cbb18 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -506,7 +506,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
Logoff
</div>
</div>
- <div className="searchBox-lozenge" onClick={() => DocServer.PRINT_CACHE()}>
+ <div className="searchBox-lozenge" onClick={() => DocServer.UPDATE_SERVER_CACHE()}>
{`UI project`}
</div>
<div className="searchBox-lozenge-dashboard" >
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,