Commit f217a5bc authored by Steffen van Bergerem's avatar Steffen van Bergerem

Add filters to notifications controller

parent 835608f0
......@@ -32,6 +32,7 @@
* Add permalinks for comments [#4577](https://github.com/diaspora/diaspora/pull/4577)
* New menu for the mobile version [#4673](https://github.com/diaspora/diaspora/pull/4673)
* Added comment count to statistic to enable calculations of posts/comments ratios [#4799](https://github.com/diaspora/diaspora/pull/4799)
* Add filters to notifications controller [#4814](https://github.com/diaspora/diaspora/pull/4814)
# 0.3.0.3
......
......@@ -151,4 +151,10 @@ class ApplicationController < ActionController::Base
gon.preloads = {}
end
def self.use_bootstrap_for *routes
before_filter -> {
@css_framework = :bootstrap
gon.bootstrap = true
}, only: routes.flatten
end
end
......@@ -2,7 +2,7 @@ class ConversationsController < ApplicationController
before_filter :authenticate_user!
layout ->(c) { request.format == :mobile ? "application" : "with_header" }
before_filter -> { @css_framework = :bootstrap }
use_bootstrap_for :index, :show, :new
respond_to :html, :mobile, :json, :js
......
......@@ -5,6 +5,9 @@
class NotificationsController < ApplicationController
before_filter :authenticate_user!
layout ->(c) { request.format == :mobile ? "application" : "with_header_with_footer" }
use_bootstrap_for :index
def update
note = Notification.where(:recipient_id => current_user.id, :id => params[:id]).first
if note
......@@ -23,6 +26,10 @@ class NotificationsController < ApplicationController
def index
conditions = {:recipient_id => current_user.id}
if params[:type] && Notification.types.has_key?(params[:type])
conditions[:type] = Notification.types[params[:type]]
end
if params[:show] == "unread" then conditions[:unread] = true end
page = params[:page] || 1
per_page = params[:per_page] || 25
@notifications = WillPaginate::Collection.create(page, per_page, Notification.where(conditions).count ) do |pager|
......@@ -43,6 +50,12 @@ class NotificationsController < ApplicationController
@unread_notification_count = current_user.unread_notifications.count
@grouped_unread_notification_counts = {}
Notification.types.each_with_object(current_user.unread_notifications.group_by(&:type)) {|(name, type), notifications|
@grouped_unread_notification_counts[name] = notifications.has_key?(type) ? notifications[type].count : 0
}
respond_to do |format|
format.html
format.xml { render :xml => @notifications.to_xml }
......
......@@ -9,7 +9,7 @@ class PostsController < ApplicationController
before_filter :set_format_if_malformed_from_status_net, :only => :show
before_filter :find_post, :only => [:show, :interactions]
before_filter -> { @css_framework = :bootstrap }
use_bootstrap_for :show
respond_to :html,
:mobile,
......
......@@ -7,7 +7,7 @@ class StatusMessagesController < ApplicationController
before_filter :remove_getting_started, :only => [:create]
before_filter -> { @css_framework = :bootstrap }, :only => [:bookmarklet]
use_bootstrap_for :bookmarklet
respond_to :html,
:mobile,
......
module NotificationsHelper
include PeopleHelper
include PostsHelper
def object_link(note, actors)
target_type = note.popup_translation_key
......@@ -7,13 +8,13 @@ module NotificationsHelper
if note.instance_of?(Notifications::Mentioned)
if post = note.linked_object
translation(target_type, :actors => actors, :count => actors_count, :post_link => link_to(t('notifications.post'), post_path(post)).html_safe)
translation(target_type, :actors => actors, :count => actors_count, :post_link => link_to(post_page_title(post), post_path(post)).html_safe)
else
t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
end
elsif note.instance_of?(Notifications::CommentOnPost) || note.instance_of?(Notifications::AlsoCommented) || note.instance_of?(Notifications::Reshared) || note.instance_of?(Notifications::Liked)
if post = note.linked_object
translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author_name), :post_link => link_to(t('notifications.post'), post_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
translation(target_type, :actors => actors, :count => actors_count, :post_author => h(post.author_name), :post_link => link_to(post_page_title(post), post_path(post), 'data-ref' => post.id, :class => 'hard_object_link').html_safe)
else
t(note.deleted_translation_key, :actors => actors, :count => actors_count).html_safe
end
......
......@@ -91,4 +91,15 @@ private
def self.suppress_notification?(recipient, post)
post.is_a?(Post) && recipient.is_shareable_hidden?(post)
end
def self.types
{
"also_commented" => "Notifications::AlsoCommented",
"comment_on_post" => "Notifications::CommentOnPost",
"liked" => "Notifications::Liked",
"mentioned" => "Notifications::Mentioned",
"reshared" => "Notifications::Reshared",
"started_sharing" => "Notifications::StartedSharing"
}
end
end
.notification_element{:data=>{:guid => n.id}, :class => (n.unread ? "unread" : "read")}
.notification_element{:data=>{:guid => n.id, :type => (Notification.types.key(n.type) || '')}, :class => (n.unread ? "unread" : "read")}
= person_image_tag n.actors.first, :thumb_small
= notification_message_for(n)
%div
......
......@@ -637,25 +637,25 @@ en:
one: "%{actors} sent you a message."
other: "%{actors} sent you a message."
comment_on_post:
zero: "%{actors} commented on your %{post_link}."
one: "%{actors} commented on your %{post_link}."
other: "%{actors} commented on your %{post_link}."
zero: "%{actors} commented on your post »%{post_link}«."
one: "%{actors} commented on your post »%{post_link}«."
other: "%{actors} commented on your post »%{post_link}«."
also_commented:
zero: "%{actors} also commented on %{post_author}'s %{post_link}."
one: "%{actors} also commented on %{post_author}'s %{post_link}."
other: "%{actors} also commented on %{post_author}'s %{post_link}."
zero: "%{actors} also commented on %{post_author}'s post »%{post_link}«."
one: "%{actors} also commented on %{post_author}'s post »%{post_link}«."
other: "%{actors} also commented on %{post_author}'s post »%{post_link}«."
mentioned:
zero: "%{actors} have mentioned you in a %{post_link}."
one: "%{actors} has mentioned you in a %{post_link}."
other: "%{actors} have mentioned you in a %{post_link}."
zero: "%{actors} have mentioned you in the post »%{post_link}«."
one: "%{actors} has mentioned you in the post »%{post_link}«."
other: "%{actors} have mentioned you in the »%{post_link}«."
liked:
zero: "%{actors} have liked your %{post_link}."
one: "%{actors} has liked your %{post_link}."
other: "%{actors} have liked your %{post_link}."
zero: "%{actors} have liked your post »%{post_link}«."
one: "%{actors} has liked your post »%{post_link}«."
other: "%{actors} have liked your post »%{post_link}«."
reshared:
zero: "%{actors} have reshared your %{post_link}."
one: "%{actors} has reshared your %{post_link}."
other: "%{actors} have reshared your %{post_link}."
zero: "%{actors} have reshared your post »%{post_link}«."
one: "%{actors} has reshared your post »%{post_link}«."
other: "%{actors} have reshared your post »%{post_link}«."
post: "post"
also_commented_deleted:
zero: "%{actors} commented on a deleted post."
......@@ -675,8 +675,18 @@ en:
other: "%{actors} mentioned you in a deleted post."
index:
notifications: "Notifications"
mark_all_as_read: "Mark All as Read"
mark_all_as_read: "Mark all as read"
mark_read: "Mark read"
mark_unread: "Mark unread"
show_all: "show all"
show_unread: "show unread"
all_notifications: "All Notifications"
also_commented: "Also commented"
comment_on_post: "Comment on post"
liked: "Liked"
mentioned: "Mentioned"
reshared: "Reshared"
started_sharing: "Started sharing"
and_others:
zero: "and nobody else"
one: "and one more"
......
......@@ -98,6 +98,10 @@ en:
conversation:
participants: "Participants"
notifications:
mark_read: "Mark read"
mark_unread: "Mark unread"
stream:
hide: "Hide"
public: "Public"
......
require 'spec_helper'
describe NotificationsController do
describe '#index' do
before do
sign_in :user, alice
@post = FactoryGirl.create(:status_message)
FactoryGirl.create(:notification, :recipient => alice, :target => @post)
get :read_all
FactoryGirl.create(:notification, :recipient => alice, :target => @post)
eve.share_with(alice.person, eve.aspects.first)
end
it "generates a jasmine fixture", :fixture => true do
get :index
save_fixture(html_for("body"), "notifications")
end
end
end
......@@ -120,7 +120,21 @@ describe NotificationsController do
Nokogiri(response.body).css('.aspect_membership').should_not be_empty
end
end
describe "filter notifications" do
it "supports filtering by notification type" do
eve.share_with(alice.person, eve.aspects.first)
get :index, "type" => "started_sharing"
assigns[:notifications].count.should == 1
end
it "supports filtering by read/unread" do
get :read_all
2.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
get :index, "show" => "unread"
assigns[:notifications].count.should == 2
end
end
end
end
......@@ -77,7 +77,7 @@ describe NotificationsHelper do
output.should include I18n.t("#{@notification.popup_translation_key}",
:actors => notification_people_link(@notification),
:count => @notification.actors.count,
:post_link => "<a href=\"#{post_path(@post)}\" class=\"hard_object_link\" data-ref=\"#{@post.id}\">#{t('notifications.post')}</a>")
:post_link => link_to(post_page_title(@post), post_path(@post), 'data-ref' => @post.id, :class => 'hard_object_link').html_safe)
end
context 'when post is deleted' do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment