diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 4572e2048..9a4b0cd69 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -17,7 +17,7 @@ class AspectsController < ApplicationController def index aspect_ids = (params[:a_ids] ? params[:a_ids] : []) @stream = AspectStream.new(current_user, aspect_ids, - :order => session[:sort_order], + :order => sort_order, :max_time => params[:max_time].to_i) if params[:only_posts] @@ -148,4 +148,8 @@ class AspectsController < ApplicationController end end + def sort_order + is_mobile_device? ? 'created_at' : session[:sort_order] + end + end diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 46b906e01..8362ae018 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -6,7 +6,7 @@ class CommentsController < ApplicationController include ApplicationHelper before_filter :authenticate_user! - respond_to :html, :mobile, :only => [:create, :destroy] + respond_to :html, :mobile, :except => :show respond_to :js, :only => [:index] rescue_from ActiveRecord::RecordNotFound do @@ -28,7 +28,7 @@ class CommentsController < ApplicationController respond_to do |format| format.js{ render(:create, :status => 201)} format.html{ render :nothing => true, :status => 201 } - format.mobile{ redirect_to post_url(@comment.post) } + format.mobile{ render :partial => 'comment', :locals => {:post => @comment.post, :comment => @comment} } end else render :nothing => true, :status => 422 @@ -64,4 +64,7 @@ class CommentsController < ApplicationController end end + def new + render :layout => false + end end diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 1d647adb8..233e1dc2c 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -21,6 +21,7 @@ class LikesController < ApplicationController format.js { render 'likes/update', :status => 201 } format.html { render :nothing => true, :status => 201 } format.mobile { redirect_to post_path(@like.post_id) } + format.json { render :nothing => true, :status => 201 } end else render :nothing => true, :status => 422 @@ -34,13 +35,15 @@ class LikesController < ApplicationController if @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first current_user.retract(@like) respond_to do |format| - format.all { } + format.any { } format.js { render 'likes/update' } + format.json { render :nothing => true, :status => :ok} end else respond_to do |format| format.mobile { redirect_to :back } format.js { render :nothing => true, :status => 403 } + format.json { render :nothing => true, :status => 403} end end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 905952665..997fe55f2 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -27,6 +27,10 @@ class PostsController < ApplicationController notification.save end + if is_mobile_device? + @comments = @post.comments + end + respond_to do |format| format.xml{ render :xml => @post.to_diaspora_xml } format.mobile{render 'posts/show.mobile.haml'} diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index d10d3f593..b6b12a842 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -9,20 +9,22 @@ class StatusMessagesController < ApplicationController respond_to :mobile # Called when a user clicks "Mention" on a profile page - # @option [Integer] person_id The id of the person to be mentioned + # @param person_id [Integer] The id of the person to be mentioned def new - @person = Person.find(params[:person_id]) - @aspect = :profile - @contact = current_user.contact_for(@person) - @aspects_with_person = [] - if @contact - @aspects_with_person = @contact.aspects - @aspect_ids = @aspects_with_person.map(&:id) - @contacts_of_contact = @contact.contacts - - render :layout => nil + if params[:person_id] && @person = Person.where(params[:person_id]).first + @aspect = :profile + @contact = current_user.contact_for(@person) + @aspects_with_person = [] + if @contact + @aspects_with_person = @contact.aspects + @aspect_ids = @aspects_with_person.map(&:id) + @contacts_of_contact = @contact.contacts + render :layout => nil + end else - redirect_to :back + @aspect = :all + @aspects = current_user.aspects + @aspect_ids = @aspects.map{ |a| a.id } end end @@ -30,6 +32,9 @@ class StatusMessagesController < ApplicationController @aspects = current_user.aspects @selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq @aspect_ids = @aspects.map{|x| x.id} + + pp @aspect_ids.inspect + render :layout => nil end @@ -48,7 +53,14 @@ class StatusMessagesController < ApplicationController if @status_message.save Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:text].length}") - aspects = current_user.aspects_from_ids(params[:aspect_ids]) + # always send to all aspects if public + if params[:status_message][:public] || params[:status_message][:aspect_ids].first == "all_aspects" + aspect_ids = current_user.aspects.map{|a| a.id} + else + aspect_ids = params[:aspect_ids] + end + + aspects = current_user.aspects_from_ids(aspect_ids) current_user.add_to_streams(@status_message, aspects) receiving_services = current_user.services.where(:type => params[:services].map{|s| "Services::"+s.titleize}) if params[:services] current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :services => receiving_services) @@ -78,7 +90,8 @@ class StatusMessagesController < ApplicationController end def normalize_public_flag! - public_flag = params[:status_message][:public] + # mobile || desktop conditions + public_flag = params[:status_message][:aspect_ids].first == 'public' || params[:status_message][:public] public_flag.to_s.match(/(true)|(on)/) ? public_flag = true : public_flag = false params[:status_message][:public] = public_flag public_flag diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index bcb16a112..e84694c73 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. module StreamHelper - def next_page_path + def next_page_path(opts ={}) if controller.instance_of?(TagsController) tag_path(@tag, :max_time => @posts.last.created_at.to_i) elsif controller.instance_of?(AppsController) @@ -13,7 +13,13 @@ module StreamHelper elsif controller.instance_of?(TagFollowingsController) tag_followings_path(:max_time => @stream.posts.last.created_at.to_i) elsif controller.instance_of?(AspectsController) - aspects_path(:max_time => @stream.posts.last.send(@stream.order.to_sym).to_i, :a_ids => @stream.aspect_ids) + if opts[:ajax_stream] + time = (Time.now() + 1).to_i + + else + time = @stream.posts.last.send(@stream.order.to_sym).to_i + end + aspects_path(:max_time => time, :a_ids => @stream.aspect_ids) else raise 'in order to use pagination for this new controller, update next_page_path in stream helper' end diff --git a/app/views/aspects/_aspect_stream.haml b/app/views/aspects/_aspect_stream.haml index 2feef09bc..fbd506ae6 100644 --- a/app/views/aspects/_aspect_stream.haml +++ b/app/views/aspects/_aspect_stream.haml @@ -23,7 +23,11 @@ = render 'aspects/no_contacts_message' #main_stream.stream{:data => {:guids => stream.aspect_ids.join(',')}} - - if stream.posts.length > 0 + - if defined?(no_posts) && no_posts + #pagination + =link_to(t('more'), next_page_path(:ajax_stream => true), :class => 'paginate') + + - elsif stream.posts.length > 0 = render 'shared/stream', :posts => stream.posts #pagination =link_to(t('more'), next_page_path, :class => 'paginate') diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index d2b59a43f..4ba3eea39 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -26,7 +26,7 @@ .span-13.append-1 #aspect_stream_container.stream_container - = render 'aspects/aspect_stream', :stream => @stream + = render 'aspects/aspect_stream', :stream => @stream, :no_posts => true .span-5.rightBar.last = render 'aspects/selected_contacts', :stream => @stream diff --git a/app/views/aspects/index.mobile.haml b/app/views/aspects/index.mobile.haml index 4f13e4ea2..806b88d18 100644 --- a/app/views/aspects/index.mobile.haml +++ b/app/views/aspects/index.mobile.haml @@ -2,19 +2,17 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -#aspect_header +%h2{:style => "padding:0 10px;display:none;"} - if @stream.for_all_aspects? = t('all_aspects') - else = @stream.aspect - = link_to t('.post_a_message'), '#publisher_page', :id => 'publisher_button' - #main_stream.stream = render 'shared/stream', :posts => @stream.posts -if @stream.posts.length > 0 #pagination %a.more-link.paginate{:href => next_page_path} - %h2= t("more") -- content_for :subpages do - = render 'shared/publisher', :aspect_ids => @stream.aspect_ids, :selected_aspects => @stream.aspects, :aspect => @stream.aspect + %h1 + = t("more") + diff --git a/app/views/comments/_comment.mobile.haml b/app/views/comments/_comment.mobile.haml index a7adc99a1..5b622dfa6 100644 --- a/app/views/comments/_comment.mobile.haml +++ b/app/views/comments/_comment.mobile.haml @@ -3,17 +3,14 @@ -# the COPYRIGHT file. %li.comment{:data=>{:guid=>comment.id}, :class => ("hidden" if(defined? hidden))} - .right - %span.time - = comment.created_at ? time_ago_in_words(comment.created_at) : time_ago_in_words(Time.now) - -#.controls - -#= link_to image_tag('deletelabel.png'), comment, :confirm => t('are_you_sure'), :method => :delete, :class => "delete comment_delete", :title => t('delete') - - - = person_image_link(comment.author) .content .from + = person_image_link(comment.author) = person_link(comment.author) - %div{ :class => direction_for(comment.text) } + .info + %span.time.timeago{:datetime => comment.created_at} + = comment.created_at ? time_ago_in_words(comment.created_at) : time_ago_in_words(Time.now) + + %div{:class => direction_for(comment.text)} = markdownify(comment, :youtube_maps => comment[:youtube_titles]) diff --git a/app/views/comments/_comments.haml b/app/views/comments/_comments.html.haml similarity index 100% rename from app/views/comments/_comments.haml rename to app/views/comments/_comments.html.haml diff --git a/app/views/comments/_new_comment.mobile.haml b/app/views/comments/_new_comment.mobile.haml index 0bf41fff6..54f487d3b 100644 --- a/app/views/comments/_new_comment.mobile.haml +++ b/app/views/comments/_new_comment.mobile.haml @@ -2,10 +2,11 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment') do += form_tag( post_comments_path(post_id), :id => "new_comment_on_#{post_id}", :class => 'new_comment', :autocomplete => "off") do = hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}" - = text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}" + = text_area_tag :text, nil, :class => "comment_box",:id => "comment_text_on_#{post_id}", :placeholder => t('.comment'), :autofocus => true - %div{:data => {:inline => 'true'}, :style => 'text-align:right;'} - = submit_tag t('.comment'), :id => "comment_submit_#{post_id}", :disable_with => t('.commenting'), "data-role" => 'button', 'data-theme' => 'b', 'data-inline' => true + .actions + = link_to "Cancel", post_path(post_id), :class => "cancel_new_comment btn" + = submit_tag t('.comment'), :id => "comment_submit_#{post_id}", :disable_with => t('.commenting'), :class => "action" diff --git a/app/views/comments/index.haml b/app/views/comments/index.html.haml similarity index 100% rename from app/views/comments/index.haml rename to app/views/comments/index.html.haml diff --git a/app/views/comments/index.mobile.haml b/app/views/comments/index.mobile.haml new file mode 100644 index 000000000..ce6d633b7 --- /dev/null +++ b/app/views/comments/index.mobile.haml @@ -0,0 +1,14 @@ +.comment_container + .post_stats + %span.comment_count + = @post.comments.size + %span.like_count + = @post.likes.size + + %ul.comments + = render :partial => 'comments/comment', :collection => @comments, :locals => {:post => @post} + + %li.comment.add_comment_bottom_link_container + = link_to "#", :class => "show_comments bottom_collapse active" do + = image_tag 'icons/arrow_up_small.png' + = link_to "Add a comment", new_post_comment_path(@post), :class => 'add_comment_bottom_link btn comment_action inactive' diff --git a/app/views/comments/new.mobile.haml b/app/views/comments/new.mobile.haml new file mode 100644 index 000000000..c34cdf84a --- /dev/null +++ b/app/views/comments/new.mobile.haml @@ -0,0 +1 @@ += new_comment_form(params[:post_id], current_user) diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index b247e7758..275877e7f 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -8,105 +8,76 @@ %title DIASPORA* + %meta{:name => "description", :content => "Diaspora* Mobile"} + %meta{:name => "author", :content => "Diaspora, Inc."} + %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ - = include_javascripts :mobile - %meta{'name' =>'viewport', 'content' => "width=device-width, minimum-scale=1, maximum-scale=1"} + / Viewport scale + %meta{:name =>'viewport', :content => "width=device-width, minimum-scale=1 maximum-scale=1"} + %meta{:name => "HandheldFriendly", :content => "True"} + %meta{:name => "MobileOptimized", :content => "320"} + / Force cleartype on WP7 + %meta{'http-equiv' => "cleartype", :content => 'on'} - -if current_user - :javascript - Diaspora.I18n.loadLocale(#{get_javascript_strings_for(current_user.language).to_json}, "#{current_user.language}"); + / Home screen icon (sized for retina displays) + %link{:rel => 'apple-touch-icon', :href => '/apple-touch-icon.png'} + / For Nokia devices + %link{:rel => 'shortcut icon', :href => '/apple-touch-icon.png'} + + / iOS mobile web app indicator + %meta{:name => "apple-mobile-web-app-capable", :content => "yes"} + %link{:rel => "apple-touch-startup-image", :href => "/images/apple-splash.png"} + + / Stylesheets + = include_stylesheets :mobile + = yield(:custom_css) + + %script{:src => "/javascripts/vendor/mbp-modernizr-custom.js"} + / Media Queries Polyfill https://github.com/shichuan/mobile-html5-boilerplate/wiki/Media-Queries-Polyfill + :javascript + Modernizr.mq('(min-width:0)') || document.write('