Newer
Older
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class NotificationsController < VannaController
Sarah Mei
a validé
include ActionController::MobileFu
has_mobile_fu
def update(opts=params)
note = Notification.where(:recipient_id => current_user.id, :id => opts[:id]).first
Raphael Sofaer
a validé
conditions = {:recipient_id => current_user.id}
per_page = opts[:per_page] || 25
notifications = WillPaginate::Collection.create(page, per_page, Notification.where(conditions).count ) do |pager|
Raphael Sofaer
a validé
result = Notification.find(:all,
:conditions => conditions,
:order => 'created_at desc',
:include => [:target, {:actors => :profile}],
:limit => pager.per_page,
Raphael Sofaer
a validé
:offset => pager.offset
)
pager.replace(result)
end
notifications.each do |n|
n[:actors] = n.actors
n[:translation_key] = n.popup_translation_key
n[:target] = n.translation_key == "notifications.mentioned" ? n.target.post : n.target
group_days = notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) }
{:group_days => group_days, :notifications => notifications}
Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
Response.new(:status => 302, :location => aspects_path)
end