diff --git a/Gemfile b/Gemfile index 7f0ba8430..546de70bc 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ group :production do # we don't install these on travis to speed up test runs gem 'newrelic_rpm' gem 'rack-google-analytics', :require => 'rack/google-analytics' gem 'rack-piwik', :require => 'rack/piwik' + gem 'rack-ssl', :require => 'rack/ssl' end # configuration @@ -116,7 +117,7 @@ gem 'jasmine', '~> 1.1.2' group :test do gem 'capybara', '~> 1.1.2' - gem 'cucumber-rails', '1.2.1' + gem 'cucumber-rails', '1.2.1', :require => false gem 'cucumber-api-steps', '0.6', :require => false gem 'database_cleaner', '0.7.1' gem 'diaspora-client', :git => 'git://github.com/diaspora/diaspora-client.git' @@ -149,4 +150,7 @@ group :development do gem 'ruby-debug19', :platforms => :ruby_19 gem 'ruby-debug', :platforms => :mri_18 gem 'yard', :require => false + + # speed up development requests (already pulled into rails 3.2) + gem 'active_reload' end diff --git a/Gemfile.lock b/Gemfile.lock index fd70d6ccc..a7c4f983b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,6 +68,7 @@ GEM rack-mount (~> 0.6.14) rack-test (~> 0.5.7) tzinfo (~> 0.3.23) + active_reload (0.6.1) activemodel (3.0.11) activesupport (= 3.0.11) builder (~> 2.1.2) @@ -147,7 +148,7 @@ GEM abstract (>= 1.0.0) eventmachine (0.12.10) excon (0.9.4) - factory_girl (2.4.0) + factory_girl (2.4.2) activesupport factory_girl_rails (1.5.0) factory_girl (~> 2.4.0) @@ -292,6 +293,8 @@ GEM rack-mount (0.6.14) rack (>= 1.0.0) rack-piwik (0.1.2) + rack-ssl (1.3.2) + rack rack-test (0.5.7) rack (>= 1.0) rails (3.0.11) @@ -416,6 +419,7 @@ PLATFORMS DEPENDENCIES SystemTimer (= 1.2.3) + active_reload activerecord-import acts-as-taggable-on! acts_as_api @@ -471,6 +475,7 @@ DEPENDENCIES pg rack-google-analytics rack-piwik + rack-ssl rails (= 3.0.11) rails-i18n redcarpet (= 2.0.1) diff --git a/app/controllers/api/v0/tags_controller.rb b/app/controllers/api/v0/tags_controller.rb deleted file mode 100644 index 1ce401b1c..000000000 --- a/app/controllers/api/v0/tags_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -class Api::V0::TagsController < ApplicationController - def show - render :json => Api::V0::Serializers::Tag.new(params[:name]) - end -end diff --git a/app/controllers/api/v0/users_controller.rb b/app/controllers/api/v0/users_controller.rb deleted file mode 100644 index 5328a63c3..000000000 --- a/app/controllers/api/v0/users_controller.rb +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -class Api::V0::UsersController < ApplicationController - def show - if user = User.find_by_username(params[:username]) - render :json => Api::V0::Serializers::User.new(user) - else - head :not_found - end - end -end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c46581f80..cce1e7772 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -83,7 +83,7 @@ class ApplicationController < ActionController::Base def redirect_unless_admin unless current_user.admin? - redirect_to multi_url, :notice => 'you need to be an admin to do that' + redirect_to multi_stream_url, :notice => 'you need to be an admin to do that' return end end @@ -111,7 +111,7 @@ class ApplicationController < ActionController::Base end def after_sign_in_path_for(resource) - stored_location_for(:user) || (current_user.getting_started? ? getting_started_path : multi_path) + stored_location_for(:user) || (current_user.getting_started? ? getting_started_path : multi_stream_path) end def tag_followings @@ -127,23 +127,7 @@ class ApplicationController < ActionController::Base @tags ||= current_user.followed_tags end - # @param stream_klass [Constant] - # @return [String] JSON representation of posts given a [Stream] constant. - def stream_json(stream_klass) - render_for_api :backbone, :json => stream(stream_klass).stream_posts, :root => :posts - end - - def stream(stream_klass) - authenticate_user! - stream_klass.new(current_user, :max_time => max_time) - end - - def default_stream_action(stream_klass) - @stream = stream(stream_klass) - render 'aspects/index' - end - def max_time - params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now + params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now + 1 end end diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 2fcc10c31..1873cd635 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -2,29 +2,13 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(Rails.root, "lib", 'stream', "aspect") - class AspectsController < ApplicationController before_filter :authenticate_user! - before_filter :save_selected_aspects, :only => :index - before_filter :ensure_page, :only => :index respond_to :html, :js, :json - def index - stream_klass = Stream::Aspect - aspect_ids = (session[:a_ids] ? session[:a_ids] : []) - @stream = Stream::Aspect.new(current_user, aspect_ids, - :max_time => params[:max_time].to_i) - - respond_with do |format| - format.html { render 'aspects/index' } - format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } - end - end - def create @aspect = current_user.aspects.create(params[:aspect]) @@ -132,16 +116,4 @@ class AspectsController < ApplicationController end @aspect.save end - - def ensure_page - params[:max_time] ||= Time.now + 1 - end - - private - - def save_selected_aspects - if params[:a_ids].present? - session[:a_ids] = params[:a_ids] - end - end end diff --git a/app/controllers/comment_stream_controller.rb b/app/controllers/comment_stream_controller.rb deleted file mode 100644 index f478a6d20..000000000 --- a/app/controllers/comment_stream_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib','stream', 'comments') - -class CommentStreamController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Comments - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 5376bc8ab..e33d51656 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -6,7 +6,7 @@ class HomeController < ApplicationController def show if current_user - redirect_to multi_path if current_user + redirect_to multi_stream_path if current_user elsif is_mobile_device? redirect_to user_session_path else diff --git a/app/controllers/like_stream_controller.rb b/app/controllers/like_stream_controller.rb deleted file mode 100644 index 5fd8fc631..000000000 --- a/app/controllers/like_stream_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib','stream', 'likes') - -class LikeStreamController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Likes - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/mentions_controller.rb b/app/controllers/mentions_controller.rb deleted file mode 100644 index 87e2f37f7..000000000 --- a/app/controllers/mentions_controller.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib','stream', 'mention') - -class MentionsController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Mention - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/multis_controller.rb b/app/controllers/multis_controller.rb deleted file mode 100644 index 9eb042503..000000000 --- a/app/controllers/multis_controller.rb +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -require File.join(Rails.root, 'lib', 'stream', 'multi') - -class MultisController < ApplicationController - - respond_to :html, :json - - def index - stream_klass = Stream::Multi - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.mobile{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end -end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index c27df96c7..b51d7e470 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -50,7 +50,7 @@ class NotificationsController < VannaController post_process :html do def post_read_all(json) - Response.new(:status => 302, :location => multi_path) + Response.new(:status => 302, :location => multi_stream_path) end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 1a44a8f26..856dcc104 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,12 +2,9 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -require File.join(Rails.root, 'lib', 'stream', 'public') - class PostsController < ApplicationController before_filter :authenticate_user!, :except => :show before_filter :set_format_if_malformed_from_status_net, :only => :show - before_filter :redirect_unless_admin, :only => :index respond_to :html, :mobile, @@ -54,7 +51,7 @@ class PostsController < ApplicationController respond_to do |format| format.js {render 'destroy'} format.json { render :nothing => true, :status => 204 } - format.all {redirect_to multi_path} + format.all {redirect_to multi_stream_path} end else Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'" @@ -62,16 +59,12 @@ class PostsController < ApplicationController end end - def index - default_stream_action(Stream::Public) - end + private def set_format_if_malformed_from_status_net request.format = :html if request.format == 'application/html+xml' end - private - def user_can_not_comment_on_post? if @post.public && @post.author.local? false diff --git a/app/controllers/share_visibilities_controller.rb b/app/controllers/share_visibilities_controller.rb index 1c6cb9a8e..49c7ead7c 100644 --- a/app/controllers/share_visibilities_controller.rb +++ b/app/controllers/share_visibilities_controller.rb @@ -11,37 +11,14 @@ class ShareVisibilitiesController < ApplicationController params[:shareable_id] ||= params[:post_id] params[:shareable_type] ||= 'Post' - @post = accessible_post - @contact = current_user.contact_for(@post.author) - - if @contact && @vis = ShareVisibility.where(:contact_id => @contact.id, - :shareable_id => params[:shareable_id], - :shareable_type => params[:shareable_type]).first - @vis.hidden = !@vis.hidden - if @vis.save - update_cache(@vis) - render :nothing => true, :status => 200 - return - end - end - render :nothing => true, :status => 403 + vis = current_user.toggle_hidden_shareable(accessible_post) + RedisCache.update_cache_for(current_user, accessible_post, vis) + render :nothing => true, :status => 200 end protected - def update_cache(visibility) - return unless RedisCache.configured? - - cache = RedisCache.new(current_user, 'created_at') - - if visibility.hidden? - cache.remove(accessible_post.id) - else - cache.add(accessible_post.created_at.to_i, accessible_post.id) - end - end - def accessible_post - @post ||= Post.where(:id => params[:post_id]).select("id, guid, author_id, created_at").first + @post ||= params[:shareable_type].constantize.where(:id => params[:post_id]).select("id, guid, author_id, created_at").first end end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 3717cd472..726835961 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -70,7 +70,7 @@ class StatusMessagesController < ApplicationController respond_to do |format| format.html { redirect_to :back} - format.mobile{ redirect_to multi_path} + format.mobile{ redirect_to multi_stream_path} format.json{ render :json => @status_message.as_api_response(:backbone), :status => 201 } end else diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb new file mode 100644 index 000000000..50a240f37 --- /dev/null +++ b/app/controllers/streams_controller.rb @@ -0,0 +1,71 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +require File.join(Rails.root, "lib", "stream", "aspect") +require File.join(Rails.root, "lib", "stream", "multi") +require File.join(Rails.root, "lib", "stream", "comments") +require File.join(Rails.root, "lib", "stream", "likes") +require File.join(Rails.root, "lib", "stream", "mention") +require File.join(Rails.root, "lib", "stream", "followed_tag") + +class StreamsController < ApplicationController + before_filter :authenticate_user! + before_filter :save_selected_aspects, :only => :aspects + before_filter :redirect_unless_admin, :only => :public + + respond_to :html, + :mobile, + :json + + def aspects + aspect_ids = (session[:a_ids] ? session[:a_ids] : []) + @stream = Stream::Aspect.new(current_user, aspect_ids, + :max_time => max_time) + stream_responder + end + + def public + stream_responder(Stream::Public) + end + + def multi + stream_responder(Stream::Multi) + end + + def commented + stream_responder(Stream::Comments) + end + + def liked + stream_responder(Stream::Likes) + end + + def mentioned + stream_responder(Stream::Mention) + end + + def followed_tags + stream_responder(Stream::FollowedTag) + end + + private + + def stream_responder(stream_klass=nil) + if stream_klass.present? + @stream ||= stream_klass.new(current_user, :max_time => max_time) + end + + respond_with do |format| + format.html { render 'layouts/main_stream' } + format.mobile { render 'layouts/main_stream' } + format.json { render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } + end + end + + def save_selected_aspects + if params[:a_ids].present? + session[:a_ids] = params[:a_ids] + end + end +end diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index b99e00a22..f9a0e7b63 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -2,22 +2,12 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. # -require File.join(Rails.root, 'lib', 'stream', 'followed_tag') class TagFollowingsController < ApplicationController before_filter :authenticate_user! respond_to :html, :json - def index - stream_klass = Stream::FollowedTag - - respond_with do |format| - format.html{ default_stream_action(stream_klass) } - format.json{ stream_json(stream_klass) } - end - end - # POST /tag_followings # POST /tag_followings.xml def create @@ -73,6 +63,6 @@ class TagFollowingsController < ApplicationController @tag_following = current_user.tag_followings.create(:tag_id => @tag.id) end end - redirect_to multi_path + redirect_to multi_stream_path end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 56a26bab8..72c1ccbd7 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -87,7 +87,7 @@ class UsersController < ApplicationController if params[:user] && params[:user][:current_password] && current_user.valid_password?(params[:user][:current_password]) current_user.close_account! sign_out current_user - redirect_to(multi_path, :notice => I18n.t('users.destroy.success')) + redirect_to(multi_stream_path, :notice => I18n.t('users.destroy.success')) else if params[:user].present? && params[:user][:current_password].present? flash[:error] = t 'users.destroy.wrong_password' @@ -111,7 +111,7 @@ class UsersController < ApplicationController format.any { redirect_to person_path(user.person.id) } end else - redirect_to multi_path, :error => I18n.t('users.public.does_not_exist', :username => params[:username]) + redirect_to multi_stream_path, :error => I18n.t('users.public.does_not_exist', :username => params[:username]) end end @@ -127,14 +127,14 @@ class UsersController < ApplicationController def logged_out @page = :logged_out if user_signed_in? - redirect_to multi_path + redirect_to multi_stream_path end end def getting_started_completed user = current_user user.update_attributes(:getting_started => false) - redirect_to multi_path + redirect_to multi_stream_path end def export @@ -150,7 +150,7 @@ class UsersController < ApplicationController def user_photo username = params[:username].split('@')[0] user = User.find_by_username(username) - if user.present? + if user.present? redirect_to user.profile.image_url else render :nothing => true, :status => 404 diff --git a/app/controllers/vanna_controller.rb b/app/controllers/vanna_controller.rb index 3ae86330c..693f10dc9 100644 --- a/app/controllers/vanna_controller.rb +++ b/app/controllers/vanna_controller.rb @@ -83,7 +83,7 @@ class VannaController < Vanna::Base def redirect_unless_admin unless current_user.admin? - redirect_to multi_path, :notice => 'you need to be an admin to do that' + redirect_to multi_stream_path, :notice => 'you need to be an admin to do that' return end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 21752935c..d0f12da91 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -32,6 +32,10 @@ module ApplicationHelper without_close_html + link_to(image_tag('deletelabel.png'), "#", :class => 'close') end + def diaspora_id_host + User.diaspora_id_host + end + def jquery_include_tag javascript_include_tag('//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js') + content_tag(:script) do diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index 44b882380..10a6e27b0 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -10,25 +10,21 @@ module StreamHelper "/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}" elsif controller.instance_of?(PeopleController) local_or_remote_person_path(@person, :max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(TagFollowingsController) - tag_followings_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(MentionsController) - mentions_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(MultisController) - multi_path(:max_time => time_for_scroll(@stream)) elsif controller.instance_of?(PostsController) public_stream_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(AspectsController) - aspects_path(:max_time => time_for_scroll(@stream), :a_ids => @stream.aspect_ids) - elsif controller.instance_of?(LikeStreamController) - like_stream_path(:max_time => time_for_scroll(@stream)) - elsif controller.instance_of?(CommentStreamController) - comment_stream_path(:max_time => time_for_scroll(@stream)) + elsif controller.instance_of?(StreamsController) + multi_stream_path(:max_time => time_for_scroll(@stream)) else raise 'in order to use pagination for this new controller, update next_page_path in stream helper' end end + def reshare?(post) + post.instance_of?(Reshare) + end + + private + def time_for_scroll(stream) if stream.stream_posts.empty? (Time.now() + 1).to_i @@ -36,8 +32,4 @@ module StreamHelper stream.stream_posts.last.send(stream.order.to_sym).to_i end end - - def reshare?(post) - post.instance_of?(Reshare) - end end diff --git a/app/models/api/v0/serializers/tag.rb b/app/models/api/v0/serializers/tag.rb deleted file mode 100644 index bd378607d..000000000 --- a/app/models/api/v0/serializers/tag.rb +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -class Api::V0::Serializers::Tag - - def initialize(tag) - @stream = Stream::Tag.new(nil, tag) - end - - def as_json(opts={}) - { - "name" => @stream.tag_name, - "person_count" => @stream.tagged_people_count, - "followed_count" => @stream.tag_follow_count, - "posts" => [] - } - end -end diff --git a/app/models/api/v0/serializers/user.rb b/app/models/api/v0/serializers/user.rb deleted file mode 100644 index 2dc94fc07..000000000 --- a/app/models/api/v0/serializers/user.rb +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -class Api::V0::Serializers::User - def initialize(user) - @person = user.person - @profile = @person.profile - end - - def as_json(opts={}) - { - "diaspora_id" => @person.diaspora_handle, - "first_name" => @profile.first_name, - "last_name" => @profile.last_name, - "image_url" => @profile.image_url, - "searchable" => @profile.searchable - } - end -end diff --git a/app/models/app_config.rb b/app/models/app_config.rb index 12e266bac..40866429a 100644 --- a/app/models/app_config.rb +++ b/app/models/app_config.rb @@ -103,6 +103,10 @@ HELP end end + def self.bare_pod_uri + self[:pod_uri].authority.gsub('www.', '') + end + def self.normalize_admins self[:admins] ||= [] self[:admins].collect! { |username| username.downcase } diff --git a/app/models/notification.rb b/app/models/notification.rb index 547899379..a15711c31 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -22,6 +22,7 @@ class Notification < ActiveRecord::Base else n = note_type.make_notification(recipient, target, actor, note_type) end + if n n.email_the_user(target, actor) n @@ -43,7 +44,8 @@ class Notification < ActiveRecord::Base private def self.concatenate_or_create(recipient, target, actor, notification_type) - return nil if share_visiblity_is_hidden?(recipient, target) + return nil if suppress_notification?(recipient, target) + if n = notification_type.where(:target_id => target.id, :target_type => target.class.base_class, :recipient_id => recipient.id, @@ -64,22 +66,16 @@ private def self.make_notification(recipient, target, actor, notification_type) - return nil if share_visiblity_is_hidden?(recipient, target) + return nil if suppress_notification?(recipient, target) n = notification_type.new(:target => target, - :recipient_id => recipient.id) + :recipient_id => recipient.id) n.actors = n.actors | [actor] n.unread = false if target.is_a? Request n.save! n end - #horrible hack that should not be here! - def self.share_visiblity_is_hidden?(recipient, post) - return false unless post.is_a?(Post) - - contact = recipient.contact_for(post.author) - return false unless contact && recipient && post - pv = ShareVisibility.where(:contact_id => contact.id, :shareable_id => post.id, :shareable_type => post.class.base_class.to_s).first - pv.present? ? pv.hidden? : false + def self.suppress_notification?(recipient, post) + post.is_a?(Post) && recipient.is_shareable_hidden?(post) end end diff --git a/app/models/person.rb b/app/models/person.rb index 3d9496a2e..55fd3fa17 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -51,7 +51,6 @@ class Person < ActiveRecord::Base has_many :mentions, :dependent => :destroy - before_destroy :remove_all_traces before_validation :clean_url validates :url, :presence => true @@ -322,10 +321,6 @@ class Person < ActiveRecord::Base end private - def remove_all_traces - Notification.joins(:notification_actors).where(:notification_actors => {:person_id => self.id}).all.each{ |n| n.destroy} - end - def fix_profile Webfinger.new(self.diaspora_handle).fetch self.reload diff --git a/app/models/post.rb b/app/models/post.rb index 4e066b635..dc656e672 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -71,27 +71,40 @@ class Post < ActiveRecord::Base end def self.excluding_blocks(user) - people = user.blocks.includes(:person).map{|b| b.person} + people = user.blocks.map{|b| b.person_id} + scope = scoped - if people.present? - where("posts.author_id NOT IN (?)", people.map { |person| person.id }) - else - scoped + if people.any? + scope = scope.where("posts.author_id NOT IN (?)", people) end + + scope + end + + def self.excluding_hidden_shareables(user) + scope = scoped + if user.has_hidden_shareables_of_type? + scope = scope.where('posts.id NOT IN (?)', user.hidden_shareables["#{self.base_class}"]) + end + scope + end + + def self.excluding_hidden_content(user) + excluding_blocks(user).excluding_hidden_shareables(user) end def self.for_a_stream(max_time, order, user=nil) scope = self.for_visible_shareable_sql(max_time, order). includes_for_a_stream - scope = scope.excluding_blocks(user) if user.present? + scope = scope.excluding_hidden_content(user) if user.present? scope end ############# - def self.diaspora_initialize params + def self.diaspora_initialize(params) new_post = self.new params.to_hash new_post.author = params[:author] new_post.public = params[:public] if params[:public] diff --git a/app/models/user.rb b/app/models/user.rb index 7c91f29bd..1fc56abf9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -30,6 +30,8 @@ class User < ActiveRecord::Base validates_associated :person validate :no_person_with_same_username + serialize :hidden_shareables, Hash + has_one :person, :foreign_key => :owner_id delegate :public_key, :posts, :photos, :owns?, :diaspora_handle, :name, :public_url, :profile, :first_name, :last_name, :to => :person @@ -99,6 +101,55 @@ class User < ActiveRecord::Base end end + def hidden_shareables + self[:hidden_shareables] ||= {} + end + + def add_hidden_shareable(key, share_id, opts={}) + if self.hidden_shareables.has_key?(key) + self.hidden_shareables[key] << share_id + else + self.hidden_shareables[key] = [share_id] + end + self.save unless opts[:batch] + self.hidden_shareables + end + + def remove_hidden_shareable(key, share_id) + if self.hidden_shareables.has_key?(key) + self.hidden_shareables[key].delete(share_id) + end + end + + def is_shareable_hidden?(shareable) + shareable_type = shareable.class.base_class.name + if self.hidden_shareables.has_key?(shareable_type) + self.hidden_shareables[shareable_type].include?(shareable.id.to_s) + else + false + end + end + + def toggle_hidden_shareable(share) + share_id = share.id.to_s + key = share.class.base_class.to_s + if self.hidden_shareables.has_key?(key) && self.hidden_shareables[key].include?(share_id) + self.remove_hidden_shareable(key, share_id) + self.save + false + else + self.add_hidden_shareable(key, share_id) + self.save + true + end + end + + def has_hidden_shareables_of_type?(t = Post) + share_type = t.base_class.to_s + self.hidden_shareables[share_type].present? + end + + def self.create_from_invitation!(invitation) user = User.new user.generate_keys @@ -114,7 +165,6 @@ class User < ActiveRecord::Base Resque.enqueue(Jobs::ResetPassword, self.id) end - def update_user_preferences(pref_hash) if self.disable_mail UserPreference::VALID_EMAIL_TYPES.each{|x| self.user_preferences.find_or_create_by_email_type(x)} @@ -377,10 +427,14 @@ class User < ActiveRecord::Base def set_person(person) person.url = AppConfig[:pod_url] - person.diaspora_handle = "#{self.username}@#{AppConfig[:pod_uri].authority}" + person.diaspora_handle = "#{self.username}#{User.diaspora_id_host}" self.person = person end + def self.diaspora_id_host + "@#{AppConfig.bare_pod_uri}" + end + def seed_aspects self.aspects.create(:name => I18n.t('aspects.seed.family')) self.aspects.create(:name => I18n.t('aspects.seed.friends')) @@ -394,7 +448,6 @@ class User < ActiveRecord::Base aq end - def encryption_key OpenSSL::PKey::RSA.new(serialized_private_key) end @@ -403,32 +456,6 @@ class User < ActiveRecord::Base AppConfig[:admins].present? && AppConfig[:admins].include?(self.username) end - def remove_all_traces - disconnect_everyone - remove_mentions - remove_person - end - - def remove_person - self.person.destroy - end - - def disconnect_everyone - self.contacts.each do |contact| - if contact.person.remote? - self.disconnect(contact) - else - contact.person.owner.disconnected_by(self.person) - remove_contact(contact, :force => true) - end - end - self.aspects.destroy_all - end - - def remove_mentions - Mention.where( :person_id => self.person.id).delete_all - end - def guard_unconfirmed_email self.unconfirmed_email = nil if unconfirmed_email.blank? || unconfirmed_email == email @@ -445,7 +472,6 @@ class User < ActiveRecord::Base end end - # Generate public/private keys for User and associated Person def generate_keys key_size = (Rails.env == 'test' ? 512 : 4096) @@ -476,7 +502,7 @@ class User < ActiveRecord::Base end def no_person_with_same_username - diaspora_id = "#{self.username}@#{AppConfig[:pod_uri].host}" + diaspora_id = "#{self.username}#{User.diaspora_id_host}" if self.username_changed? && Person.exists?(:diaspora_handle => diaspora_id) errors[:base] << 'That username has already been taken' end diff --git a/app/views/invitations/edit.html.haml b/app/views/invitations/edit.html.haml index ca4047ff3..e208b613f 100644 --- a/app/views/invitations/edit.html.haml +++ b/app/views/invitations/edit.html.haml @@ -27,7 +27,7 @@ = t('username') = f.text_field :username, :title => t('registrations.new.enter_username') %span.host_uri - = "@#{AppConfig[:pod_uri].host}" + = diaspora_id_host .clearfix %b = t('email') diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index 89601a4c5..b574203bd 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -50,7 +50,7 @@ = yield %header - = link_to(image_tag('white@2x.png', :height => 20, :width => 127, :id => 'header_title'), multi_path) + = link_to(image_tag('white@2x.png', :height => 20, :width => 127, :id => 'header_title'), multi_stream_path) - if user_signed_in? - if yield(:header_action).present? = yield(:header_action) diff --git a/app/views/aspects/index.html.haml b/app/views/layouts/main_stream.html.haml similarity index 67% rename from app/views/aspects/index.html.haml rename to app/views/layouts/main_stream.html.haml index bd1039821..fad1427e9 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/layouts/main_stream.html.haml @@ -13,9 +13,9 @@ = link_to image_tag('close_label.png'), getting_started_completed_path, :id => "gs-skip-x" .span-23 %h1 - = t('.welcome_to_diaspora', :name => current_user.first_name) + = t('aspects.index.welcome_to_diaspora', :name => current_user.first_name) %h3 - = t('.introduce_yourself') + = t('aspects.index.introduce_yourself') %br %br %br @@ -31,21 +31,21 @@ .section %ul.left_nav %li - = link_to t("streams.multi.title"), multi_path, :class => 'home_selector', :rel => 'backbone' + = link_to t("streams.multi.title"), multi_stream_path, :class => 'home_selector', :rel => 'backbone' = render 'aspects/aspect_listings', :stream => @stream %ul.left_nav %li - = link_to t('streams.mentions.title'), mentions_path, :class => 'home_selector', :rel => 'backbone' + = link_to t('streams.mentions.title'), mentioned_stream_path, :class => 'home_selector', :rel => 'backbone' %ul.left_nav %li - = link_to t('streams.comment_stream.title'), comment_stream_path, :class => 'home_selector', :rel => 'backbone' + = link_to t('streams.comment_stream.title'), commented_stream_path, :class => 'home_selector', :rel => 'backbone' %ul.left_nav %li - = link_to t('streams.like_stream.title'), like_stream_path, :class => 'home_selector', :rel => 'backbone' + = link_to t('streams.like_stream.title'), liked_stream_path, :class => 'home_selector', :rel => 'backbone' #followed_tags_listing = render 'tags/followed_tags_listings' diff --git a/app/views/layouts/main_stream.mobile.haml b/app/views/layouts/main_stream.mobile.haml new file mode 100644 index 000000000..4c5ab0cb9 --- /dev/null +++ b/app/views/layouts/main_stream.mobile.haml @@ -0,0 +1,18 @@ +-# Copyright (c) 2010-2011, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +%h2{:style => "padding:0 10px;display:none;"} + - if @stream.for_all_aspects? + = t('all_aspects') + - else + = @stream.aspect + +#main_stream.stream + = render 'shared/stream', :posts => @stream.stream_posts + -if @stream.stream_posts.length > 0 + #pagination + %a.more-link.paginate{:href => next_page_path} + %h1 + = t("more") + diff --git a/app/views/publics/host_meta.erb b/app/views/publics/host_meta.erb index fa8cd9879..bc7b16d4c 100644 --- a/app/views/publics/host_meta.erb +++ b/app/views/publics/host_meta.erb @@ -1,7 +1,7 @@ - <%= AppConfig[:pod_uri].authority %> + <%= AppConfig[:pod_bare_domain] %> Resource Descriptor diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index 012aa79be..b4a27188e 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -28,7 +28,7 @@ = t('username') = f.text_field :username, :title => t('registrations.new.enter_username') %span.host_uri - = "@#{AppConfig[:pod_uri].host}" + = diaspora_id_host .clearfix %b = t('email') diff --git a/app/views/registrations/new.mobile.haml b/app/views/registrations/new.mobile.haml index 17f0d5f5a..60b23c1f4 100644 --- a/app/views/registrations/new.mobile.haml +++ b/app/views/registrations/new.mobile.haml @@ -16,7 +16,7 @@ .centered = f.text_field :username %span.host_uri - = "@#{AppConfig[:pod_uri].host}" + = diaspora_id_host .row .row = f.label :email, t('email') diff --git a/app/views/tags/_followed_tags_listings.haml b/app/views/tags/_followed_tags_listings.haml index 30bed3e9f..3ed55ada3 100644 --- a/app/views/tags/_followed_tags_listings.haml +++ b/app/views/tags/_followed_tags_listings.haml @@ -5,7 +5,7 @@ - if user_signed_in? %ul.left_nav %li - %b=link_to t('streams.followed_tag.title'), tag_followings_path, :class => 'home_selector' + %b=link_to t('streams.followed_tag.title'), followed_tags_stream_path, :class => 'home_selector' - if @stream.is_a?(Stream::FollowedTag) %ul.sub_nav diff --git a/app/views/templates/comment.jst b/app/views/templates/comment.jst index e42f601a7..7397726dd 100644 --- a/app/views/templates/comment.jst +++ b/app/views/templates/comment.jst @@ -18,7 +18,9 @@ - <%= text %> +
+ <%= text %> +