mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 02:09:54 +08:00
correctly handle empty case
This commit is contained in:
parent
e8aa85d783
commit
bf957513ec
|
@ -91,7 +91,7 @@ class Notification < ActiveRecord::Base
|
||||||
|
|
||||||
def self.recent_report(user, count = nil)
|
def self.recent_report(user, count = nil)
|
||||||
|
|
||||||
notifications = user.notifications.recent(count).includes(:topic)
|
notifications = user.notifications.recent(count).includes(:topic).to_a
|
||||||
|
|
||||||
if notifications.present?
|
if notifications.present?
|
||||||
notifications += user.notifications
|
notifications += user.notifications
|
||||||
|
@ -99,17 +99,19 @@ class Notification < ActiveRecord::Base
|
||||||
.where(read: false, notification_type: Notification.types[:private_message])
|
.where(read: false, notification_type: Notification.types[:private_message])
|
||||||
.where('id < ?', notifications.last.id)
|
.where('id < ?', notifications.last.id)
|
||||||
.limit(count)
|
.limit(count)
|
||||||
end
|
|
||||||
|
|
||||||
notifications.sort do |x,y|
|
notifications.sort do |x,y|
|
||||||
if x.unread_pm? && !y.unread_pm?
|
if x.unread_pm? && !y.unread_pm?
|
||||||
-1
|
-1
|
||||||
elsif y.unread_pm? && !x.unread_pm?
|
elsif y.unread_pm? && !x.unread_pm?
|
||||||
1
|
1
|
||||||
else
|
else
|
||||||
y.created_at <=> x.created_at
|
y.created_at <=> x.created_at
|
||||||
end
|
end
|
||||||
end.take(count)
|
end.take(count)
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user