Skip to content

Commit

Permalink
Fix requests for deleted users
Browse files Browse the repository at this point in the history
When users are requested from the authorship which no longer exist, they
shouldn't cause a 500.

Signed-off-by: Sheogorath <[email protected]>
  • Loading branch information
SISheogorath committed May 25, 2018
1 parent 4229084 commit e31d204
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 7 additions & 5 deletions lib/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit e31d204

Please sign in to comment.