diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 9cee8143d5930c71c66ec862469e25f59229a795..7d53b614adfb0f714a0275d588ce46bde0cad196 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -1,9 +1,10 @@ - +# Copyright (c) 2010, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. class LikesController < ApplicationController include ApplicationHelper + helper :likes before_filter :authenticate_user! respond_to :html, :mobile, :json @@ -19,18 +20,7 @@ class LikesController < ApplicationController Postzord::Dispatch.new(current_user, @like).post respond_to do |format| - format.js { - json = { :post_id => @like.post_id, - :html => render_to_string( - :partial => 'likes/likes', - :locals => { - :likes => @like.post.likes, - :dislikes => @like.post.dislikes - } - ) - } - render(:json => json, :status => 201) - } + format.js { render :status => 201 } format.html { render :nothing => true, :status => 201 } format.mobile { redirect_to status_message_path(@like.post_id) } end @@ -45,10 +35,6 @@ class LikesController < ApplicationController def destroy if @like = Like.where(:post_id => params[:post_id], :author_id => current_user.person.id).first current_user.retract(@like) - respond_to do |format| - format.mobile{ redirect_to @like.post } - format.js {render :nothing => true, :status => 204} - end else respond_to do |format| format.mobile {redirect_to :back} @@ -56,5 +42,4 @@ class LikesController < ApplicationController end end end - end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 04bd87472f2309d19da8ebbe6d6e2e9ab2a630dd..5b7b26a11cde8832909c7d576f2dc36bf59bc365 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. class PeopleController < ApplicationController - helper :comments + helper :comments, :likes before_filter :authenticate_user!, :except => [:show] respond_to :html diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index 913ead739686a6541eb19586ead0fedbe356f5aa..d565f793691430b0edbd4d9b85cd8d56eaa722e1 100644 --- a/app/controllers/sockets_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. class SocketsController < ApplicationController - helper :comments + helper :comments, :likes include ApplicationHelper include SocketsHelper include Rails.application.routes.url_helpers diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 2b0e89ace70fb32405cadb4b81ef4603a580c665..e8120b459c4fbffef8e4171458a475cf982efc91 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. class StatusMessagesController < ApplicationController - helper :comments + helper :comments, :likes before_filter :authenticate_user! respond_to :html diff --git a/app/helpers/likes_helper.rb b/app/helpers/likes_helper.rb index fde7be672fa00c021f2648a9886ec0ffeceec499..77e5a603e3a6e3812dcd113eeeda608166f6c4bd 100644 --- a/app/helpers/likes_helper.rb +++ b/app/helpers/likes_helper.rb @@ -3,8 +3,16 @@ # the COPYRIGHT file. module LikesHelper - def likes_list likes + def likes_list(likes) links = likes.collect { |like| link_to "#{h(like.author.name.titlecase)}", person_path(like.author) } links.join(", ").html_safe end + + def like_action(post) + if current_user.liked?(post) + link_to t('shared.stream_element.unlike'), like_path(:post_id => post.id, :id => 'xxx'), :method => :delete, :class => 'unlike', :remote => true + else + link_to t('shared.stream_element.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => 'like', :remote => true + end + end end diff --git a/app/views/likes/_likes.haml b/app/views/likes/_likes.haml index dbddecccd87eb33f537ab5c9ac95f9dfb11b9df0..e8d61603fe31774e96e11ab9b51decd84c28c706 100644 --- a/app/views/likes/_likes.haml +++ b/app/views/likes/_likes.haml @@ -3,15 +3,10 @@ -# the COPYRIGHT file. - if likes.size > 0 - .likes - = image_tag('icons/happy_smiley.png') - = link_to t('.people_like_this', :count => likes.length), "#", :class => "expand_likes" - %span.hidden.likes_list - = likes_list(likes) + .likes_container + .likes + = image_tag('icons/happy_smiley.png') + = link_to t('.people_like_this', :count => likes.length), "#", :class => "expand_likes" + %span.hidden.likes_list + = likes_list(likes) -/- if dislikes.length > 0 -/ .dislikes -/ = image_tag('icons/sad_smiley.png') -/ = link_to t('.people_dislike_this', :count => dislikes.length), "#", :class => "expand_dislikes" -/ %span.hidden.dislikes_list -/ = likes_list(dislikes) diff --git a/app/views/likes/create.js.erb b/app/views/likes/create.js.erb new file mode 100644 index 0000000000000000000000000000000000000000..b5486b8b4276443accd09f5d3a241a514de9ef13 --- /dev/null +++ b/app/views/likes/create.js.erb @@ -0,0 +1,4 @@ +$(".like_action", ".stream_element[data-guid=<%=@like.post_id%>]").html("<%= escape_javascript(like_action(@like.post))%>"); + +WebSocketReceiver.processLike("<%=@like.post_id%>", "<%= escape_javascript(render("likes/likes", :post_id => @like.post_id, :likes => @like.post.likes, :dislikes => @like.post.dislikes)) %>"); + diff --git a/app/views/likes/destroy.js.erb b/app/views/likes/destroy.js.erb new file mode 100644 index 0000000000000000000000000000000000000000..7538c2113826070b2edf9e5b9a2721733a75201c --- /dev/null +++ b/app/views/likes/destroy.js.erb @@ -0,0 +1,3 @@ +$(".like_action", ".stream_element[data-guid=<%=@like.post_id%>]").html("<%= escape_javascript(like_action(@like.post))%>"); +WebSocketReceiver.processLike("<%=@like.post_id%>", "<%= escape_javascript(render("likes/likes", :post_id => @like.post_id, :likes => @like.post.likes, :dislikes => @like.post.dislikes)) %>"); + diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index b91323a951b26003899f2ecdb10414a284329a3e..22b8f27c3cbf79c75c9ed7b55132cf281083f57c 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -37,20 +37,14 @@ = link_to(how_long_ago(post), status_message_path(post)) - unless (defined?(@commenting_disabled) && @commenting_disabled) + | + %span.like_action + = like_action(post) + | = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' - - if defined?(current_user) - %span.like_links - | - - if !current_user.liked?(post) - = link_to t('.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => "like_it", :remote => true - - else - = link_to t('.unlike'), like_path(:post_id => post.id, :id => 'xxx'), :method => :delete, :class => "like_it", :remote => true - - /| - /= link_to t('.dislike'), like_path(:positive => 'false', :post_id => post.id), :method => :post, :class => "dislike_it", :remote => true - - .likes_container - = render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user + .likes + - if post.likes.count > 0 + = render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user = render "comments/comments", :post => post, :comments => post.comments, :current_user => current_user, :condensed => true, :commenting_disabled => (defined?(@commenting_disabled) && @commenting_disabled) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 60d14b83f97ae34fb95827b358b992dd1750a4a4..8104b69a0a70b4b0902c85db78cf6698792b6d0c 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -161,7 +161,7 @@ en: many: "%{count} comments" other: "%{count} comments" new_comment: - comment: "comment" + comment: "Comment" commenting: "Commenting..." contacts: diff --git a/public/javascripts/stream.js b/public/javascripts/stream.js index 03d6df209a0d2b20df9b844fcd3d2f60d228a10d..8b6c2a69a9ca500952ffe662fc649b70fbb7a096 100644 --- a/public/javascripts/stream.js +++ b/public/javascripts/stream.js @@ -92,12 +92,6 @@ var Stream = { $(this).parent().fadeOut('fast'); }); - likes.live('ajax:success', function(data, json, xhr) { - $(this).parent().detach(); - json = $.parseJSON(json); - WebSocketReceiver.processLike(json.post_id, json.html); - }); - likes.live('ajax:failure', function(data, html, xhr) { Diaspora.widgets.alert.alert('Failed to like/dislike!'); $(this).parent().fadeIn('fast'); diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index c244ea05ad5a49cfd175137a0cf36bfaa3bc7c06..e0ad2349c668f11dd1bd05c18899e2b4c1cb0ba4 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -123,7 +123,7 @@ var WebSocketReceiver = { processLike: function(postId, html) { var post = $("*[data-guid='"+postId+"']"); - $(".likes_container", post).fadeOut('fast').html(html).fadeIn('fast'); + $('.likes', post).html(html); }, processPost: function(className, postId, html, aspectIds) { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index e922fece782af0d9c8c389dbd3a31e0b80c1ef91..c724e8524c99d415e08ebd3d41fcc7b50773d5c8 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -571,8 +571,7 @@ header ul.comments, ul.show_comments, -div.likes, -div.dislikes +.likes_container :margin 0 :top 0.5em :padding 0 @@ -2280,22 +2279,31 @@ h3,h4 :position relative :z-index 10 -ul.show_comments, -div.likes, -div.dislikes + +ul.show_comments :margin :bottom -0.5em - > li + +.likes_container + :margin + :bottom -4px + :padding 4px + + +ul.show_comments, +.likes_container + > * :font :size smaller - img - :position relative - :top 3px - :height 12px - :width 12px - :margin - :left 0.5em - :right 0.5em + :weight bold + + img + :position relative + :top 3px + :height 12px + :width 12px + :margin + :left 0.5em .mark_all_read :position relative @@ -2821,22 +2829,6 @@ h1.tag :background :color rgb(245,245,245) -.likes_container - .likes, - .dislikes - :border-bottom 1px solid white - a - :padding 1px - :vertical-align middle - :font-size 11px - img - :position relative - :width 14px - :height 14px - :margin-left 5px - :top 2px - - #contacts_of_contact .section :margin diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index d09303e2d9a3f7d698e064dd9e3d521a5158f527..6e5a0d2168b689c4b45aefd6ebdc41bf8e38f8d8 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -83,7 +83,7 @@ describe LikesController do it 'lets a user destroy their like' do alice.should_receive(:retract).with(@like) delete :destroy, :format => "js", :post_id => @like.post_id, :id => @like.id - response.status.should == 204 + response.should be_success end it 'does not let a user destroy other likes' do