summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/models/note.js2
-rw-r--r--lib/realtime.js30
2 files changed, 20 insertions, 12 deletions
diff --git a/lib/models/note.js b/lib/models/note.js
index a6921267..86112973 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -23,7 +23,7 @@ var logger = require("../logger.js");
var ot = require("../ot/index.js");
// permission types
-var permissionTypes = ["freely", "editable", "limited", "private", "protected", "locked"];
+var permissionTypes = ["freely", "editable", "limited", "locked", "protected", "private"];
module.exports = function (sequelize, DataTypes) {
var Note = sequelize.define("Note", {
diff --git a/lib/realtime.js b/lib/realtime.js
index a3c56c41..21390607 100644
--- a/lib/realtime.js
+++ b/lib/realtime.js
@@ -652,17 +652,25 @@ function operationCallback(socket, operation) {
if (!user) return;
userId = socket.request.user.id;
if (!note.authors[userId]) {
- models.Author.create({
- noteId: noteId,
- userId: userId,
- color: user.color
- }).then(function (author) {
- note.authors[author.userId] = {
- userid: author.userId,
- color: author.color,
- photo: user.photo,
- name: user.name
- };
+ models.Author.findOrCreate({
+ where: {
+ noteId: noteId,
+ userId: userId
+ },
+ defaults: {
+ noteId: noteId,
+ userId: userId,
+ color: user.color
+ }
+ }).spread(function (author, created) {
+ if (author) {
+ note.authors[author.userId] = {
+ userid: author.userId,
+ color: author.color,
+ photo: user.photo,
+ name: user.name
+ };
+ }
}).catch(function (err) {
return logger.error('operation callback failed: ' + err);
});