Class: NotificationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/notifications_controller.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Method Summary (collapse)

Instance Method Details

- (Object) index



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/notifications_controller.rb', line 24

def index
  conditions = {:recipient_id => current_user.id}
  page = params[:page] || 1
  per_page = params[:per_page] || 25
  @notifications = WillPaginate::Collection.create(page, per_page, Notification.where(conditions).count ) do |pager|
    result = Notification.find(:all,
                               :conditions => conditions,
                               :order => 'created_at desc',
                               :include => [:target, {:actors => :profile}],
                               :limit => pager.per_page,
                               :offset => pager.offset
                              )

    pager.replace(result)
  end
  @notifications.each do |n|
    n.note_html = render_to_string( :partial => 'notify_popup_item', :locals => { :n => n } )
  end
  @group_days = @notifications.group_by{|note| I18n.l(note.created_at, :format => I18n.t('date.formats.fullmonth_day')) }

  @unread_notification_count = current_user.unread_notifications.count

  respond_to do |format|
    format.html
    format.xml { render :xml => @notifications.to_xml }
    format.json { render :json => @notifications.to_json }
  end

end

- (Object) read_all



54
55
56
57
58
59
60
61
62
# File 'app/controllers/notifications_controller.rb', line 54

def read_all
  Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
  respond_to do |format|
    format.html { redirect_to stream_path }
    format.mobile{ redirect_to stream_path}
    format.xml { render :xml => {}.to_xml }
    format.json { render :json => {}.to_json }
  end
end

- (Object) update



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/notifications_controller.rb', line 8

def update
  note = Notification.where(:recipient_id => current_user.id, :id => params[:id]).first
  if note
    note.set_read_state(params[:set_unread] != "true" )

    respond_to do |format|
      format.json { render :json => { :guid => note.id, :unread => note.unread } }
    end

  else
    respond_to do |format|
      format.json { render :json => {}.to_json }
    end
  end
end