diff --git a/app/models/user.rb b/app/models/user.rb index bd058f6e58a..f188ec78f51 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1790,14 +1790,17 @@ class User < ActiveRecord::Base end def set_status!(description, emoji, ends_at = nil) - status = { description: description, emoji: emoji, set_at: Time.zone.now, ends_at: ends_at } - - if user_status - user_status.update!(status) - else - self.user_status = UserStatus.create!(status) - end + status = { + description: description, + emoji: emoji, + set_at: Time.zone.now, + ends_at: ends_at, + user_id: id, + } + validate_status!(status) + UserStatus.upsert(status) + reload_user_status publish_user_status(user_status) end @@ -2175,6 +2178,10 @@ class User < ActiveRecord::Base ) SQL end + + def validate_status!(status) + UserStatus.new(status).validate! + end end # == Schema Information