diff options
author | Sheogorath | 2018-05-25 16:15:10 +0200 |
---|---|---|
committer | Sheogorath | 2018-05-25 16:15:18 +0200 |
commit | e31d204d747c6db0b39288fa55269e8a3311525c (patch) | |
tree | 56daa065a2815c0c09dcd7149d6d5cd999cbad2f | |
parent | 4229084c6211db3d22cd9abec99b957725650b9e (diff) |
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 <sheogorath@shivering-isles.com>
-rw-r--r-- | lib/models/user.js | 3 | ||||
-rw-r--r-- | 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 + } } } |