aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/CurrentUserUtils.ts26
-rw-r--r--src/client/util/GroupManager.tsx8
-rw-r--r--src/client/util/LinkManager.ts12
-rw-r--r--src/client/util/SharingManager.tsx9
4 files changed, 35 insertions, 20 deletions
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index 694982fea..7535d7c24 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -1,6 +1,6 @@
import { computed, observable, reaction } from "mobx";
import * as rp from 'request-promise';
-import { DataSym, Doc, DocListCast, DocListCastAsync } from "../../fields/Doc";
+import { DataSym, Doc, DocListCast, DocListCastAsync, AclReadonly } from "../../fields/Doc";
import { Id } from "../../fields/FieldSymbols";
import { List } from "../../fields/List";
import { PrefetchProxy } from "../../fields/Proxy";
@@ -541,9 +541,9 @@ export class CurrentUserUtils {
})) as any as Doc;
}
}
- static async setupMenuPanel(doc: Doc, sharingDocumentId: string) {
+ static async setupMenuPanel(doc: Doc, sharingDocumentId: string, linkDatabaseId: string) {
if (doc.menuStack === undefined) {
- await this.setupSharingSidebar(doc, sharingDocumentId); // sets up the right sidebar collection for mobile upload documents and sharing
+ await this.setupSharingSidebar(doc, sharingDocumentId, linkDatabaseId); // sets up the right sidebar collection for mobile upload documents and sharing
const menuBtns = (await CurrentUserUtils.menuBtnDescriptions(doc)).map(({ title, target, icon, click, watchedDocuments }) =>
Docs.Create.FontIconDocument({
icon,
@@ -876,7 +876,16 @@ export class CurrentUserUtils {
}
// Sharing sidebar is where shared documents are contained
- static async setupSharingSidebar(doc: Doc, sharingDocumentId: string) {
+ static async setupSharingSidebar(doc: Doc, sharingDocumentId: string, linkDatabaseId: string) {
+ if (doc.myLinkDatabase === undefined) {
+ let linkDocs = await DocServer.GetRefField(linkDatabaseId);
+ if (!linkDocs) {
+ linkDocs = new Doc(linkDatabaseId, true);
+ (linkDocs as Doc).data = new List<Doc>([]);
+ (linkDocs as Doc)["acl-Public"] = SharingPermissions.Add;
+ }
+ doc.myLinkDatabase = new PrefetchProxy(linkDocs);
+ }
if (doc.mySharedDocs === undefined) {
let sharedDocs = await DocServer.GetRefField(sharingDocumentId + "outer");
if (!sharedDocs) {
@@ -956,7 +965,7 @@ export class CurrentUserUtils {
return doc.clickFuncs as Doc;
}
- static async updateUserDocument(doc: Doc, sharingDocumentId: string) {
+ static async updateUserDocument(doc: Doc, sharingDocumentId: string, linkDatabaseId: string) {
if (!doc.globalGroupDatabase) doc.globalGroupDatabase = Docs.Prototypes.MainGroupDocument();
const groups = await DocListCastAsync((doc.globalGroupDatabase as Doc).data);
reaction(() => DateCast((doc.globalGroupDatabase as Doc).lastModified),
@@ -996,9 +1005,8 @@ export class CurrentUserUtils {
this.setupOverlays(doc); // documents in overlay layer
this.setupDockedButtons(doc); // the bottom bar of font icons
await this.setupSidebarButtons(doc); // the pop-out left sidebar of tools/panels
- await this.setupMenuPanel(doc, sharingDocumentId);
+ await this.setupMenuPanel(doc, sharingDocumentId, linkDatabaseId);
if (!doc.globalScriptDatabase) doc.globalScriptDatabase = Docs.Prototypes.MainScriptDocument();
- if (!doc.myLinkDatabase) doc.myLinkDatabase = new List([]);
setTimeout(() => this.setupDefaultPresentation(doc), 0); // presentation that's initially triggered
@@ -1036,10 +1044,10 @@ export class CurrentUserUtils {
public static async loadUserDocument(id: string) {
this.curr_id = id;
await rp.get(Utils.prepend("/getUserDocumentIds")).then(ids => {
- const { userDocumentId, sharingDocumentId } = JSON.parse(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));
+ this.updateUserDocument(Doc.SetUserDoc(field instanceof Doc ? field : new Doc(userDocumentId, true)), sharingDocumentId, linkDatabaseId));
} else {
throw new Error("There should be a user id! Why does Dash think there isn't one?");
}
diff --git a/src/client/util/GroupManager.tsx b/src/client/util/GroupManager.tsx
index cc1d45a58..6458de0ed 100644
--- a/src/client/util/GroupManager.tsx
+++ b/src/client/util/GroupManager.tsx
@@ -145,8 +145,8 @@ export class GroupManager extends React.Component<{}> {
*/
addGroup(groupDoc: Doc): boolean {
if (this.GroupManagerDoc) {
- this.GroupManagerDoc.lastModified = new DateField;
Doc.AddDocToList(this.GroupManagerDoc, "data", groupDoc);
+ this.GroupManagerDoc.lastModified = new DateField;
return true;
}
return false;
@@ -160,7 +160,6 @@ export class GroupManager extends React.Component<{}> {
deleteGroup(group: Doc): boolean {
if (group) {
if (this.GroupManagerDoc && this.hasEditAccess(group)) {
- this.GroupManagerDoc.lastModified = new DateField;
Doc.RemoveDocFromList(this.GroupManagerDoc, "data", group);
SharingManager.Instance.removeGroup(group);
const members = JSON.parse(StrCast(group.members));
@@ -168,6 +167,7 @@ export class GroupManager extends React.Component<{}> {
const index = DocListCast(this.GroupManagerDoc.data).findIndex(grp => grp === group);
index !== -1 && Cast(this.GroupManagerDoc.data, listSpec(Doc), [])?.splice(index, 1);
}
+ this.GroupManagerDoc.lastModified = new DateField;
if (group === this.currentGroup) {
this.currentGroup = undefined;
}
@@ -187,8 +187,8 @@ export class GroupManager extends React.Component<{}> {
const memberList = JSON.parse(StrCast(groupDoc.members));
!memberList.includes(email) && memberList.push(email);
groupDoc.members = JSON.stringify(memberList);
- this.GroupManagerDoc && (this.GroupManagerDoc.lastModified = new DateField);
SharingManager.Instance.shareWithAddedMember(groupDoc, email);
+ this.GroupManagerDoc && (this.GroupManagerDoc.lastModified = new DateField);
}
}
@@ -204,8 +204,8 @@ export class GroupManager extends React.Component<{}> {
if (index !== -1) {
const user = memberList.splice(index, 1)[0];
groupDoc.members = JSON.stringify(memberList);
- this.GroupManagerDoc && (this.GroupManagerDoc.lastModified = new DateField);
SharingManager.Instance.removeMember(groupDoc, email);
+ this.GroupManagerDoc && (this.GroupManagerDoc.lastModified = new DateField);
}
}
}
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index 56b6cb8a9..0456b4029 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -36,17 +36,21 @@ export class LinkManager {
public getAllLinks(): Doc[] {
- const lset = new Set<Doc>(DocListCast(Doc.UserDoc().myLinkDatabase));
- SharingManager.Instance.users.forEach(user => DocListCast(user.sharingDoc.myLinkDatabase).map(lset.add));
+ const lset = new Set<Doc>(DocListCast(Doc.LinkDBDoc().data));
+ SharingManager.Instance.users.forEach(user => {
+ DocListCast((user.linkDatabase as Doc)?.data).map(doc => {
+ lset.add(doc);
+ });
+ });
return Array.from(lset);
}
public addLink(linkDoc: Doc): boolean {
- return Doc.AddDocToList(Doc.UserDoc(), "myLinkDatabase", linkDoc);
+ return Doc.AddDocToList(Doc.LinkDBDoc(), "data", linkDoc);
}
public deleteLink(linkDoc: Doc): boolean {
- return Doc.RemoveDocFromList(Doc.UserDoc(), "myLinkDatabase", linkDoc);
+ return Doc.RemoveDocFromList(Doc.LinkDBDoc(), "data", linkDoc);
}
// finds all links that contain the given anchor
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index 16bcd46c8..271face98 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -22,11 +22,11 @@ import "./SharingManager.scss";
import { SelectionManager } from "./SelectionManager";
import { intersection } from "lodash";
import { SearchBox } from "../views/search/SearchBox";
-import { listSpec } from "../../fields/Schema";
export interface User {
email: string;
sharingDocumentId: string;
+ linkDatabaseId: string;
}
/**
@@ -53,6 +53,7 @@ const storage = "data";
interface ValidatedUser {
user: User; // database minimal info to identify / communicate with a user (email, sharing doc id)
sharingDoc: Doc; // document to share/message another user
+ linkDatabase: Doc;
userColor: string; // stored on the sharinDoc, extracted for convenience?
}
@@ -130,8 +131,10 @@ export class SharingManager extends React.Component<{}> {
const isCandidate = user.email !== Doc.CurrentUserEmail;
if (isCandidate) {
const sharingDoc = await DocServer.GetRefField(user.sharingDocumentId);
- if (sharingDoc instanceof Doc) {
- sharingDocs.push({ user, sharingDoc, userColor: StrCast(sharingDoc.color) });
+ const linkDatabase = await DocServer.GetRefField(user.linkDatabaseId);
+ if (sharingDoc instanceof Doc && linkDatabase instanceof Doc) {
+ await DocListCastAsync(linkDatabase.data);
+ sharingDocs.push({ user, sharingDoc, linkDatabase, userColor: StrCast(sharingDoc.color) });
}
}
});