diff --git a/.gitignore b/.gitignore index 8b309cc03..91e987e1c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,6 @@ db/*.sqlite3 log/*.log tmp/**/* +Gemfile.lock gpg/diaspora-development/*.gpg gpg/diaspora-production/*.gpg diff --git a/Gemfile b/Gemfile index 4f2c736a1..7be06ae84 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'http://rubygems.org' source 'http://gemcutter.org' -gem 'rails', '3.0.0.beta4' +gem 'rails', :git =>'http://github.com/rails/rails.git' gem 'bundler' gem 'mongo_mapper', :git => "http://github.com/BadMinus/mongomapper.git" gem 'devise', :git => "http://github.com/BadMinus/devise.git" diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index c5508d51c..11dbd939a 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -17,21 +17,21 @@ class DashboardsController < ApplicationController def warzombie render :nothing => true - if User.first.email == "tom@joindiaspora.com" && StatusMessage.where(:message => "There's a bomb in the lasagna!?").first == nil - StatusMessage.create(:message => "There's a bomb in the lasagna!?", :person => User.first) - Bookmark.create(:title => "xkcd", :link => "http://xkcd.com/743/", :person => User.first ) - StatusMessage.create(:message => "I switched to Motoroi today, a Motorola Android-based phone, in Korea. Now, I am using Android phones in both the U.S. and Korea", :person => User.first, :created_at => Time.now-930) - StatusMessage.create(:message => "I had 5 hours to study for it :-( GREs on Thursday. Wunderbar.", :person => User.first, :created_at => Time.now-43990) - StatusMessage.create(:message => "Spotted in toy story 3: google maps, OSX, and windows XP. Two out of three isn't bad.", :person => User.first, :created_at => Time.now-4390) - Bookmark.create( :title => "Reddit", :link => "http://reddit.com", :person => User.first, :created_at => Time.now-54390) - Blog.create(:title => "I Love Rock'N'Roll - Joan Jett & The Blackhearts", :body => "

The loudspeakers played this song as we walked into the city pool for the first time this summer. Those loudspeakers make every song sound fresh even if I have heard it a thousand times and their effect on this song was no different. Joan sounded young and strong and ready, and for a moment I forgot where or when I was.

also i can tell it won’t be long and also happy summer imaginary constructs -mumblelard

", :person => User.first, :created_at => Time.now-3090) - StatusMessage.create(:message => "Commercials for IE make me SO MAD and my friends just don't get why.", :person => User.first, :created_at => Time.now-30900) - Bookmark.create(:title => "Zombo.com", :link => "http://zombo.com", :person => User.first, :created_at => Time.now-9090) - StatusMessage.create(:message => "Why do I have \"No More Heroes\" by Westlife on repeat all day?", :person => User.first, :created_at => Time.now-590000) - StatusMessage.create(:message => "Mmm. Friday night. Acknowledged.", :person => User.first, :created_at => Time.now-503900) - StatusMessage.create(:message => "Getting a universal remote is the epitome of laziness, I do declare.", :person => User.first, :created_at => Time.now-4400) - StatusMessage.create(:message => "Does anyone know how to merge two Skype contact entries of the same person? (i.e. one Skype ID and one mobile number)", :person => User.first, :created_at => Time.now-400239) - StatusMessage.create(:message => "A cool, cool morning for once.", :person => User.first, :created_at => Time.now-150000) + if User.owner.email == "tom@joindiaspora.com" && StatusMessage.where(:message => "There's a bomb in the lasagna!?").first == nil + StatusMessage.create(:message => "There's a bomb in the lasagna!?", :person => User.owner) + Bookmark.create(:title => "xkcd", :link => "http://xkcd.com/743/", :person => User.owner ) + StatusMessage.create(:message => "I switched to Motoroi today, a Motorola Android-based phone, in Korea. Now, I am using Android phones in both the U.S. and Korea", :person => User.owner, :created_at => Time.now-930) + StatusMessage.create(:message => "I had 5 hours to study for it :-( GREs on Thursday. Wunderbar.", :person => User.owner, :created_at => Time.now-43990) + StatusMessage.create(:message => "Spotted in toy story 3: google maps, OSX, and windows XP. Two out of three isn't bad.", :person => User.owner, :created_at => Time.now-4390) + Bookmark.create( :title => "Reddit", :link => "http://reddit.com", :person => User.owner, :created_at => Time.now-54390) + Blog.create(:title => "I Love Rock'N'Roll - Joan Jett & The Blackhearts", :body => "

The loudspeakers played this song as we walked into the city pool for the first time this summer. Those loudspeakers make every song sound fresh even if I have heard it a thousand times and their effect on this song was no different. Joan sounded young and strong and ready, and for a moment I forgot where or when I was.

also i can tell it won’t be long and also happy summer imaginary constructs -mumblelard

", :person => User.owner, :created_at => Time.now-3090) + StatusMessage.create(:message => "Commercials for IE make me SO MAD and my friends just don't get why.", :person => User.owner, :created_at => Time.now-30900) + Bookmark.create(:title => "Zombo.com", :link => "http://zombo.com", :person => User.owner, :created_at => Time.now-9090) + StatusMessage.create(:message => "Why do I have \"No More Heroes\" by Westlife on repeat all day?", :person => User.owner, :created_at => Time.now-590000) + StatusMessage.create(:message => "Mmm. Friday night. Acknowledged.", :person => User.owner, :created_at => Time.now-503900) + StatusMessage.create(:message => "Getting a universal remote is the epitome of laziness, I do declare.", :person => User.owner, :created_at => Time.now-4400) + StatusMessage.create(:message => "Does anyone know how to merge two Skype contact entries of the same person? (i.e. one Skype ID and one mobile number)", :person => User.owner, :created_at => Time.now-400239) + StatusMessage.create(:message => "A cool, cool morning for once.", :person => User.owner, :created_at => Time.now-150000) end end end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index d8769d448..44bdaf63f 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -12,9 +12,8 @@ class PeopleController < ApplicationController end def destroy - @person = Person.where(:id => params[:id]).first - @person.destroy - flash[:notice] = "Successfully destroyed person." + current_user.unfriend(params[:id]) + flash[:notice] = "unfriended person." redirect_to people_url end diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index 4bafd6d54..c37a86ca7 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -8,13 +8,15 @@ class RequestsController < ApplicationController def destroy if params[:accept] - current_user.accept_friend_request params[:id] - flash[:notice] = "you are now friends with #{@request.person.real_name}" + @friend = current_user.accept_friend_request params[:id] + + flash[:notice] = "you are now friends" + redirect_to root_url else current_user.ignore_friend_request params[:id] flash[:notice] = "ignored friend request" + redirect_to requests_url end - redirect_to requests_url end @@ -24,11 +26,13 @@ class RequestsController < ApplicationController def create @request = current_user.send_friend_request_to(params[:request][:destination_url]) - if @request flash[:notice] = "a friend request was sent to #{@request.destination_url}" redirect_to requests_url else + + flash[:error] = "you have already friended this person" + @request = Request.new render :action => 'new' end end diff --git a/app/controllers/sockets_controller.rb b/app/controllers/sockets_controller.rb index daea6466a..67ffc7dc8 100644 --- a/app/controllers/sockets_controller.rb +++ b/app/controllers/sockets_controller.rb @@ -3,12 +3,6 @@ class SocketsController < ApplicationController include SocketsHelper include Rails.application.routes.url_helpers before_filter :authenticate_user! - - - - # def default_url_options() - # {:host=> 'example.com'} - # end def incoming(msg) puts "#{msg} connected!" @@ -20,12 +14,11 @@ class SocketsController < ApplicationController def outgoing(object) @_request = ActionDispatch::Request.new({}) + puts action_hash(object) WebSocket.push_to_clients(action_hash(object)) end def delete_subscriber(sid) WebSocket.unsubscribe(sid) end - - end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c476210ab..897c4826a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,7 +10,7 @@ module ApplicationHelper end def mine?(post) - post.person == User.first + post.person == User.owner end def type_partial(post) @@ -39,9 +39,9 @@ module ApplicationHelper def owner_picture default = "/images/user/default.jpg" - image = "/images/user/#{User.first.profile.last_name.gsub(/ /,'').downcase}.jpg" + image = "/images/user/#{User.owner.profile.last_name.gsub(/ /,'').downcase}.jpg" - if File.exist?("public/images/user/#{User.first.profile.last_name.gsub(/ /,'').downcase}.jpg") + if File.exist?("public/images/user/#{User.owner.profile.last_name.gsub(/ /,'').downcase}.jpg") image_tag image, :id => "user_picture" else image_tag default, :id => "user_picture" diff --git a/app/models/comment.rb b/app/models/comment.rb index b8a682a94..b1cdc493b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -29,7 +29,7 @@ class Comment protected def send_people_comments_on_my_posts - if User.first.mine?(self.post) && !(self.person.is_a? User) + if User.owner.mine?(self.post) && !(self.person.is_a? User) self.push_to(self.post.people_with_permissions) end end diff --git a/app/models/person.rb b/app/models/person.rb index 7ace2308d..d299b35fc 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -30,6 +30,7 @@ class Person scope :friends, where(:_type => "Person", :active => true) + def real_name "#{profile.first_name.to_s} #{profile.last_name.to_s}" diff --git a/app/models/post.rb b/app/models/post.rb index ae6d11af3..c29c9510b 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -36,7 +36,7 @@ class Post end def self.my_newest - self.newest(User.first) + self.newest(User.owner) end def self.newest_by_email(email) self.newest(Person.first(:email => email)) diff --git a/app/models/retraction.rb b/app/models/retraction.rb index a4d10bb59..c799df5fd 100644 --- a/app/models/retraction.rb +++ b/app/models/retraction.rb @@ -2,21 +2,44 @@ class Retraction include ROXML include Diaspora::Webhooks - def self.for(post) - result = self.new - result.post_id = post.id - result.person_id = post.person.id - result + def self.for(object) + retraction = self.new + retraction.post_id= object.id + retraction.person_id = person_id_from(object) + retraction.type = self.type_name(object) + retraction end xml_accessor :post_id xml_accessor :person_id + xml_accessor :type attr_accessor :post_id attr_accessor :person_id - + attr_accessor :type + def perform - Post.delete(self.post_id) + puts('GO GO GO') + self.type.constantize.destroy(self.post_id) + end + + def self.person_id_from(object) + if object.is_a? Person + object.id + else + object.person.id + end + end + + + def self.type_name(object) + if object.is_a? Post + object.class + elsif object.is_a? User + 'Person' + else + 'Clowntown' + end end end diff --git a/app/models/user.rb b/app/models/user.rb index 9c7393ecd..1e7aa4bd7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,7 +8,9 @@ class User < Person validates_presence_of :profile before_validation :do_bad_things - + + + ######## Commenting ######## def comment(text, options = {}) @@ -29,10 +31,11 @@ class User < Person def send_friend_request_to(friend_url) unless Person.where(:url => friend_url).first p = Request.instantiate(:to => friend_url, :from => self) + puts p.inspect if p.save p.push_to_url friend_url - p end + p end end @@ -46,7 +49,7 @@ class User < Person end def ignore_friend_request(friend_request_id) - request = Request.where(:id => friend_request_id).first + request = Request.first(:id => friend_request_id) person = request.person person.destroy unless person.active request.destroy @@ -62,6 +65,14 @@ class User < Person end end + def unfriend(friend_id) + bad_friend = Person.first(:id => friend_id, :active => true) + if bad_friend + Retraction.for(self).push_to_url(bad_friend.url) + bad_friend.destroy + end + end + ###Helpers############ def mine?(post) @@ -72,6 +83,9 @@ class User < Person self.password_confirmation = self.password end + def self.owner + User.first + end protected diff --git a/app/views/devise/sessions/new.html.haml b/app/views/devise/sessions/new.html.haml index 79a391314..96b9ca9c4 100644 --- a/app/views/devise/sessions/new.html.haml +++ b/app/views/devise/sessions/new.html.haml @@ -6,7 +6,7 @@ /= f.check_box :remember_me /= f.label :remember_me - = hidden_field_tag "user_email", "#{User.first.email}", :name => "user[email]" + = hidden_field_tag "user_email", "#{User.owner.email}", :name => "user[email]" = f.submit "Sign in" /= render :partial => "devise/shared/links" diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 09c7dff3b..79abadcdf 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,7 +2,7 @@ %html %head %title - = User.first.real_name if User.first + = current_user.real_name if current_user = " | diaspora" %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ @@ -30,7 +30,7 @@ #session_action - if user_signed_in? - =User.first.real_name + = current_user.real_name | = link_to "requests (#{@request_count})", requests_path | @@ -50,9 +50,9 @@ .span-20 - if user_signed_in? %h1#user_name - = link_to User.first.real_name, root_url + = link_to current_user.real_name, root_url %span.description = my_latest_message = yield - .span-20 + .span-12 = render "posts/debug" diff --git a/app/views/layouts/session_wall.html.haml b/app/views/layouts/session_wall.html.haml index f4b13e524..19e9d2043 100644 --- a/app/views/layouts/session_wall.html.haml +++ b/app/views/layouts/session_wall.html.haml @@ -39,11 +39,11 @@ - flash.each do |name, msg| = content_tag :div, msg, :id => "flash_#{name}" - - if User.first + - if User.owner %div#huge_text welcome back, %span - = User.first.real_name.downcase + = User.owner.real_name.downcase = yield -else %div#huge_text diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index ccdabacd3..50050d2eb 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -1,5 +1,6 @@ .span-20.last %h1= "#{@person.real_name}" + = link_to 'remove friend', @person, :confirm => 'Are you sure?', :method => :delete - if @person_profile %p %b First Name diff --git a/app/views/requests/_request.html.haml b/app/views/requests/_request.html.haml index 84284151a..39a4114b3 100644 --- a/app/views/requests/_request.html.haml +++ b/app/views/requests/_request.html.haml @@ -4,6 +4,6 @@ = "#{request.destination_url}" .destroy_link - = link_to 'Accept', request_path(request, :accept => true), :confirm => 'Are you sure?', :method => :delete + = link_to 'Accept', request_path(request, :accept => true), :method => :delete | = link_to 'Ignore', request_path(request), :confirm => 'Are you sure?', :method => :delete diff --git a/config/environments/development.rb b/config/environments/development.rb index d03bf7d3a..12446d661 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -16,6 +16,6 @@ Diaspora::Application.configure do # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = false - + config.active_support.deprecation = :log #config.threadsafe! end diff --git a/lib/common.rb b/lib/common.rb index c0fd6947f..fcd9cd82b 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -33,7 +33,7 @@ module Diaspora if p.is_a? Retraction p.perform elsif p.is_a? Request - User.first.receive_friend_request(p) + User.owner.receive_friend_request(p) #This line checks if the sender was in the database, among other things? elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User) #WTF p.save @@ -47,10 +47,11 @@ module Diaspora def self.included(klass) klass.class_eval do include ROXML + require 'message_handler' @@queue = MessageHandler.new def notify_people - if self.person_id == User.first.id + if self.person_id == User.owner.id push_to(people_with_permissions) end end @@ -76,7 +77,7 @@ module Diaspora end def people_with_permissions - Person.where( :_type => "Person" ).all + Person.friends.all end def self.build_xml_for(posts) diff --git a/public/javascripts/jquery_form.js b/public/javascripts/jquery_form.js deleted file mode 100644 index be8c0b6bf..000000000 --- a/public/javascripts/jquery_form.js +++ /dev/null @@ -1,675 +0,0 @@ -/*! - * jQuery Form Plugin - * version: 2.43 (12-MAR-2010) - * @requires jQuery v1.3.2 or later - * - * Examples and documentation at: http://malsup.com/jquery/form/ - * Dual licensed under the MIT and GPL licenses: - * http://www.opensource.org/licenses/mit-license.php - * http://www.gnu.org/licenses/gpl.html - */ -;(function($) { - -/* - Usage Note: - ----------- - Do not use both ajaxSubmit and ajaxForm on the same form. These - functions are intended to be exclusive. Use ajaxSubmit if you want - to bind your own submit handler to the form. For example, - - $(document).ready(function() { - $('#myForm').bind('submit', function() { - $(this).ajaxSubmit({ - target: '#output' - }); - return false; // <-- important! - }); - }); - - Use ajaxForm when you want the plugin to manage all the event binding - for you. For example, - - $(document).ready(function() { - $('#myForm').ajaxForm({ - target: '#output' - }); - }); - - When using ajaxForm, the ajaxSubmit function will be invoked for you - at the appropriate time. -*/ - -/** - * ajaxSubmit() provides a mechanism for immediately submitting - * an HTML form using AJAX. - */ -$.fn.ajaxSubmit = function(options) { - // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) - if (!this.length) { - log('ajaxSubmit: skipping submit process - no element selected'); - return this; - } - - if (typeof options == 'function') - options = { success: options }; - - var url = $.trim(this.attr('action')); - if (url) { - // clean url (don't include hash vaue) - url = (url.match(/^([^#]+)/)||[])[1]; - } - url = url || window.location.href || ''; - - options = $.extend({ - url: url, - type: this.attr('method') || 'GET', - iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' - }, options || {}); - - // hook for manipulating the form data before it is extracted; - // convenient for use with rich editors like tinyMCE or FCKEditor - var veto = {}; - this.trigger('form-pre-serialize', [this, options, veto]); - if (veto.veto) { - log('ajaxSubmit: submit vetoed via form-pre-serialize trigger'); - return this; - } - - // provide opportunity to alter form data before it is serialized - if (options.beforeSerialize && options.beforeSerialize(this, options) === false) { - log('ajaxSubmit: submit aborted via beforeSerialize callback'); - return this; - } - - var a = this.formToArray(options.semantic); - if (options.data) { - options.extraData = options.data; - for (var n in options.data) { - if(options.data[n] instanceof Array) { - for (var k in options.data[n]) - a.push( { name: n, value: options.data[n][k] } ); - } - else - a.push( { name: n, value: options.data[n] } ); - } - } - - // give pre-submit callback an opportunity to abort the submit - if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) { - log('ajaxSubmit: submit aborted via beforeSubmit callback'); - return this; - } - - // fire vetoable 'validate' event - this.trigger('form-submit-validate', [a, this, options, veto]); - if (veto.veto) { - log('ajaxSubmit: submit vetoed via form-submit-validate trigger'); - return this; - } - - var q = $.param(a); - - if (options.type.toUpperCase() == 'GET') { - options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; - options.data = null; // data is null for 'get' - } - else - options.data = q; // data is the query string for 'post' - - var $form = this, callbacks = []; - if (options.resetForm) callbacks.push(function() { $form.resetForm(); }); - if (options.clearForm) callbacks.push(function() { $form.clearForm(); }); - - // perform a load on the target only if dataType is not provided - if (!options.dataType && options.target) { - var oldSuccess = options.success || function(){}; - callbacks.push(function(data) { - var fn = options.replaceTarget ? 'replaceWith' : 'html'; - $(options.target)[fn](data).each(oldSuccess, arguments); - }); - } - else if (options.success) - callbacks.push(options.success); - - options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg - for (var i=0, max=callbacks.length; i < max; i++) - callbacks[i].apply(options, [data, status, xhr || $form, $form]); - }; - - // are there files to upload? - var files = $('input:file', this).fieldValue(); - var found = false; - for (var j=0; j < files.length; j++) - if (files[j]) - found = true; - - var multipart = false; -// var mp = 'multipart/form-data'; -// multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); - - // options.iframe allows user to force iframe mode - // 06-NOV-09: now defaulting to iframe mode if file input is detected - if ((files.length && options.iframe !== false) || options.iframe || found || multipart) { - // hack to fix Safari hang (thanks to Tim Molendijk for this) - // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d - if (options.closeKeepAlive) - $.get(options.closeKeepAlive, fileUpload); - else - fileUpload(); - } - else - $.ajax(options); - - // fire 'notify' event - this.trigger('form-submit-notify', [this, options]); - return this; - - - // private function for handling file uploads (hat tip to YAHOO!) - function fileUpload() { - var form = $form[0]; - - if ($(':input[name=submit]', form).length) { - alert('Error: Form elements must not be named "submit".'); - return; - } - - var opts = $.extend({}, $.ajaxSettings, options); - var s = $.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts); - - var id = 'jqFormIO' + (new Date().getTime()); - var $io = $('