diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index 856426ef7..3e5d5a73b 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -1,6 +1,6 @@ class ResharesController < ApplicationController before_filter :authenticate_user! - respond_to :js + respond_to :js, :json def create @reshare = current_user.build_post(:reshare, :root_guid => params[:root_guid]) diff --git a/app/views/shared/_stream_element.mobile.haml b/app/views/shared/_stream_element.mobile.haml index e7066cb79..1a4b9c853 100644 --- a/app/views/shared/_stream_element.mobile.haml +++ b/app/views/shared/_stream_element.mobile.haml @@ -17,6 +17,17 @@ .bottom_bar .floater + + - if (post.public? || reshare?(post)) && post.author != current_user.person + + - if reshare?(post) + - root = post.root + - else + - root = post + + - reshare = Reshare.where(:author_id => current_user.person.id, :root_guid => root.guid).first ? "active" : "inactive" + = link_to '', reshares_path(:root_guid => root.guid), :title => t('reshares.reshare.reshare_confirmation', :author => root.author.name), :class => "image_link reshare_action #{reshare}" + = link_to '', new_post_comment_path(post), :class => "image_link comment_action inactive" - if current_user && current_user.liked?(post) @@ -33,6 +44,10 @@ - if defined?(expanded_info) && expanded_info .comment_container .post_stats + - if @post.public? + %span.comment_count + = @post.reshares.size + %span.comment_count = @post.comments.size diff --git a/db/migrate/20111003232053_add_index_for_reshares.rb b/db/migrate/20111003232053_add_index_for_reshares.rb new file mode 100644 index 000000000..d99694fd9 --- /dev/null +++ b/db/migrate/20111003232053_add_index_for_reshares.rb @@ -0,0 +1,9 @@ +class AddIndexForReshares < ActiveRecord::Migration + def self.up + add_index :posts, [:author_id, :root_guid], :unique => true + end + + def self.down + remove_index :posts, :column => [:author_id, :root_guid] + end +end diff --git a/db/schema.rb b/db/schema.rb index 87defb4b6..57297a4e7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111002013921) do +ActiveRecord::Schema.define(:version => 20111003232053) do create_table "aspect_memberships", :force => true do |t| t.integer "aspect_id", :null => false @@ -285,6 +285,7 @@ ActiveRecord::Schema.define(:version => 20111002013921) do t.integer "comments_count", :default => 0 end + add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true add_index "posts", ["author_id"], :name => "index_posts_on_person_id" add_index "posts", ["guid"], :name => "index_posts_on_guid", :unique => true add_index "posts", ["root_guid"], :name => "index_posts_on_root_guid" diff --git a/public/images/icons/reshare_mobile.png b/public/images/icons/reshare_mobile.png index 7b53165ec..91883ea03 100644 Binary files a/public/images/icons/reshare_mobile.png and b/public/images/icons/reshare_mobile.png differ diff --git a/public/images/icons/reshare_mobile_active.png b/public/images/icons/reshare_mobile_active.png new file mode 100644 index 000000000..71a1feb5b Binary files /dev/null and b/public/images/icons/reshare_mobile_active.png differ diff --git a/public/javascripts/mobile.js b/public/javascripts/mobile.js index c338c5e31..13c8a9ba0 100644 --- a/public/javascripts/mobile.js +++ b/public/javascripts/mobile.js @@ -1,5 +1,15 @@ $(document).ready(function(){ + var showLoader = function(link){ + link.addClass('loading'); + }; + + var removeLoader = function(link){ + link.removeClass('loading') + .toggleClass('active') + .toggleClass('inactive'); + }; + /* Heart toggle */ $(".like_action", ".stream").bind("tap click", function(evt){ evt.preventDefault(); @@ -7,48 +17,68 @@ $(document).ready(function(){ likeCounter = $(this).closest(".stream_element").find("like_count"), href = link.attr("href"); - var showLoader = function(link){ - link.addClass('loading'); - }; + if(!link.hasClass("loading")){ + if(link.hasClass('inactive')) { + $.ajax({ + url: href, + dataType: 'json', + type: 'POST', + beforeSend: showLoader(link), + success: function(data){ + removeLoader(link); + link.attr("href", href + "/" + data["id"]); - var removeLoader = function(link){ - link.removeClass('loading') - .toggleClass('active') - .toggleClass('inactive'); - }; - - if(!link.hasClass("loading") && link.hasClass('inactive')) { - - $.ajax({ - url: href, - dataType: 'json', - type: 'POST', - beforeSend: showLoader(link), - success: function(data){ - removeLoader(link); - link.attr("href", href + "/" + data["id"]); - - if(likeCounter){ - likeCounter.text(parseInt(likeCounter.text) + 1); + if(likeCounter){ + likeCounter.text(parseInt(likeCounter.text) + 1); + } } - } - }); + }); + } + else if(link.hasClass("active")){ + $.ajax({ + url: link.attr("href"), + dataType: 'json', + type: 'DELETE', + beforeSend: showLoader(link), + complete: function(data){ + removeLoader(link); + link.attr("href", href.replace(/\/\d+$/, '')); + + if(likeCounter){ + likeCounter.text(parseInt(likeCounter.text) - 1); + } + } + }); + } } - else if(!link.hasClass("loading") && link.hasClass("active")){ - $.ajax({ - url: link.attr("href"), - dataType: 'json', - type: 'DELETE', - beforeSend: showLoader(link), - complete: function(data){ - removeLoader(link); - link.attr("href", href.replace(/\/\d+$/, '')); + }); - if(likeCounter){ - likeCounter.text(parseInt(likeCounter.text) - 1); - } + /* Reshare */ + $(".reshare_action", ".stream").bind("tap click", function(evt){ + evt.preventDefault(); + + var link = $(this), + href = link.attr("href"), + confirmText = link.attr('title'); + + if(!link.hasClass("loading")) { + if(link.hasClass('inactive')) { + if(confirm(confirmText)) { + $.ajax({ + url: href + "&provider_display_name=mobile", + dataType: 'json', + type: 'POST', + beforeSend: showLoader(link), + success: function(data){ + removeLoader(link); + }, + error: function(data){ + removeLoader(link); + alert("Failed to reshare!"); + } + }); } - }); + } } }); diff --git a/public/stylesheets/sass/mobile.scss b/public/stylesheets/sass/mobile.scss index 37f99c911..4538f6814 100644 --- a/public/stylesheets/sass/mobile.scss +++ b/public/stylesheets/sass/mobile.scss @@ -614,28 +614,32 @@ footer { width: 24px; padding: 5px; margin: { - left: 5px; }; } + left: 5px; }; -.like_action { - &.inactive{ - background-image: url("/images/icons/heart_mobile_grey.png"); - } - &.active { - background-image: url("/images/icons/heart_mobile_red.png"); - } &.loading { background-image: url("/images/mobile-spinner.gif"); } } +.reshare_action { + background-image: url("/images/icons/reshare_mobile.png"); + &.active { + background-image: url("/images/icons/reshare_mobile_active.png"); + } +} + +.like_action { + background-image: url("/images/icons/heart_mobile_grey.png"); + &.active { + background-image: url("/images/icons/heart_mobile_red.png"); + } +} + .comment_action.image_link { background-image: url("/images/icons/pencil_mobile_grey_active.png"); &.inactive { background-image: url("/images/icons/pencil_mobile_grey.png"); } - &.loading { - background-image: url("/images/mobile-spinner.gif"); - } } .compose_icon {