Skip to content

Commit e31d204

Browse files
committed
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>
1 parent 4229084 commit e31d204

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

lib/models/user.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ module.exports = function (sequelize, DataTypes) {
6666
})
6767
},
6868
getProfile: function (user) {
69+
if (!user) {
70+
return null
71+
}
6972
return user.profile ? User.parseProfile(user.profile) : (user.email ? User.parseProfileByEmail(user.email) : null)
7073
},
7174
parseProfile: function (profile) {

lib/realtime.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,13 @@ function startConnection (socket) {
486486
for (var i = 0; i < note.authors.length; i++) {
487487
var author = note.authors[i]
488488
var profile = models.User.getProfile(author.user)
489-
authors[author.userId] = {
490-
userid: author.userId,
491-
color: author.color,
492-
photo: profile.photo,
493-
name: profile.name
489+
if (profile) {
490+
authors[author.userId] = {
491+
userid: author.userId,
492+
color: author.color,
493+
photo: profile.photo,
494+
name: profile.name
495+
}
494496
}
495497
}
496498

0 commit comments

Comments
 (0)