From e31d204d747c6db0b39288fa55269e8a3311525c Mon Sep 17 00:00:00 2001 From: Sheogorath Date: Fri, 25 May 2018 16:15:10 +0200 Subject: [PATCH] Fix requests for deleted users When users are requested from the authorship which no longer exist, they shouldn't cause a 500. Signed-off-by: Sheogorath --- lib/models/user.js | 3 +++ lib/realtime.js | 12 +++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/models/user.js b/lib/models/user.js index 4c823355..62ed5cc7 100644 --- a/lib/models/user.js +++ b/lib/models/user.js @@ -66,6 +66,9 @@ module.exports = function (sequelize, DataTypes) { }) }, getProfile: function (user) { + if (!user) { + return null + } return user.profile ? User.parseProfile(user.profile) : (user.email ? User.parseProfileByEmail(user.email) : null) }, parseProfile: function (profile) { diff --git a/lib/realtime.js b/lib/realtime.js index 070bde2d..f6c62d4e 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -486,11 +486,13 @@ function startConnection (socket) { for (var i = 0; i < note.authors.length; i++) { var author = note.authors[i] var profile = models.User.getProfile(author.user) - authors[author.userId] = { - userid: author.userId, - color: author.color, - photo: profile.photo, - name: profile.name + if (profile) { + authors[author.userId] = { + userid: author.userId, + color: author.color, + photo: profile.photo, + name: profile.name + } } }