Compare commits

...

4 Commits

2 changed files with 28 additions and 27 deletions

View File

@ -94,7 +94,7 @@ exports.getColorPalette = () => [
* Checks if the author exists * Checks if the author exists
*/ */
exports.doesAuthorExist = async (authorID) => { exports.doesAuthorExist = async (authorID) => {
const author = await db.get(`globalAuthor:${authorID}`); const author = await exports.getAuthor(authorID);
return author != null; return author != null;
}; };
@ -107,6 +107,10 @@ exports.doesAuthorExists = exports.doesAuthorExist;
* @param {String} token The token * @param {String} token The token
*/ */
exports.getAuthor4Token = async (token) => { exports.getAuthor4Token = async (token) => {
// e.g. in case of an export of a public pad, a token is not needed
if (token == null) {
return;
}
const author = await mapAuthorWithDBKey('token2author', token); const author = await mapAuthorWithDBKey('token2author', token);
// return only the sub value authorID // return only the sub value authorID
@ -181,41 +185,42 @@ exports.createAuthor = async (name) => {
/** /**
* Returns the Author Obj of the author * Returns the Author Obj of the author
* @param {String} author The id of the author * @param {String} authorID The id of the author
*/ */
exports.getAuthor = async (author) => await db.get(`globalAuthor:${author}`); exports.getAuthor = async (authorID) => await db.get(`globalAuthor:${authorID}`);
/** /**
* Returns the color Id of the author * Returns the color Id of the author
* @param {String} author The id of the author * @param {String} authorID The id of the author
*/ */
exports.getAuthorColorId = async (author) => await db.getSub(`globalAuthor:${author}`, ['colorId']); exports.getAuthorColorId = async (authorID) => await db.getSub(
`globalAuthor:${authorID}`, ['colorId']);
/** /**
* Sets the color Id of the author * Sets the color Id of the author
* @param {String} author The id of the author * @param {String} authorID The id of the author
* @param {String} colorId The color id of the author * @param {String} colorId The color id of the author
*/ */
exports.setAuthorColorId = async (author, colorId) => await db.setSub( exports.setAuthorColorId = async (authorID, colorId) => await db.setSub(
`globalAuthor:${author}`, ['colorId'], colorId); `globalAuthor:${authorID}`, ['colorId'], colorId);
/** /**
* Returns the name of the author * Returns the name of the author
* @param {String} author The id of the author * @param {String} authorID The id of the author
*/ */
exports.getAuthorName = async (author) => await db.getSub(`globalAuthor:${author}`, ['name']); exports.getAuthorName = async (authorID) => await db.getSub(`globalAuthor:${authorID}`, ['name']);
/** /**
* Sets the name of the author * Sets the name of the author
* @param {String} author The id of the author * @param {String} authorID The id of the author
* @param {String} name The name of the author * @param {String} name The name of the author
*/ */
exports.setAuthorName = async (author, name) => await db.setSub( exports.setAuthorName = async (authorID, name) => await db.setSub(
`globalAuthor:${author}`, ['name'], name); `globalAuthor:${authorID}`, ['name'], name);
/** /**
* Returns an array of all pads this author contributed to * Returns an array of all pads this author contributed to
* @param {String} author The id of the author * @param {String} authorID The id of the author
*/ */
exports.listPadsOfAuthor = async (authorID) => { exports.listPadsOfAuthor = async (authorID) => {
/* There are two other places where this array is manipulated: /* There are two other places where this array is manipulated:
@ -224,7 +229,7 @@ exports.listPadsOfAuthor = async (authorID) => {
*/ */
// get the globalAuthor // get the globalAuthor
const author = await db.get(`globalAuthor:${authorID}`); const author = await exports.getAuthor(authorID);
if (author == null) { if (author == null) {
// author does not exist // author does not exist
@ -239,12 +244,12 @@ exports.listPadsOfAuthor = async (authorID) => {
/** /**
* Adds a new pad to the list of contributions * Adds a new pad to the list of contributions
* @param {String} author The id of the author * @param {String} authorID The id of the author
* @param {String} padID The id of the pad the author contributes to * @param {String} padID The id of the pad the author contributes to
*/ */
exports.addPad = async (authorID, padID) => { exports.addPad = async (authorID, padID) => {
// get the entry // get the entry
const author = await db.get(`globalAuthor:${authorID}`); const author = await exports.getAuthor(authorID);
if (author == null) return; if (author == null) return;
@ -266,11 +271,11 @@ exports.addPad = async (authorID, padID) => {
/** /**
* Removes a pad from the list of contributions * Removes a pad from the list of contributions
* @param {String} author The id of the author * @param {String} authorID The id of the author
* @param {String} padID The id of the pad the author contributes to * @param {String} padID The id of the pad the author contributes to
*/ */
exports.removePad = async (authorID, padID) => { exports.removePad = async (authorID, padID) => {
const author = await db.get(`globalAuthor:${authorID}`); const author = await exports.getAuthor(authorID);
if (author == null) return; if (author == null) return;

View File

@ -92,15 +92,11 @@ Pad.prototype.appendRevision = async function (aChangeset, author) {
newRevData.meta.atext = this.atext; newRevData.meta.atext = this.atext;
} }
const p = [ this.saveToDatabase();
db.set(`pad:${this.id}:revs:${newRev}`, newRevData), const p_newRevData = db.set(`pad:${this.id}:revs:${newRev}`, newRevData);
this.saveToDatabase(),
];
// set the author to pad // set the author to pad
if (author) { if (author) authorManager.addPad(author, this.id);
p.push(authorManager.addPad(author, this.id));
}
if (this.head === 0) { if (this.head === 0) {
hooks.callAll('padCreate', {pad: this, author}); hooks.callAll('padCreate', {pad: this, author});
@ -108,7 +104,7 @@ Pad.prototype.appendRevision = async function (aChangeset, author) {
hooks.callAll('padUpdate', {pad: this, author, revs: newRev, changeset: aChangeset}); hooks.callAll('padUpdate', {pad: this, author, revs: newRev, changeset: aChangeset});
} }
await Promise.all(p); await p_newRevData;
}; };
// save all attributes to the database // save all attributes to the database