diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/DocServer.ts | 7 | ||||
-rw-r--r-- | src/client/util/CurrentUserUtils.ts | 13 | ||||
-rw-r--r-- | src/client/views/Main.tsx | 16 | ||||
-rw-r--r-- | src/debug/Repl.tsx | 2 | ||||
-rw-r--r-- | src/debug/Viewer.tsx | 2 | ||||
-rw-r--r-- | src/server/ApiManagers/UserManager.ts | 21 | ||||
-rw-r--r-- | src/server/authentication/AuthenticationManager.ts | 3 | ||||
-rw-r--r-- | src/server/authentication/DashUserModel.ts | 2 |
8 files changed, 47 insertions, 19 deletions
diff --git a/src/client/DocServer.ts b/src/client/DocServer.ts index 9683eab45..d936f6e2a 100644 --- a/src/client/DocServer.ts +++ b/src/client/DocServer.ts @@ -10,6 +10,7 @@ import MobileInkOverlay from '../mobile/MobileInkOverlay'; import { runInAction } from 'mobx'; import { ObjectField } from '../fields/ObjectField'; import { StrCast } from '../fields/Types'; +import * as rp from 'request-promise'; /** * This class encapsulates the transfer and cross-client synchronization of @@ -34,6 +35,12 @@ export namespace DocServer { 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)); + rp.post(Utils.prepend("/setCacheDocumentIds"), { + body: { + cacheDocumentIds: Array.from(Object.keys(_cache)).join(";"), + }, + json: true, + }); } export let _socket: SocketIOClient.Socket; // this client's distinct GUID created at initialization diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index 1096b8e5f..d011d7b09 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -31,8 +31,10 @@ import { SearchUtil } from "./SearchUtil"; import { SelectionManager } from "./SelectionManager"; import { UndoManager } from "./UndoManager"; import { SharingPermissions } from "../../fields/util"; +import { Networking } from "../Network"; +export let resolvedPorts: { server: number, socket: number }; const headerViewVersion = "0.1"; export class CurrentUserUtils { private static curr_id: string; @@ -1009,9 +1011,13 @@ export class CurrentUserUtils { } public static async loadCurrentUser() { - return rp.get(Utils.prepend("/getCurrentUser")).then(response => { + return rp.get(Utils.prepend("/getCurrentUser")).then(async response => { if (response) { - const result: { id: string, email: string } = JSON.parse(response); + const result: { id: string, email: string, cacheDocumentIds: string } = JSON.parse(response); + Doc.CurrentUserEmail = result.email; + resolvedPorts = JSON.parse(await Networking.FetchFromServer("/resolvedPorts")); + DocServer.init(window.location.protocol, window.location.hostname, resolvedPorts.socket, result.email); + result.cacheDocumentIds && (await DocServer.GetRefFields(result.cacheDocumentIds.split(";"))); return result; } else { throw new Error("There should be a user! Why does Dash think there isn't one?"); @@ -1019,9 +1025,8 @@ export class CurrentUserUtils { }); } - public static async loadUserDocument({ id, email }: { id: string, email: string }) { + public static async loadUserDocument(id: string) { this.curr_id = id; - Doc.CurrentUserEmail = email; await rp.get(Utils.prepend("/getUserDocumentIds")).then(ids => { const { userDocumentId, sharingDocumentId } = JSON.parse(ids); if (userDocumentId !== "guest") { diff --git a/src/client/views/Main.tsx b/src/client/views/Main.tsx index 77e37834d..a5352c94a 100644 --- a/src/client/views/Main.tsx +++ b/src/client/views/Main.tsx @@ -1,26 +1,20 @@ -import { MainView } from "./MainView"; -import { Docs } from "../documents/Documents"; -import { CurrentUserUtils } from "../util/CurrentUserUtils"; -import * as ReactDOM from 'react-dom'; import * as React from 'react'; -import { DocServer } from "../DocServer"; +import * as ReactDOM from 'react-dom'; import { AssignAllExtensions } from "../../extensions/General/Extensions"; -import { Networking } from "../Network"; +import { Docs } from "../documents/Documents"; +import { CurrentUserUtils } from "../util/CurrentUserUtils"; import { CollectionView } from "./collections/CollectionView"; +import { MainView } from "./MainView"; AssignAllExtensions(); -export let resolvedPorts: { server: number, socket: number }; - (async () => { window.location.search.includes("safe") && CollectionView.SetSafeMode(true); const info = await CurrentUserUtils.loadCurrentUser(); - resolvedPorts = JSON.parse(await Networking.FetchFromServer("/resolvedPorts")); - DocServer.init(window.location.protocol, window.location.hostname, resolvedPorts.socket, info.email); await Docs.Prototypes.initialize(); if (info.id !== "__guest__") { // a guest will not have an id registered - await CurrentUserUtils.loadUserDocument(info); + await CurrentUserUtils.loadUserDocument(info.id); } document.getElementById('root')!.addEventListener('wheel', event => { if (event.ctrlKey) { diff --git a/src/debug/Repl.tsx b/src/debug/Repl.tsx index be53c0b9b..1b12e208c 100644 --- a/src/debug/Repl.tsx +++ b/src/debug/Repl.tsx @@ -7,7 +7,7 @@ import { makeInterface } from '../fields/Schema'; import { ObjectField } from '../fields/ObjectField'; import { RefField } from '../fields/RefField'; import { DocServer } from '../client/DocServer'; -import { resolvedPorts } from '../client/views/Main'; +import { resolvedPorts } from '../client/util/CurrentUserUtils'; @observer class Repl extends React.Component { diff --git a/src/debug/Viewer.tsx b/src/debug/Viewer.tsx index 0ca067ed3..bebd71dcf 100644 --- a/src/debug/Viewer.tsx +++ b/src/debug/Viewer.tsx @@ -14,7 +14,7 @@ import { RichTextField } from '../fields/RichTextField'; import { DateField } from '../fields/DateField'; import { ScriptField } from '../fields/ScriptField'; import CursorField from '../fields/CursorField'; -import { resolvedPorts } from '../client/views/Main'; +import { resolvedPorts } from '../client/util/CurrentUserUtils'; DateField; URLField; diff --git a/src/server/ApiManagers/UserManager.ts b/src/server/ApiManagers/UserManager.ts index c9ffaff4c..e5c0f3827 100644 --- a/src/server/ApiManagers/UserManager.ts +++ b/src/server/ApiManagers/UserManager.ts @@ -26,6 +26,25 @@ export default class UserManager extends ApiManager { }); register({ + method: Method.POST, + subscription: "/setCacheDocumentIds", + secureHandler: async ({ user, req, res }) => { + const result: any = {}; + user.cacheDocumentIds = req.body.cacheDocumentIds; + user.save(err => { + if (err) { + result.error = [{ msg: "Error while caching documents" }]; + } + }); + + // Database.Instance.update(id, { "$set": { "fields.cacheDocumentIds": cacheDocumentIds } }, e => { + // console.log(e); + // }); + res.send(result); + } + }); + + register({ method: Method.GET, subscription: "/getUserDocumentIds", secureHandler: ({ res, user }) => res.send({ userDocumentId: user.userDocumentId, sharingDocumentId: user.sharingDocumentId }) @@ -40,7 +59,7 @@ export default class UserManager extends ApiManager { register({ method: Method.GET, subscription: "/getCurrentUser", - secureHandler: ({ res, user: { _id, email } }) => res.send(JSON.stringify({ id: _id, email })), + secureHandler: ({ res, user: { _id, email, cacheDocumentIds } }) => res.send(JSON.stringify({ id: _id, email, cacheDocumentIds })), publicHandler: ({ res }) => res.send(JSON.stringify({ id: "__guest__", email: "" })) }); diff --git a/src/server/authentication/AuthenticationManager.ts b/src/server/authentication/AuthenticationManager.ts index 36363e3cf..84abd41a2 100644 --- a/src/server/authentication/AuthenticationManager.ts +++ b/src/server/authentication/AuthenticationManager.ts @@ -48,7 +48,8 @@ export let postSignup = (req: Request, res: Response, next: NextFunction) => { email, password, userDocumentId: Utils.GenerateGuid(), - sharingDocumentId: Utils.GenerateGuid() + sharingDocumentId: Utils.GenerateGuid(), + cacheDocumentIds: "" } as Partial<DashUserModel>; const user = new User(model); diff --git a/src/server/authentication/DashUserModel.ts b/src/server/authentication/DashUserModel.ts index 0bdc25644..4f2856a78 100644 --- a/src/server/authentication/DashUserModel.ts +++ b/src/server/authentication/DashUserModel.ts @@ -11,6 +11,7 @@ export type DashUserModel = mongoose.Document & { userDocumentId: string; sharingDocumentId: string; + cacheDocumentIds: string; profile: { name: string, @@ -38,6 +39,7 @@ const userSchema = new mongoose.Schema({ userDocumentId: String, // id that identifies a document which hosts all of a user's account data sharingDocumentId: String, // id that identifies a document that stores documents shared to a user, their user color, and any additional info needed to communicate between users + cacheDocumentIds: String, facebook: String, twitter: String, |