// Code that is shared between client and server, i.e. sent to both. // main.js is loaded last: // http://docs.meteor.com/#/full/structuringyourapp // Methods that provide write access to the data. Meteor.methods({ addDoc: function () { Meteor._debug("addDoc, this", this); // Not logged-in. if (!this.userId) { return; } else { let doc = { owner: this.userId, createdOn: new Date(), title: "my new doc" }; const docid = Documents.insert(doc); return docid; } }, // Changing doc privacy settings. updateDocPrivacy: function (doc) { Meteor._debug("updatedocPrivacy", this.userId, doc) if (!this.userId) { return; } let res = Documents.update({ _id: doc._id, owner: this.userId }, { $set: { isPrivate: doc.isPrivate } }); Meteor._debug("update", res); }, // Adding editors to a document. addEditingUser: function (docid) { let doc = Documents.findOne({ _id: docid }); if (!doc) { // No doc: give up. return; } if (!this.userId) { // No logged-in user: give up. return; } // Now I have a doc and possibly a user. let user = Meteor.user().profile; let eUsers = EditingUsers.findOne({ docId: doc._id }); // No editing users have been stored yet. if (!eUsers) { eUsers = { docId: doc._id, users: {} }; } user.lastEdit = new Date(); eUsers.users[this.userId] = user; // Upsert: insert or update if filter matches. EditingUsers.upsert({ _id: eUsers._id }, eUsers); } });