Skip to content
Extraits de code Groupes Projets
notifications_controller.rb 2,19 ko
Newer Older
  • Learn to ignore specific revisions
  • danielgrippi's avatar
    danielgrippi a validé
    #   Copyright (c) 2010-2011, Diaspora Inc.  This file is
    
    maxwell's avatar
    maxwell a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    #   the COPYRIGHT file.
    
    
    class NotificationsController < ApplicationController
    
      before_filter :authenticate_user!
    
    maxwell's avatar
    maxwell a validé
    
    
      def update
        note = Notification.where(:recipient_id => current_user.id, :id => params[:id]).first
    
    maxwell's avatar
    maxwell a validé
        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
    
    
    maxwell's avatar
    maxwell a validé
        else
    
          respond_to do |format|
            format.json { render :json => {}.to_json }
          end
    
    maxwell's avatar
    maxwell a validé
        end
      end
    
    
        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}],
    
        if request.format != :json
          @notifications.each do |n|
            n[:note_html] = render_to_string( :partial => 'notify_popup_item', :locals => { :n => n } )
          end
    
        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 }
    
    Dan Hansen's avatar
    Dan Hansen a validé
    
    
      def read_all
        Notification.where(:recipient_id => current_user.id).update_all(:unread => false)
        respond_to do |format|
    
          format.html { redirect_to stream_path }
    
    Diaspora Europe's avatar
    Diaspora Europe a validé
          format.mobile{ redirect_to stream_path}
    
          format.xml { render :xml => {}.to_xml }
          format.json { render :json => {}.to_json }
    
    Dan Hansen's avatar
    Dan Hansen a validé
    
    
    maxwell's avatar
    maxwell a validé
    end