Merging in friend-refactor...
|
|
@ -12,7 +12,8 @@ class AlbumsController < ApplicationController
|
|||
flash[:notice] = "Successfully created album."
|
||||
redirect_to @album
|
||||
else
|
||||
render :action => 'new'
|
||||
flash[:error] = "Successfully failed."
|
||||
redirect_to albums_path
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,12 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def set_friends_and_status
|
||||
@friends = Person.friends.all if current_user
|
||||
@latest_status_message = StatusMessage.newest(current_user) if current_user
|
||||
|
||||
if current_user
|
||||
@groups = current_user.groups
|
||||
@friends = current_user.friends
|
||||
@latest_status_message = StatusMessage.newest_for(current_user.person)
|
||||
@group = params[:group] ? current_user.group_by_id(params[:group]) : current_user.groups.first
|
||||
end
|
||||
end
|
||||
|
||||
def count_requests
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ class BlogsController < ApplicationController
|
|||
|
||||
if @blog.created_at
|
||||
flash[:notice] = "Successfully created blog."
|
||||
redirect_to @blog
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,11 +4,6 @@ class BookmarksController < ApplicationController
|
|||
def index
|
||||
@bookmark = Bookmark.new
|
||||
@bookmarks = Bookmark.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
|
|
@ -34,7 +29,6 @@ class BookmarksController < ApplicationController
|
|||
|
||||
if @bookmark.created_at
|
||||
flash[:notice] = "Successfully created bookmark."
|
||||
redirect_to @bookmark
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
class DashboardsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
include ApplicationHelper
|
||||
|
||||
def index
|
||||
@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,33 +1,37 @@
|
|||
class DevUtilitiesController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
before_filter :authenticate_user!, :except => [:set_backer_number]
|
||||
include ApplicationHelper
|
||||
include RequestsHelper
|
||||
def warzombie
|
||||
render :nothing => true
|
||||
if User.owner.email == "tom@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 => "<p>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.</p> <p>also i can tell it won’t be long and also happy summer imaginary constructs -mumblelard</p>", :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)
|
||||
if current_user.email == "tom@tom.joindiaspora.com" && StatusMessage.where(:message => "There's a bomb in the lasagna!?").first == nil
|
||||
current_user.post(:status_message, :message => "There's a bomb in the lasagna!?")
|
||||
current_user.post(:bookmark, :title => "xkcd", :link => "http://xkcd.com/743/" )
|
||||
current_user.post(:status_message, :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", :created_at => Time.now-930)
|
||||
current_user.post(:status_message, :message => "I had 5 hours to study for it :-( GREs on Thursday. Wunderbar.", :created_at => Time.now-43990)
|
||||
current_user.post(:status_message, :message => "Spotted in toy story 3: google maps, OSX, and windows XP. Two out of three isn't bad.", :created_at => Time.now-4390)
|
||||
current_user.post(:bookmark, :title => "Reddit", :link => "http://reddit.com", :created_at => Time.now-54390)
|
||||
current_user.post(:blog, :title => "I Love Rock'N'Roll - Joan Jett & The Blackhearts", :body => "<p>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.</p> <p>also i can tell it won’t be long and also happy summer imaginary constructs -mumblelard</p>", :created_at => Time.now-3090)
|
||||
current_user.post(:status_message, :message => "Commercials for IE make me SO MAD and my friends just don't get why.", :created_at => Time.now-30900)
|
||||
current_user.post(:bookmark, :title => "Zombo.com", :link => "http://zombo.com", :created_at => Time.now-9090)
|
||||
current_user.post(:status_message, :message => "Why do I have \"No More Heroes\" by Westlife on repeat all day?", :created_at => Time.now-590000)
|
||||
current_user.post(:status_message, :message => "Mmm. Friday night. Acknowledged.", :created_at => Time.now-503900)
|
||||
current_user.post(:status_message, :message => "Getting a universal remote is the epitome of laziness, I do declare.", :created_at => Time.now-4400)
|
||||
current_user.post(:status_message, :message => "Does anyone know how to merge two Skype contact entries of the same person? (i.e. one Skype ID and one mobile number)", :created_at => Time.now-400239)
|
||||
current_user.post(:status_message, :message => "A cool, cool morning for once.", :created_at => Time.now-150000)
|
||||
end
|
||||
end
|
||||
|
||||
def zombiefriends
|
||||
render :nothing => true
|
||||
backer_info
|
||||
if User.owner.email == "tom@tom.joindiaspora.com" && Person.friends.first.nil?
|
||||
backer_info.each do |backer|
|
||||
bkr_info = backer_info
|
||||
|
||||
if current_user.email == "tom@tom.joindiaspora.com"
|
||||
bkr_info.each do |backer|
|
||||
backer_email = "#{backer['username']}@#{backer['username']}.joindiaspora.com"
|
||||
rel_hash = relationship_flow(backer_email)
|
||||
logger.info "Zombefriending #{backer['given_name']} #{backer['family_name']}"
|
||||
User.owner.send_friend_request_to("http://#{backer['username']}.joindiaspora.com/")
|
||||
current_user.send_request(rel_hash, current_user.groups.first.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -35,7 +39,7 @@ def warzombie
|
|||
def zombiefriendaccept
|
||||
render :nothing => true
|
||||
Request.all.each{|r|
|
||||
User.owner.accept_friend_request(r.id)
|
||||
current_user.accept_and_respond(r.id, current_user.groups.first.id)
|
||||
}
|
||||
end
|
||||
|
||||
|
|
@ -44,4 +48,11 @@ def warzombie
|
|||
config['servers']['backer']
|
||||
end
|
||||
|
||||
def set_backer_number
|
||||
render :nothing => true
|
||||
seed_num_hash = {:seed_number => params[:number]}
|
||||
file = File.new(Rails.root.join('config','backer_number.yml'),'w')
|
||||
file.write(seed_num_hash.to_yaml)
|
||||
file.close
|
||||
end
|
||||
end
|
||||
|
|
|
|||
50
app/controllers/groups_controller.rb
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
class GroupsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
@posts = Post.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
end
|
||||
|
||||
def create
|
||||
@group = current_user.group(params[:group])
|
||||
|
||||
if @group.created_at
|
||||
flash[:notice] = "Successfully created group."
|
||||
redirect_to @group
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@group = Group.new
|
||||
end
|
||||
|
||||
def destroy
|
||||
@group = Group.first(:id => params[:id])
|
||||
@group.destroy
|
||||
flash[:notice] = "Successfully destroyed group."
|
||||
redirect_to groups_url
|
||||
end
|
||||
|
||||
def show
|
||||
@people_ids = @group.people.map {|p| p.id}
|
||||
@posts = Post.paginate :person_id => @people_ids, :order => 'created_at DESC'
|
||||
@group = Group.first(:id => params[:id])
|
||||
end
|
||||
|
||||
def edit
|
||||
@group = Group.first(:id => params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@group = Group.first(:id => params[:id])
|
||||
if @group.update_attributes(params[:group])
|
||||
flash[:notice] = "Successfully updated group."
|
||||
redirect_to @group
|
||||
else
|
||||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -3,7 +3,7 @@ class PeopleController < ApplicationController
|
|||
|
||||
def index
|
||||
unless params[:q]
|
||||
@people = Person.friends.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
@people = current_user.friends.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
render :index
|
||||
else
|
||||
@people = Person.search_for_friends(params[:q])
|
||||
|
|
@ -12,15 +12,16 @@ class PeopleController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@person= Person.where(:id => params[:id]).first
|
||||
@person= current_user.friend_by_id(params[:id])
|
||||
|
||||
@person_profile = @person.profile
|
||||
@person_posts = Post.where(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC'
|
||||
@latest_status_message = StatusMessage.newest(@person)
|
||||
@latest_status_message = StatusMessage.newest_for(@person)
|
||||
@post_count = @person_posts.count
|
||||
end
|
||||
|
||||
def destroy
|
||||
current_user.unfriend(params[:id])
|
||||
current_user.unfriend(current_user.friend_by_id(params[:id]))
|
||||
flash[:notice] = "unfriended person."
|
||||
redirect_to people_url
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ class PhotosController < ApplicationController
|
|||
|
||||
if @photo.created_at
|
||||
flash[:notice] = "Successfully uploaded photo."
|
||||
redirect_to @photo.album
|
||||
else
|
||||
render :action => 'album#new'
|
||||
end
|
||||
|
|
@ -25,14 +24,14 @@ class PhotosController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@photo = Photo.where(:id => params[:id]).first
|
||||
@photo = Photo.first(:id => params[:id])
|
||||
@photo.destroy
|
||||
flash[:notice] = "Successfully deleted photo."
|
||||
redirect_to @photo.album
|
||||
end
|
||||
|
||||
def show
|
||||
@photo = Photo.where(:id => params[:id]).first
|
||||
@photo = Photo.first(:id => params[:id])
|
||||
@album = @photo.album
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,23 +3,28 @@ class PublicsController < ApplicationController
|
|||
include Diaspora::Parser
|
||||
|
||||
def hcard
|
||||
@user = User.owner
|
||||
render 'hcard'
|
||||
@person = Person.first(:_id => params[:id])
|
||||
|
||||
unless @person.nil? || @person.owner.nil?
|
||||
render 'hcard'
|
||||
end
|
||||
end
|
||||
|
||||
def host_meta
|
||||
@user = User.owner
|
||||
render 'host_meta', :layout => false, :content_type => 'application/xrd+xml'
|
||||
end
|
||||
|
||||
def webfinger
|
||||
@user = Person.first(:email => params[:q].gsub('acct:', ''))
|
||||
render 'webfinger', :layout => false, :content_type => 'application/xrd+xml'
|
||||
@person = Person.by_webfinger(params[:q])
|
||||
unless @person.nil? || @person.owner.nil?
|
||||
render 'webfinger', :layout => false, :content_type => 'application/xrd+xml'
|
||||
end
|
||||
end
|
||||
|
||||
def receive
|
||||
puts "SOMEONE JUST SENT ME: #{params[:xml]}"
|
||||
store_objects_from_xml params[:xml]
|
||||
@user = Person.first(:id => params[:id]).owner
|
||||
Rails.logger.debug "PublicsController has received: #{params[:xml]}"
|
||||
@user.receive params[:xml] if params[:xml]
|
||||
render :nothing => true
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,16 @@ class RequestsController < ApplicationController
|
|||
|
||||
def destroy
|
||||
if params[:accept]
|
||||
@friend = current_user.accept_friend_request params[:id]
|
||||
|
||||
flash[:notice] = "you are now friends"
|
||||
redirect_to root_url
|
||||
|
||||
if params[:group_id]
|
||||
@friend = current_user.accept_and_respond( params[:id], params[:group_id])
|
||||
|
||||
flash[:notice] = "you are now friends"
|
||||
redirect_to root_url
|
||||
else
|
||||
flash[:error] = "please select a group!"
|
||||
redirect_to requests_url
|
||||
end
|
||||
else
|
||||
current_user.ignore_friend_request params[:id]
|
||||
flash[:notice] = "ignored friend request"
|
||||
|
|
@ -26,8 +32,8 @@ class RequestsController < ApplicationController
|
|||
|
||||
def create
|
||||
rel_hash = relationship_flow(params[:request][:destination_url])
|
||||
Rails.logger.info("Sending request: #{rel_hash}")
|
||||
@request = current_user.send_request(rel_hash)
|
||||
Rails.logger.debug("Sending request: #{rel_hash}")
|
||||
@request = current_user.send_request(rel_hash, params[:request][:group])
|
||||
|
||||
if @request
|
||||
flash[:notice] = "a friend request was sent to #{@request.destination_url}"
|
||||
|
|
@ -43,9 +49,4 @@ class RequestsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,22 +2,14 @@ class SocketsController < ApplicationController
|
|||
include ApplicationHelper
|
||||
include SocketsHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def incoming(msg)
|
||||
puts "#{msg} connected!"
|
||||
puts "Got a connection to: #{msg}"
|
||||
end
|
||||
|
||||
def new_subscriber
|
||||
WebSocket.subscribe
|
||||
end
|
||||
|
||||
def outgoing(object)
|
||||
def outgoing(uid,object)
|
||||
@_request = ActionDispatch::Request.new({})
|
||||
WebSocket.push_to_clients(action_hash(object))
|
||||
Diaspora::WebSocket.push_to_user(uid, action_hash(uid, object))
|
||||
end
|
||||
|
||||
def delete_subscriber(sid)
|
||||
WebSocket.unsubscribe(sid)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class StatusMessagesController < ApplicationController
|
||||
#before_filter :authenticate_user!
|
||||
before_filter :authenticate_user!
|
||||
|
||||
def index
|
||||
@status_messages = StatusMessage.paginate :page => params[:page], :order => 'created_at DESC'
|
||||
|
|
@ -16,7 +16,6 @@ class StatusMessagesController < ApplicationController
|
|||
|
||||
if @status_message.created_at
|
||||
flash[:notice] = "Successfully created status message."
|
||||
redirect_to status_messages_url
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
|
|
@ -38,7 +37,7 @@ class StatusMessagesController < ApplicationController
|
|||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => Post.build_xml_for(@status_message) }
|
||||
format.xml { render :xml => @status_message.build_xml_for }
|
||||
format.json { render :json => @status_message }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
class UsersController < ApplicationController
|
||||
before_filter :authenticate_user!, :except => [:new, :create]
|
||||
|
||||
before_filter :authenticate_user!
|
||||
def index
|
||||
@users = User.sort(:created_at.desc).all
|
||||
end
|
||||
def show
|
||||
@user= Person.first(:id => params[:id])
|
||||
@user_profile = @user.profile
|
||||
@user= User.first(:id => params[:id])
|
||||
@user_profile = @user.person.profile
|
||||
end
|
||||
|
||||
def edit
|
||||
|
|
@ -25,4 +25,20 @@ class UsersController < ApplicationController
|
|||
render :action => 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.instantiate(params[:user])
|
||||
|
||||
if @user.created_at && @user.person.created_at
|
||||
flash[:notice] = "Successfully signed up."
|
||||
redirect_to root_path
|
||||
else
|
||||
render :action => 'new'
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def mine?(post)
|
||||
post.person == User.owner
|
||||
current_user.owns? post
|
||||
end
|
||||
|
||||
def type_partial(post)
|
||||
|
|
@ -31,12 +31,12 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
def link_to_person(person)
|
||||
link_to person.real_name, person_path(person)
|
||||
def owner_image_tag
|
||||
person_image_tag(current_user)
|
||||
end
|
||||
|
||||
def owner_image_tag
|
||||
person_image_tag(User.owner)
|
||||
def owner_image_link
|
||||
person_image_link(current_user)
|
||||
end
|
||||
|
||||
def person_image_tag(person)
|
||||
|
|
@ -50,10 +50,6 @@ module ApplicationHelper
|
|||
link_to person_image_tag(person), object_path(person)
|
||||
end
|
||||
|
||||
def owner_image_link
|
||||
person_image_link(User.owner)
|
||||
end
|
||||
|
||||
def new_request(request_count)
|
||||
"new_requests" if request_count > 0
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
module CommentsHelper
|
||||
def target
|
||||
|
||||
end
|
||||
|
||||
def text
|
||||
params[:comment][:text]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ module PhotosHelper
|
|||
end
|
||||
|
||||
def link_to_prev(photo, album)
|
||||
link_to "<< previous", photo_path(album.prev_photo(photo)), :rel => "prefetch"
|
||||
link_to "<< prev", photo_path(album.prev_photo(photo)), :rel => "prefetch"
|
||||
end
|
||||
|
||||
def link_to_next(photo, album)
|
||||
|
|
|
|||
|
|
@ -14,4 +14,11 @@ module PublicsHelper
|
|||
400
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def terse_url(full_url)
|
||||
terse = full_url.gsub(/https?:\/\//, '')
|
||||
terse.gsub!(/www\./, '')
|
||||
terse = terse.chop! if terse[-1, 1] == '/'
|
||||
terse
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,10 +26,16 @@ module RequestsHelper
|
|||
end
|
||||
|
||||
def relationship_flow(identifier)
|
||||
f = Redfinger.finger(identifier)
|
||||
action = subscription_mode(f)
|
||||
url = subscription_url(action, f)
|
||||
|
||||
puts request.host
|
||||
if identifier.include?(request.host)
|
||||
person = Person.by_webfinger identifier
|
||||
action = (person == current_user.person ? :none : :friend)
|
||||
url = person.owner.receive_url
|
||||
else
|
||||
f = Redfinger.finger(identifier)
|
||||
action = subscription_mode(f)
|
||||
url = subscription_url(action, f)
|
||||
end
|
||||
{ action => url }
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,17 +5,16 @@ module SocketsHelper
|
|||
(object.is_a? Post) ? object.id : object.post_id
|
||||
end
|
||||
|
||||
def url_options
|
||||
{:host => ""}
|
||||
end
|
||||
#def url_options
|
||||
# {:host => ""}
|
||||
#end
|
||||
|
||||
def action_hash(object)
|
||||
def action_hash(uid, object)
|
||||
begin
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object}) unless object.is_a? Retraction
|
||||
user = User.first(:id => uid)
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
|
||||
rescue Exception => e
|
||||
puts "web socket view rendering failed for some reason." + v.inspect
|
||||
puts object.inspect
|
||||
puts e.message
|
||||
Rails.logger.error("web socket view rendering failed for object #{object.inspect}.")
|
||||
raise e
|
||||
end
|
||||
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
||||
|
|
@ -24,6 +23,7 @@ module SocketsHelper
|
|||
action_hash[:photo_hash] = object.thumb_hash
|
||||
elsif object.is_a? StatusMessage
|
||||
action_hash[:status_message_hash] = object.latest_hash
|
||||
action_hash[:status_message_hash][:mine?] = true if object.person.owner_id == uid
|
||||
end
|
||||
|
||||
action_hash.to_json
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
module StatusMessagesHelper
|
||||
|
||||
def my_latest_message
|
||||
unless @latest_status_message.nil?
|
||||
return @latest_status_message.message
|
||||
|
|
@ -7,7 +6,4 @@ module StatusMessagesHelper
|
|||
return "No message to display."
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ class Album
|
|||
|
||||
def self.mine_or_friends(friend_param, current_user)
|
||||
if friend_param
|
||||
Album.where(:person_id.ne => current_user.id)
|
||||
Album.where(:person_id => current_user.friend_ids)
|
||||
else
|
||||
Album.where(:person_id => current_user.id)
|
||||
current_user.person.albums
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ class Blog < Post
|
|||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<title>#{self.title}</title>
|
||||
<content>#{self.body}</content>
|
||||
<link rel="alternate" type="text/html" href="#{User.owner.url}blogs/#{self.id}"/>
|
||||
<id>#{User.owner.url}blogs/#{self.id}</id>
|
||||
<link rel="alternate" type="text/html" href="#{person.url}blogs/#{self.id}"/>
|
||||
<id>#{person.url}blogs/#{self.id}</id>
|
||||
<published>#{self.created_at.xmlschema}</published>
|
||||
<updated>#{self.updated_at.xmlschema}</updated>
|
||||
</entry>
|
||||
|
|
|
|||
|
|
@ -12,27 +12,31 @@ class Bookmark < Post
|
|||
validates_format_of :link, :with =>
|
||||
/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
|
||||
|
||||
before_validation :clean_link
|
||||
|
||||
def to_activity
|
||||
<<-XML
|
||||
<entry>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<title>#{self.title}</title>
|
||||
<link rel="alternate" type="text/html" href="#{User.owner.url}bookmarks/#{self.id}"/>
|
||||
<link rel="alternate" type="text/html" href="#{person.url}bookmarks/#{self.id}"/>
|
||||
<link rel="related" type="text/html" href="#{self.link}"/>
|
||||
<id>#{User.owner.url}bookmarks/#{self.id}</id>
|
||||
<id>#{person.url}bookmarks/#{self.id}</id>
|
||||
<published>#{self.created_at.xmlschema}</published>
|
||||
<updated>#{self.updated_at.xmlschema}</updated>
|
||||
</entry>
|
||||
XML
|
||||
end
|
||||
|
||||
def self.instantiate params
|
||||
params[:link] = clean_link(params[:link])
|
||||
create params
|
||||
end
|
||||
|
||||
protected
|
||||
def clean_link
|
||||
if self.link
|
||||
self.link = 'http://' + self.link unless self.link.match('https?://')
|
||||
self.link = self.link + '/' if self.link[-1,1] != '/'
|
||||
def self.clean_link link
|
||||
if link
|
||||
link = 'http://' + link unless link.match('https?://')
|
||||
link = link + '/' if link[-1,1] != '/'
|
||||
link
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@ class Comment
|
|||
include ROXML
|
||||
include Diaspora::Webhooks
|
||||
include Encryptable
|
||||
include Diaspora::Socketable
|
||||
|
||||
xml_accessor :text
|
||||
xml_accessor :person, :as => Person
|
||||
xml_accessor :post_id
|
||||
|
||||
xml_accessor :_id
|
||||
|
||||
key :text, String
|
||||
timestamps!
|
||||
|
|
@ -17,19 +18,22 @@ class Comment
|
|||
|
||||
key :person_id, ObjectId
|
||||
belongs_to :person, :class_name => "Person"
|
||||
|
||||
after_save :send_people_comments_on_my_posts
|
||||
after_save :send_to_view
|
||||
|
||||
|
||||
def ==(other)
|
||||
(self.message == other.message) && (self.person.email == other.person.email)
|
||||
end
|
||||
validates_presence_of :text
|
||||
|
||||
def push_upstream
|
||||
Rails.logger.info("GOIN UPSTREAM")
|
||||
push_to([post.person])
|
||||
end
|
||||
|
||||
def push_downstream
|
||||
Rails.logger.info("SWIMMIN DOWNSTREAM")
|
||||
push_to(post.people_with_permissions)
|
||||
end
|
||||
|
||||
#ENCRYPTION
|
||||
|
||||
before_validation :sign_if_mine, :sign_if_my_post
|
||||
#validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
||||
validates_true_for :post_creator_signature, :logic => lambda {self.verify_post_creator_signature}
|
||||
|
||||
xml_accessor :creator_signature
|
||||
|
|
@ -53,8 +57,7 @@ class Comment
|
|||
end
|
||||
|
||||
def verify_post_creator_signature
|
||||
unless person == User.owner
|
||||
puts "verifying post creator sig from #{post.person.real_name}"
|
||||
if person.owner.nil?
|
||||
verify_signature(post_creator_signature, post.person)
|
||||
else
|
||||
true
|
||||
|
|
@ -64,19 +67,9 @@ class Comment
|
|||
|
||||
protected
|
||||
def sign_if_my_post
|
||||
if self.post.person == User.owner
|
||||
self.post_creator_signature = sign
|
||||
unless self.post.person.owner.nil?
|
||||
self.post_creator_signature = sign_with_key self.post.person.encryption_key
|
||||
end
|
||||
end
|
||||
|
||||
def send_people_comments_on_my_posts
|
||||
if User.owner.mine?(self.post) && !(self.person.is_a? User)
|
||||
self.push_to(self.post.people_with_permissions)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def send_to_view
|
||||
SocketsController.new.outgoing(self)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
19
app/models/group.rb
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class Group
|
||||
include MongoMapper::Document
|
||||
|
||||
key :name, String
|
||||
|
||||
key :person_ids, Array
|
||||
key :request_ids, Array
|
||||
key :post_ids, Array
|
||||
|
||||
many :people, :in => :person_ids, :class_name => 'Person'
|
||||
many :requests, :in => :request_ids, :class_name => 'Request'
|
||||
many :posts, :in => :post_ids, :class_name => 'Post'
|
||||
|
||||
belongs_to :user, :class_name => 'User'
|
||||
|
||||
timestamps!
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -5,32 +5,35 @@ class Person
|
|||
xml_accessor :_id
|
||||
xml_accessor :email
|
||||
xml_accessor :url
|
||||
xml_accessor :serialized_key
|
||||
xml_accessor :profile, :as => Profile
|
||||
|
||||
|
||||
key :email, String
|
||||
key :email, String, :unique => true
|
||||
key :url, String
|
||||
key :active, Boolean, :default => false
|
||||
|
||||
key :serialized_key, String
|
||||
|
||||
|
||||
key :owner_id, ObjectId
|
||||
key :user_refs, Integer, :default => 0
|
||||
|
||||
belongs_to :owner, :class_name => 'User'
|
||||
one :profile, :class_name => 'Profile'
|
||||
|
||||
many :posts, :class_name => 'Post', :foreign_key => :person_id
|
||||
many :albums, :class_name => 'Album', :foreign_key => :person_id
|
||||
|
||||
|
||||
timestamps!
|
||||
|
||||
before_validation :clean_url
|
||||
validates_presence_of :email, :url, :serialized_key
|
||||
validates_presence_of :email, :url, :profile, :serialized_key
|
||||
validates_format_of :url, :with =>
|
||||
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
|
||||
|
||||
validates_true_for :url, :logic => lambda { self.url_unique?}
|
||||
|
||||
after_destroy :remove_all_traces
|
||||
|
||||
scope :friends, where(:_type => "Person", :active => true)
|
||||
|
||||
def self.search_for_friends(query)
|
||||
Person.all('$where' => "function() { return this.profile.first_name.match(/^#{query}/i) || this.profile.last_name.match(/^#{query}/i); }")
|
||||
|
|
@ -40,25 +43,84 @@ class Person
|
|||
"#{profile.first_name.to_s} #{profile.last_name.to_s}"
|
||||
end
|
||||
|
||||
def key
|
||||
def encryption_key
|
||||
OpenSSL::PKey::RSA.new( serialized_key )
|
||||
end
|
||||
|
||||
def key= new_key
|
||||
def encryption_key= new_key
|
||||
raise TypeError unless new_key.class == OpenSSL::PKey::RSA
|
||||
serialized_key = new_key.export
|
||||
end
|
||||
def export_key
|
||||
key.public_key.export
|
||||
encryption_key.public_key.export
|
||||
end
|
||||
|
||||
|
||||
######## Posting ########
|
||||
def post(class_name, options = {})
|
||||
options[:person] = self
|
||||
model_class = class_name.to_s.camelize.constantize
|
||||
post = model_class.instantiate(options)
|
||||
post.notify_people
|
||||
post.socket_to_uid owner.id if (owner_id && post.respond_to?( :socket_to_uid))
|
||||
post
|
||||
end
|
||||
|
||||
######## Commenting ########
|
||||
def comment(text, options = {})
|
||||
raise "must comment on something!" unless options[:on]
|
||||
c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
|
||||
if c.save
|
||||
begin
|
||||
dispatch_comment c
|
||||
rescue Exception => e
|
||||
puts e.inspect
|
||||
raise e
|
||||
end
|
||||
|
||||
|
||||
c.socket_to_uid owner.id if owner_id
|
||||
true
|
||||
else
|
||||
Rails.logger.warn "this failed to save: #{c.inspect}"
|
||||
end
|
||||
false
|
||||
end
|
||||
|
||||
def dispatch_comment( c )
|
||||
if owns? c.post
|
||||
c.push_downstream
|
||||
elsif owns? c
|
||||
c.push_upstream
|
||||
end
|
||||
end
|
||||
##profile
|
||||
def update_profile(params)
|
||||
if self.update_attributes(params)
|
||||
self.profile.notify_people!
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def owns?(post)
|
||||
self.id == post.person.id
|
||||
end
|
||||
|
||||
def receive_url
|
||||
"#{self.url}receive/users/#{self.id}/"
|
||||
end
|
||||
|
||||
def self.by_webfinger( identifier )
|
||||
Person.first(:email => identifier.gsub('acct:', ''))
|
||||
end
|
||||
|
||||
def remote?
|
||||
owner.nil?
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def url_unique?
|
||||
same_url = Person.first(:url => self.url)
|
||||
return same_url.nil? || same_url.id == self.id
|
||||
end
|
||||
|
||||
def clean_url
|
||||
self.url ||= "http://localhost:3000/" if self.class == User
|
||||
if self.url
|
||||
|
|
|
|||
|
|
@ -37,22 +37,20 @@ class Photo < Post
|
|||
end
|
||||
|
||||
def remote_photo
|
||||
@remote_photo ||= User.owner.url.chop + image.url
|
||||
@remote_photo ||= self.person.url.chop + image.url
|
||||
end
|
||||
|
||||
def remote_photo= remote_path
|
||||
Rails.logger.info("Setting remote photo with id #{id}")
|
||||
@remote_photo = remote_path
|
||||
image.download! remote_path
|
||||
image.store!
|
||||
Rails.logger.info("Setting remote photo with id #{id}")
|
||||
end
|
||||
|
||||
def ensure_user_picture
|
||||
user = User.owner
|
||||
if user.profile.image_url == image.url(:thumb_medium)
|
||||
users = Person.all('profile.image_url' => image.url(:thumb_medium) )
|
||||
users.each{ |user|
|
||||
user.profile.update_attributes!(:image_url => nil)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def thumb_hash
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ class Post
|
|||
include ROXML
|
||||
include Diaspora::Webhooks
|
||||
include Encryptable
|
||||
include Diaspora::Socketable
|
||||
|
||||
xml_accessor :_id
|
||||
xml_accessor :person, :as => Person
|
||||
|
|
@ -20,11 +21,8 @@ class Post
|
|||
|
||||
timestamps!
|
||||
|
||||
after_save :send_to_view
|
||||
after_save :notify_people
|
||||
|
||||
before_destroy :propagate_retraction
|
||||
after_destroy :destroy_comments, :remove_from_view
|
||||
after_destroy :destroy_comments
|
||||
|
||||
def self.instantiate params
|
||||
self.create params
|
||||
|
|
@ -35,19 +33,10 @@ class Post
|
|||
Post.sort(:created_at.desc).all
|
||||
end
|
||||
|
||||
def self.newest(person = nil)
|
||||
return self.last if person.nil?
|
||||
|
||||
def self.newest_for(person)
|
||||
self.first(:person_id => person.id, :order => '_id desc')
|
||||
end
|
||||
|
||||
def self.my_newest
|
||||
self.newest(User.owner)
|
||||
end
|
||||
def self.newest_by_email(email)
|
||||
self.newest(Person.first(:email => email))
|
||||
end
|
||||
|
||||
#ENCRYPTION
|
||||
before_validation :sign_if_mine
|
||||
validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
||||
|
|
@ -69,10 +58,10 @@ class Post
|
|||
end
|
||||
|
||||
def log_inspection
|
||||
Rails.logger.info self.inspect
|
||||
Rails.logger.debug self.inspect
|
||||
end
|
||||
def log_save_inspection
|
||||
Rails.logger.info "After saving, object is:"
|
||||
Rails.logger.debug "After saving, object is:"
|
||||
log_inspection
|
||||
end
|
||||
|
||||
|
|
@ -85,13 +74,7 @@ protected
|
|||
Retraction.for(self).notify_people
|
||||
end
|
||||
|
||||
def send_to_view
|
||||
SocketsController.new.outgoing(self)
|
||||
end
|
||||
|
||||
def remove_from_view
|
||||
SocketsController.new.outgoing(Retraction.for(self))
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ class Profile
|
|||
self._parent_document.id
|
||||
end
|
||||
|
||||
def to_diaspora_xml
|
||||
"<post>"+ self.to_xml.to_s + "</post>"
|
||||
def person
|
||||
Person.first(:id => self.person_id)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ class Request
|
|||
key :callback_url, String
|
||||
key :person_id, ObjectId
|
||||
key :exported_key, String
|
||||
key :group_id, ObjectId
|
||||
|
||||
belongs_to :person
|
||||
|
||||
|
|
@ -25,23 +26,35 @@ class Request
|
|||
|
||||
before_validation :clean_link
|
||||
|
||||
scope :for_user, lambda{ |user| where(:destination_url => user.url) }
|
||||
scope :from_user, lambda{ |user| where(:destination_url.ne => user.url) }
|
||||
scope :for_user, lambda{ |user| where(:destination_url => user.receive_url) }
|
||||
scope :from_user, lambda{ |user| where(:destination_url.ne => user.receive_url) }
|
||||
|
||||
def self.instantiate(options ={})
|
||||
def self.instantiate(options = {})
|
||||
person = options[:from]
|
||||
self.new(:destination_url => options[:to], :callback_url => person.url, :person => person, :exported_key => person.export_key)
|
||||
self.new(:destination_url => options[:to],
|
||||
:callback_url => person.receive_url,
|
||||
:person => person,
|
||||
:exported_key => person.export_key,
|
||||
:group_id => options[:into])
|
||||
end
|
||||
|
||||
def activate_friend
|
||||
p = Person.where(:url => self.person.url).first
|
||||
p.active = true
|
||||
p.save
|
||||
|
||||
def reverse accepting_user
|
||||
self.person = accepting_user.person
|
||||
self.exported_key = accepting_user.export_key
|
||||
self.destination_url = self.callback_url
|
||||
save
|
||||
end
|
||||
|
||||
def set_pending_friend
|
||||
p = Person.first(:id => self.person.id)
|
||||
|
||||
self.person.save #save pending friend
|
||||
|
||||
end
|
||||
|
||||
#ENCRYPTION
|
||||
before_validation :sign_if_mine
|
||||
validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
||||
#before_validation :sign_if_mine
|
||||
#validates_true_for :creator_signature, :logic => lambda {self.verify_creator_signature}
|
||||
|
||||
xml_accessor :creator_signature
|
||||
key :creator_signature, String
|
||||
|
|
|
|||
|
|
@ -5,9 +5,15 @@ class Retraction
|
|||
|
||||
def self.for(object)
|
||||
retraction = self.new
|
||||
retraction.post_id= object.id
|
||||
if object.is_a? User
|
||||
retraction.post_id = object.person.id
|
||||
retraction.type = object.person.class.to_s
|
||||
else
|
||||
retraction.post_id = object.id
|
||||
retraction.type = object.class.to_s
|
||||
end
|
||||
retraction.person_id = person_id_from(object)
|
||||
retraction.type = object.class.to_s
|
||||
retraction.send(:sign_if_mine)
|
||||
retraction
|
||||
end
|
||||
|
||||
|
|
@ -19,10 +25,14 @@ class Retraction
|
|||
attr_accessor :person_id
|
||||
attr_accessor :type
|
||||
|
||||
def perform
|
||||
def perform receiving_user_id
|
||||
Rails.logger.debug "Performing retraction for #{post_id}"
|
||||
begin
|
||||
return unless signature_valid?
|
||||
self.type.constantize.destroy(self.post_id)
|
||||
return unless signature_valid?
|
||||
Rails.logger.debug("Retracting #{self.type} id: #{self.post_id}")
|
||||
target = self.type.constantize.first(self.post_id)
|
||||
target.unsocket_from_uid receiving_user_id if target.respond_to? :unsocket_from_uid
|
||||
target.destroy
|
||||
rescue NameError
|
||||
Rails.logger.info("Retraction for unknown type recieved.")
|
||||
end
|
||||
|
|
@ -44,12 +54,22 @@ class Retraction
|
|||
object.person.id
|
||||
end
|
||||
end
|
||||
|
||||
def person
|
||||
Person.first(:id => self.person_id)
|
||||
end
|
||||
|
||||
#ENCRYPTION
|
||||
xml_reader :creator_signature
|
||||
|
||||
def creator_signature
|
||||
@creator_signature ||= sign if person_id == User.owner.id
|
||||
object = self.type.constantize.first(:id => post_id)
|
||||
|
||||
if object.class == Person && person_id == object.id
|
||||
@creator_signature || sign_with_key(object.key)
|
||||
elsif person_id == object.person.id
|
||||
@creator_signature || sign_if_mine
|
||||
end
|
||||
end
|
||||
|
||||
def creator_signature= input
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class StatusMessage < Post
|
|||
<entry>
|
||||
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
|
||||
<title>#{self.message}</title>
|
||||
<link rel="alternate" type="text/html" href="#{User.owner.url}status_messages/#{self.id}"/>
|
||||
<id>#{User.owner.url}status_messages/#{self.id}</id>
|
||||
<link rel="alternate" type="text/html" href="#{person.url}status_messages/#{self.id}"/>
|
||||
<id>#{person.url}status_messages/#{self.id}</id>
|
||||
<published>#{self.created_at.xmlschema}</published>
|
||||
<updated>#{self.updated_at.xmlschema}</updated>
|
||||
</entry>
|
||||
|
|
@ -22,7 +22,7 @@ class StatusMessage < Post
|
|||
end
|
||||
|
||||
def latest_hash
|
||||
{:mine? => self.person == User.owner, :text => message}
|
||||
{ :text => message}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,109 +1,188 @@
|
|||
class User < Person
|
||||
class User
|
||||
include MongoMapper::Document
|
||||
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
|
||||
key :friend_ids, Array
|
||||
key :pending_request_ids, Array
|
||||
|
||||
one :person, :class_name => 'Person', :foreign_key => :owner_id
|
||||
|
||||
many :friends, :in => :friend_ids, :class_name => 'Person'
|
||||
many :pending_requests, :in => :pending_request_ids, :class_name => 'Request'
|
||||
|
||||
many :groups, :class_name => 'Group'
|
||||
|
||||
before_validation_on_create :assign_key
|
||||
validates_presence_of :profile
|
||||
|
||||
before_validation :do_bad_things
|
||||
|
||||
|
||||
######## Posting ########
|
||||
######## Making things work ########
|
||||
|
||||
def post(class_name, options = {})
|
||||
options[:person] = self
|
||||
model_class = class_name.to_s.camelize.constantize
|
||||
post = model_class.instantiate(options)
|
||||
key :email, String
|
||||
|
||||
def method_missing(method, *args)
|
||||
self.person.send(method, *args)
|
||||
end
|
||||
|
||||
######## Commenting ########
|
||||
def comment(text, options = {})
|
||||
raise "must comment on something!" unless options[:on]
|
||||
c = Comment.new(:person_id => self.id, :text => text, :post => options[:on])
|
||||
if c.save
|
||||
if mine?(c.post)
|
||||
c.push_to(c.post.people_with_permissions) # should return plucky query
|
||||
else
|
||||
c.push_to([c.post.person])
|
||||
end
|
||||
true
|
||||
end
|
||||
false
|
||||
|
||||
def real_name
|
||||
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
|
||||
end
|
||||
|
||||
##profile
|
||||
def update_profile(params)
|
||||
if self.update_attributes(params)
|
||||
puts self.profile.class
|
||||
self.profile.notify_people!
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
######### Groups ######################
|
||||
|
||||
def group( opts = {} )
|
||||
opts[:user] = self
|
||||
Group.create(opts)
|
||||
end
|
||||
|
||||
######### Friend Requesting
|
||||
def send_friend_request_to(friend_url)
|
||||
unless Person.where(:url => friend_url).first
|
||||
p = Request.instantiate(:to => friend_url, :from => self)
|
||||
if p.save
|
||||
p.push_to_url friend_url
|
||||
######### Friend Requesting ###########
|
||||
def send_friend_request_to(friend_url, group_id)
|
||||
unless self.friends.detect{ |x| x.receive_url == friend_url}
|
||||
request = Request.instantiate(:to => friend_url, :from => self.person, :into => group_id)
|
||||
if request.save
|
||||
self.pending_requests << request
|
||||
self.save
|
||||
|
||||
group = self.group_by_id(group_id)
|
||||
|
||||
group.requests << request
|
||||
group.save
|
||||
|
||||
request.push_to_url friend_url
|
||||
end
|
||||
p
|
||||
request
|
||||
end
|
||||
end
|
||||
|
||||
def accept_friend_request(friend_request_id)
|
||||
def accept_friend_request(friend_request_id, group_id)
|
||||
request = Request.where(:id => friend_request_id).first
|
||||
request.activate_friend
|
||||
request.person = self
|
||||
request.exported_key = self.export_key
|
||||
request.destination_url = request.callback_url
|
||||
n = pending_requests.delete(request)
|
||||
|
||||
activate_friend(request.person, group_by_id(group_id))
|
||||
|
||||
request.reverse self
|
||||
request
|
||||
end
|
||||
|
||||
def dispatch_friend_acceptance(request)
|
||||
request.push_to_url(request.callback_url)
|
||||
request.destroy
|
||||
request.destroy unless request.callback_url.include? url
|
||||
end
|
||||
|
||||
def accept_and_respond(friend_request_id, group_id)
|
||||
dispatch_friend_acceptance(accept_friend_request(friend_request_id, group_id))
|
||||
end
|
||||
|
||||
def ignore_friend_request(friend_request_id)
|
||||
request = Request.first(:id => friend_request_id)
|
||||
person = request.person
|
||||
person.destroy unless person.active
|
||||
person.user_refs -= 1
|
||||
pending_requests.delete(request)
|
||||
save
|
||||
(person.user_refs > 0 || person.owner.nil? == false) ? person.save : person.destroy
|
||||
request.destroy
|
||||
end
|
||||
|
||||
def receive_friend_request(friend_request)
|
||||
Rails.logger.info("receiving friend request #{friend_request.to_json}")
|
||||
friend_request.person.serialized_key = friend_request.exported_key
|
||||
if Request.where(:callback_url => friend_request.callback_url).first
|
||||
friend_request.activate_friend
|
||||
if request_from_me?(friend_request)
|
||||
group = self.group_by_id(friend_request.group_id)
|
||||
activate_friend(friend_request.person, group)
|
||||
|
||||
Rails.logger.info("#{self.real_name}'s friend request has been accepted")
|
||||
friend_request.destroy
|
||||
else
|
||||
friend_request.person.user_refs += 1
|
||||
friend_request.person.save
|
||||
pending_requests << friend_request
|
||||
save
|
||||
Rails.logger.info("#{self.real_name} has received a friend request")
|
||||
friend_request.save
|
||||
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
|
||||
def unfriend(bad_friend)
|
||||
Rails.logger.info("#{self.real_name} is unfriending #{bad_friend.inspect}")
|
||||
Retraction.for(self).push_to_url(bad_friend.receive_url)
|
||||
remove_friend(bad_friend)
|
||||
end
|
||||
|
||||
def remove_friend(bad_friend)
|
||||
raise "Friend not deleted" unless self.friend_ids.delete( bad_friend.id )
|
||||
groups.each{|g| g.person_ids.delete( bad_friend.id )}
|
||||
self.save
|
||||
bad_friend.user_refs -= 1
|
||||
(bad_friend.user_refs > 0 || bad_friend.owner.nil? == false) ? bad_friend.save : bad_friend.destroy
|
||||
end
|
||||
|
||||
def send_request(rel_hash)
|
||||
def unfriended_by(bad_friend)
|
||||
Rails.logger.info("#{self.real_name} is being unfriended by #{bad_friend.inspect}")
|
||||
remove_friend bad_friend
|
||||
end
|
||||
|
||||
def send_request(rel_hash, group)
|
||||
if rel_hash[:friend]
|
||||
self.send_friend_request_to(rel_hash[:friend])
|
||||
self.send_friend_request_to(rel_hash[:friend], group)
|
||||
else
|
||||
raise "you can't do anything to that url"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def activate_friend(person, group)
|
||||
person.user_refs += 1
|
||||
group.people << person
|
||||
friends << person
|
||||
person.save
|
||||
group.save
|
||||
save
|
||||
end
|
||||
|
||||
def request_from_me?(request)
|
||||
pending_requests.detect{|req| (req.callback_url == person.receive_url) && (req.destination_url == person.receive_url)}
|
||||
end
|
||||
|
||||
###### Receiving #######
|
||||
def receive xml
|
||||
object = Diaspora::Parser.from_xml(xml)
|
||||
Rails.logger.debug("Receiving object:\n#{object.inspect}")
|
||||
|
||||
if object.is_a? Retraction
|
||||
if object.type == 'Person' && object.signature_valid?
|
||||
|
||||
Rails.logger.info( "the person id is #{object.post_id} the friend found is #{friend_by_id(object.post_id).inspect}")
|
||||
unfriended_by friend_by_id(object.post_id)
|
||||
|
||||
else
|
||||
object.perform self.id
|
||||
end
|
||||
elsif object.is_a? Request
|
||||
person = Diaspora::Parser.get_or_create_person_object_from_xml( xml )
|
||||
person.serialized_key ||= object.exported_key
|
||||
object.person = person
|
||||
object.person.save
|
||||
old_request = Request.first(:id => object.id)
|
||||
object.group_id = old_request.group_id if old_request
|
||||
object.save
|
||||
receive_friend_request(object)
|
||||
elsif object.is_a? Profile
|
||||
person = Diaspora::Parser.owner_id_from_xml xml
|
||||
person.profile = object
|
||||
person.save
|
||||
elsif object.verify_creator_signature == true
|
||||
Rails.logger.debug("Saving object: #{object}")
|
||||
object.save
|
||||
object.socket_to_uid( id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
|
||||
dispatch_comment object if object.is_a?(Comment) && !owns?(object)
|
||||
end
|
||||
end
|
||||
|
||||
###Helpers############
|
||||
def mine?(post)
|
||||
self == post.person
|
||||
def self.instantiate( opts = {} )
|
||||
opts[:person][:email] = opts[:email]
|
||||
opts[:person][:serialized_key] = generate_key
|
||||
User.create( opts)
|
||||
end
|
||||
|
||||
def terse_url
|
||||
|
|
@ -117,18 +196,29 @@ class User < Person
|
|||
self.password_confirmation = self.password
|
||||
end
|
||||
|
||||
def self.owner
|
||||
User.first
|
||||
def friend_by_id( id )
|
||||
friends.detect{|x| x.id == ensure_bson( id ) }
|
||||
end
|
||||
|
||||
|
||||
def group_by_id( id )
|
||||
groups.detect{|x| x.id == ensure_bson( id ) }
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def assign_key
|
||||
self.serialized_key ||= generate_key.export
|
||||
self.person.serialized_key ||= generate_key.export
|
||||
end
|
||||
|
||||
def generate_key
|
||||
OpenSSL::PKey::RSA::generate 1024
|
||||
end
|
||||
|
||||
def self.generate_key
|
||||
OpenSSL::PKey::RSA::generate 1024
|
||||
end
|
||||
|
||||
def ensure_bson id
|
||||
id.class == String ? BSON::ObjectID(id) : id
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ class ImageUploader < CarrierWave::Uploader::Base
|
|||
end
|
||||
|
||||
version :thumb_large do
|
||||
process :resize_to_fill => [300,200]
|
||||
process :resize_to_fill => [300,300]
|
||||
end
|
||||
|
||||
version :scaled_full do
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
.album{:id => post.id, :class => ("mine" if mine?(post))}
|
||||
.album{:id => post.id, :class => ("mine" if current_user.owns?(post))}
|
||||
|
||||
%div.name
|
||||
= link_to post.name, object_path(post)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
%h1 Add a new album
|
||||
|
||||
= form_for Album.new do |f|
|
||||
= f.error_messages
|
||||
%p
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
.back= link_to "⇧ #{@album.name}", @album
|
||||
%h1.big_text
|
||||
.back
|
||||
= link_to "⇧ #{@album.name}", @album
|
||||
|
||||
= "Editing #{@album.name}"
|
||||
|
||||
|
|
@ -12,6 +11,10 @@
|
|||
%p
|
||||
= a.text_field :name
|
||||
|
||||
%ul
|
||||
- for photo in @album.photos
|
||||
%li.photo_edit_block= image_tag photo.image.url(:thumb_large)
|
||||
|
||||
#submit_block
|
||||
= link_to "Cancel", root_path
|
||||
or
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
.back= link_to "⇧ home", root_path
|
||||
%h1.big_text
|
||||
.back
|
||||
= link_to "⇧ home", root_path
|
||||
Albums
|
||||
.button.right#add_album_button
|
||||
= link_to 'New Album', "#"
|
||||
.right
|
||||
= link_to 'New Album', '#new_album_pane', {:class => "button", :id => "add_album_button"}
|
||||
|
||||
#add_album_box.contextual_pane
|
||||
.yo{:style => "display:none;" }
|
||||
#new_album_pane
|
||||
= render "albums/new_album"
|
||||
|
||||
.sub_header
|
||||
%ul.button_set
|
||||
%li.selected= friends_albums_link
|
||||
%li= your_albums_link
|
||||
%li{:class => ("selected" if params[:friends])}= friends_albums_link
|
||||
%li{:class => ("selected" if not params[:friends])}= your_albums_link
|
||||
|
||||
%div
|
||||
- for album in @albums
|
||||
|
|
|
|||
|
|
@ -1,20 +1,22 @@
|
|||
.back= link_to '⇧ albums', albums_path
|
||||
%h1.big_text
|
||||
.back
|
||||
= link_to '⇧ albums', albums_path
|
||||
|
||||
= @album.name
|
||||
|
||||
-if mine? @album
|
||||
.button.right#add_photos_button
|
||||
= link_to 'Add Photos', '#'
|
||||
-if current_user.owns? @album
|
||||
.right
|
||||
#add_photo_loader
|
||||
= image_tag 'ajax-loader.gif'
|
||||
= link_to 'Add Photos', '#new_photo_pane', :class => 'button', :id => "add_photo_button"
|
||||
|
||||
#add_photo_box.contextual_pane
|
||||
.yo{:style => "display:none;"}
|
||||
#new_photo_pane
|
||||
= render "photos/new_photo", :photo => @photo, :album => @album
|
||||
|
||||
.sub_header
|
||||
="updated #{how_long_ago(@album)}"
|
||||
|
||||
-unless mine? @album
|
||||
-unless current_user.owns? @album
|
||||
%h4= "by #{@album.person.real_name}"
|
||||
|
||||
#thumbnails
|
||||
|
|
@ -25,6 +27,7 @@
|
|||
#content_bottom
|
||||
.back
|
||||
= link_to "⇧ albums", albums_path
|
||||
-if mine? @album
|
||||
.button.right
|
||||
= link_to 'Edit Album', edit_album_path(@album)
|
||||
|
||||
-if current_user.owns? @album
|
||||
.right
|
||||
= link_to 'Edit Album', edit_album_path(@album), :class => 'button'
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||
%li.message{:id => post.id, :class => ("mine" if current_user.owns?(post))}
|
||||
|
||||
= person_image_tag(post.person)
|
||||
|
||||
%span.from
|
||||
= link_to_person post.person
|
||||
= link_to post.person.real_name, post.person
|
||||
%b wrote a new blog post
|
||||
%br
|
||||
%b= post.title
|
||||
|
|
@ -15,6 +15,6 @@
|
|||
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
|
||||
= render "comments/comments", :post => post
|
||||
|
||||
- if mine?(post)
|
||||
- if current_user.owns?(post)
|
||||
.destroy_link
|
||||
= link_to 'Delete', blog_path(post), :confirm => 'Are you sure?', :method => :delete, :remote=> true
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||
%li.message{:id => post.id, :class => ("mine" if current_user.owns?(post))}
|
||||
|
||||
= person_image_tag(post.person)
|
||||
|
||||
%span.from
|
||||
= link_to_person post.person
|
||||
= link_to post.person.real_name, post.person
|
||||
%b shared a link
|
||||
%br
|
||||
= post.title
|
||||
|
|
@ -16,6 +16,6 @@
|
|||
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
|
||||
= render "comments/comments", :post => post
|
||||
|
||||
- if mine?(post)
|
||||
- if current_user.owns?(post)
|
||||
.destroy_link
|
||||
= link_to 'Delete', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
%li.comment{:id => post.id}
|
||||
= person_image_tag(post.person)
|
||||
%span.from
|
||||
= link_to_person post.person
|
||||
= link_to post.person.real_name, post.person
|
||||
= auto_link post.text
|
||||
%div.time
|
||||
= "#{time_ago_in_words(post.updated_at)} ago"
|
||||
|
|
|
|||
|
|
@ -1,17 +1,29 @@
|
|||
= image_tag "http://needcoffee.cachefly.net/needcoffee/uploads/2009/02/predator-arnold-schwarzenegger.jpg"
|
||||
|
||||
|
||||
%h2 Sign up
|
||||
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
|
||||
= devise_error_messages!
|
||||
%p
|
||||
= f.label :email
|
||||
%br/
|
||||
= f.text_field :email
|
||||
%p
|
||||
= f.label :password
|
||||
%br/
|
||||
= f.password_field :password
|
||||
%p
|
||||
= f.label :password_confirmation
|
||||
%br/
|
||||
= f.password_field :password_confirmation
|
||||
|
||||
= f.fields_for :person do |p|
|
||||
= p.hidden_field :url, :value => "http://google.com/"
|
||||
|
||||
= p.fields_for :profile do |pr|
|
||||
%p
|
||||
= pr.label :first_name
|
||||
= pr.text_field :first_name
|
||||
%p
|
||||
= pr.label :last_name
|
||||
= pr.text_field :last_name
|
||||
|
||||
%p= f.submit "Sign up"
|
||||
= render :partial => "devise/shared/links"
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
|
||||
%p
|
||||
= f.text_field :email
|
||||
%br
|
||||
= f.password_field :password
|
||||
/%p
|
||||
/- if devise_mapping.rememberable?
|
||||
/ = f.check_box :remember_me
|
||||
/ = f.label :remember_me
|
||||
%p
|
||||
- if devise_mapping.rememberable?
|
||||
/= f.check_box :remember_me
|
||||
/= f.label :remember_me
|
||||
|
||||
= hidden_field_tag "user_email", "#{User.owner.email}", :name => "user[email]"
|
||||
= f.submit "Sign in"
|
||||
/= render :partial => "devise/shared/links"
|
||||
= render :partial => "devise/shared/links"
|
||||
|
||||
|
|
|
|||
7
app/views/groups/_new_group.haml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
%h1 Add a new group
|
||||
= form_for Group.new do |f|
|
||||
= f.error_messages
|
||||
%p
|
||||
= f.label :name
|
||||
= f.text_field :name
|
||||
= f.submit 'create', :class => 'button'
|
||||
25
app/views/groups/edit.html.haml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
%h1.big_text
|
||||
.back
|
||||
= link_to "⇧ #{@group.name}", @group
|
||||
|
||||
= "Editing #{@group.name}"
|
||||
|
||||
.sub_header
|
||||
="updated #{how_long_ago(@group)}"
|
||||
|
||||
- form_for @group do |a|
|
||||
= a.error_messages
|
||||
%p
|
||||
= a.text_field :name
|
||||
|
||||
#submit_block
|
||||
= link_to "Cancel", root_path
|
||||
or
|
||||
= a.submit
|
||||
|
||||
.button.delete
|
||||
= link_to 'Delete Album', @group, :confirm => 'Are you sure?', :method => :delete
|
||||
|
||||
#content_bottom
|
||||
.back
|
||||
= link_to "⇧ #{@group.name}", @group
|
||||
11
app/views/groups/index.html.haml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
%h1
|
||||
welcome home,
|
||||
= current_user.profile.first_name
|
||||
|
||||
= render "shared/publisher"
|
||||
%ul#stream
|
||||
- for post in @posts
|
||||
= render type_partial(post), :post => post
|
||||
#pagination
|
||||
= will_paginate @posts
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
%h1.big_text
|
||||
=link_to 'albums', albums_path
|
||||
=link_to 'groups', groups_path
|
||||
>>
|
||||
new album
|
||||
new group
|
||||
|
||||
= form_for @album do |f|
|
||||
= form_for @group do |f|
|
||||
= f.error_messages
|
||||
%p
|
||||
= f.label :name
|
||||
|
|
@ -11,4 +11,4 @@
|
|||
%p
|
||||
= f.submit
|
||||
|
||||
%p= link_to "Back to List", albums_path
|
||||
%p= link_to "Back to List", groups_path
|
||||
|
|
@ -7,7 +7,9 @@
|
|||
$(document).ready(function(){
|
||||
function debug(str){ $("#debug").append("<p>" + str); };
|
||||
|
||||
ws = new WebSocket("ws://#{request.host}:8080/");
|
||||
ws = new WebSocket("ws://#{request.host}:8080/#{CGI::escape(current_user.id.to_s)}");
|
||||
|
||||
//Attach onmessage to websocket
|
||||
ws.onmessage = function(evt) {
|
||||
var obj = jQuery.parseJSON(evt.data);
|
||||
debug("got a " + obj['class']);
|
||||
|
|
@ -62,6 +64,7 @@
|
|||
|
||||
function processStatusMessage(className, html, messageHash){
|
||||
processPost(className, html);
|
||||
console.log(messageHash)
|
||||
if(messageHash['mine?']){
|
||||
updateMyLatestStatus(messageHash);
|
||||
}
|
||||
|
|
@ -76,7 +79,7 @@
|
|||
if (location.href.indexOf(photoHash['album_id']) == -1){
|
||||
return ;
|
||||
}
|
||||
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\'> \
|
||||
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
||||
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
||||
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
||||
</a> </div>"
|
||||
|
|
|
|||
|
|
@ -8,11 +8,17 @@
|
|||
|
||||
= stylesheet_link_tag "blueprint/screen", :media => 'screen'
|
||||
= stylesheet_link_tag "application", "ui", 'bubble'
|
||||
|
||||
= stylesheet_link_tag "/../javascripts/fancybox/jquery.fancybox-1.3.1"
|
||||
|
||||
/= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
|
||||
= javascript_include_tag 'jquery142', 'rails', 'google'
|
||||
= javascript_include_tag 'tiny_mce/tiny_mce', 'jquery.infieldlabel'
|
||||
= javascript_include_tag 'jquery.cycle/jquery.cycle.min.js'
|
||||
= javascript_include_tag 'view', 'publisher', 'image_picker'
|
||||
= javascript_include_tag 'tiny_mce/tiny_mce'
|
||||
= javascript_include_tag 'jquery.infieldlabel', 'jquery.cycle/jquery.cycle.min.js'
|
||||
|
||||
= javascript_include_tag 'fancybox/jquery.fancybox-1.3.1.pack'
|
||||
|
||||
= javascript_include_tag 'view', 'publisher', 'image_picker', 'group_nav'
|
||||
= render 'js/websocket_js'
|
||||
|
||||
= csrf_meta_tag
|
||||
|
|
@ -23,51 +29,31 @@
|
|||
= javascript_include_tag 'jquery.html5_upload'
|
||||
|
||||
%body
|
||||
- flash.each do |name, msg|
|
||||
= content_tag :div, msg, :id => "flash_#{name}"
|
||||
|
||||
%header
|
||||
.container
|
||||
- flash.each do |name, msg|
|
||||
= content_tag :div, msg, :id => "flash_#{name}"
|
||||
#session_action
|
||||
- if user_signed_in?
|
||||
%ul#user_menu
|
||||
%li.name= link_to current_user.real_name, current_user.person
|
||||
%li= link_to "requests (#{@request_count})", requests_path, :class => new_request(@request_count)
|
||||
%li= link_to "settings", edit_user_path(current_user)
|
||||
%li= link_to "logout", destroy_user_session_path
|
||||
- else
|
||||
= link_to "login", new_user_session_path
|
||||
|
||||
#diaspora_text{:href => root_path}
|
||||
= link_to "DIASPORA*", root_path
|
||||
%span.sub_text
|
||||
PREVIEW
|
||||
= render "shared/group_nav"
|
||||
|
||||
#session_action
|
||||
- if user_signed_in?
|
||||
= link_to_person current_user
|
||||
|
|
||||
= link_to "requests (#{@request_count})", requests_path, :class => new_request(@request_count)
|
||||
|
|
||||
= link_to "logout", destroy_user_session_path
|
||||
- else
|
||||
= link_to "login", new_user_session_path
|
||||
|
||||
.container
|
||||
- if user_signed_in?
|
||||
#user_name
|
||||
= link_to(person_image_tag(current_user), root_path)
|
||||
%h1
|
||||
= link_to current_user.real_name, root_path
|
||||
%span#latest_message
|
||||
= my_latest_message
|
||||
- unless @latest_status_message.nil?
|
||||
%span{:style => "font-size: small", :id => 'latest_message_time'}
|
||||
= " - #{how_long_ago @latest_status_message}"
|
||||
|
||||
%ul.nav
|
||||
%li= link_to "home", root_path
|
||||
%li= link_to "photos", albums_path
|
||||
%li= "|"
|
||||
%li= link_to "edit profile", edit_user_path(current_user)
|
||||
= link_to "photos", albums_path
|
||||
|
||||
.container
|
||||
.span-24.last
|
||||
.span-20.append-1.last
|
||||
|
||||
= yield
|
||||
|
||||
.span-3.last
|
||||
= render 'people/sidebar' if user_signed_in?
|
||||
|
||||
.span-24.last
|
||||
= render "posts/debug"
|
||||
= yield
|
||||
.span-24.last
|
||||
= render "posts/debug"
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
:javascript
|
||||
$(document).ready(function(){
|
||||
$("#user_password").focus();
|
||||
$("#user_email").focus();
|
||||
});
|
||||
|
||||
= csrf_meta_tag
|
||||
|
|
@ -40,18 +40,10 @@
|
|||
</div>
|
||||
<![endif]-->
|
||||
|
||||
|
||||
|
||||
- flash.each do |name, msg|
|
||||
= content_tag :div, msg, :id => "flash_#{name}"
|
||||
- if User.owner
|
||||
%div#huge_text
|
||||
welcome back,
|
||||
%span
|
||||
= User.owner.real_name.downcase
|
||||
= yield
|
||||
-else
|
||||
%div#huge_text
|
||||
%span
|
||||
you need to add a user first!
|
||||
|
||||
%div#huge_text
|
||||
diaspora
|
||||
= yield
|
||||
|
||||
/= link_to "signup", "/signup"
|
||||
|
|
|
|||
|
|
@ -4,45 +4,38 @@
|
|||
// WE INSERT ALBUM_ID PARAM HERE
|
||||
url: "/photos?album_id=#{album.id}",
|
||||
sendBoundary: window.FormData || $.browser.mozilla,
|
||||
onStart: function(event, total) {
|
||||
return confirm("You are about to upload " + total + " photos. Are you sure?");
|
||||
},
|
||||
setName: function(text) {
|
||||
$("#progress_report_name").text(text);
|
||||
},
|
||||
setStatus: function(text) {
|
||||
$("#progress_report_status").text(text);
|
||||
},
|
||||
setProgress: function(val) {
|
||||
//$("#progress_report_bar").css('width', Math.ceil(val*100)+"%");
|
||||
},
|
||||
onFinishOne: function(event, response, name, number, total) {
|
||||
//alert(response);
|
||||
},
|
||||
onFinish: function(event, total){
|
||||
$("#progress_report").delay(600).slideUp(200);
|
||||
$("#add_photo_box").delay(600).fadeOut(200);
|
||||
$("#add_photo_button").html( "Add Photos" );
|
||||
$("#add_photo_loader").fadeOut(400);
|
||||
|
||||
$("#photo_title_status").text("Done!");
|
||||
$("#progress_report").html("Great job!");
|
||||
},
|
||||
onStart: function(event, total){
|
||||
$("#progress_report").slideDown(600);
|
||||
$("#add_photo_button").html( "Uploading Photos" );
|
||||
$("#add_photo_loader").fadeIn(400);
|
||||
|
||||
$("form").fadeOut(0);
|
||||
$("#progress_report").fadeIn(0);
|
||||
$("#photo_title_status").text("Uploading...");
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
:css
|
||||
#progress_report, #progress_report_name, #progress_report_status{
|
||||
font-size: 12px;
|
||||
padding: 0;
|
||||
line-height: auto;
|
||||
}
|
||||
|
||||
%h1
|
||||
%span{:id=>"photo_title_status"}
|
||||
Add photos to
|
||||
%i= album.name
|
||||
= form_for photo, :html => {:multipart => true} do |f|
|
||||
= f.error_messages
|
||||
= f.hidden_field :album_id, :value => album.id
|
||||
= f.file_field :image, :multiple => 'multiple'
|
||||
|
||||
#progress_report{ :style => "display:none;" }
|
||||
= image_tag "loader.gif"
|
||||
#progress_report_name
|
||||
#progress_report_status{ :style => "font-style: italic;" }
|
||||
#progress_report{ :style => "display:none;text-align:center;" }
|
||||
= image_tag "ajax-loader.gif"
|
||||
#progress_report_name
|
||||
#progress_report_status
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
= person_image_tag(post.person)
|
||||
|
||||
%span.from
|
||||
= link_to_person post.person
|
||||
= link_to post.person.real_name, post.person
|
||||
%b
|
||||
posted a new photo to
|
||||
= link_to post.album.name, object_path(post.album)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#content_bottom
|
||||
.back
|
||||
= link_to "⇧ #{@album.name}", album_path(@album)
|
||||
-if mine? @album
|
||||
-if current_user.owns? @album
|
||||
.button.right
|
||||
= link_to 'Delete Photo', @photo, :confirm => 'Are you sure?', :method => :delete
|
||||
|
||||
|
|
|
|||
|
|
@ -1,33 +1,30 @@
|
|||
.back= link_to "⇧ #{@album.name}", album_path(@album)
|
||||
%h1.big_text
|
||||
.back
|
||||
= link_to "⇧ #{@album.name}", album_path(@album)
|
||||
= @photo.image
|
||||
|
||||
.button.right
|
||||
= link_to 'Edit Photo', edit_photo_path(@photo)
|
||||
.right
|
||||
= link_to 'Edit Photo', edit_photo_path(@photo), :class => "button"
|
||||
|
||||
.sub_header
|
||||
= link_to_prev @photo, @album
|
||||
|
|
||||
= link_to "full size", @photo.image.url
|
||||
|
|
||||
= link_to_next @photo, @album
|
||||
|
||||
%div{:id => @photo.id}
|
||||
|
||||
#show_photo
|
||||
= linked_scaled_photo @photo, @album
|
||||
|
||||
.caption
|
||||
= @photo.caption
|
||||
|
||||
#next_prev_links
|
||||
= link_to_prev @photo, @album
|
||||
|
|
||||
= link_to_next @photo, @album
|
||||
|
||||
#content_bottom
|
||||
.back
|
||||
= link_to "⇧ #{@album.name}", album_path(@album)
|
||||
-if mine? @album
|
||||
.button.right
|
||||
= link_to 'Delete Photo', @photo, :confirm => 'Are you sure?', :method => :delete
|
||||
|
||||
-if current_user.owns? @album
|
||||
.right
|
||||
= link_to 'Delete Photo', @photo, :confirm => 'Are you sure?', :method => :delete, :class => 'button'
|
||||
|
||||
%h4{:class => "show_post_comments"}
|
||||
= "comments (#{@photo.comments.count})"
|
||||
|
|
|
|||
|
|
@ -1,24 +1,24 @@
|
|||
<div id="content">
|
||||
<h1><%=@user.real_name%></h1>
|
||||
<h1><%=@person.real_name%></h1>
|
||||
<div id="content_inner">
|
||||
<div id="i" class="entity_profile vcard author">
|
||||
<h2>User profile</h2>
|
||||
<dl class="entity_nickname">
|
||||
<dt>Nickname</dt>
|
||||
<dd>
|
||||
<a href="<%=@user.url%>" rel="me" class="nickname url uid"><%= @user.real_name%></a>
|
||||
<a href="<%=@person.url%>" rel="me" class="nickname url uid"><%= @person.real_name%></a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_fn">
|
||||
<dt>Full name</dt>
|
||||
<dd>
|
||||
<span class="fn"><%= @user.real_name %></span>
|
||||
<span class="fn"><%= @person.real_name %></span>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_url">
|
||||
<dt>URL</dt>
|
||||
<dd>
|
||||
<a href="<%= @user.url%>" rel="me" class="url"><%= @user.url%></a>
|
||||
<a href="<%= @person.url%>" rel="me" class="url"><%= @person.url%></a>
|
||||
</dd>
|
||||
</dl>
|
||||
<dl class="entity_note">
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
|
||||
xmlns:hm='http://host-meta.net/xrd/1.0'>
|
||||
<hm:Host><%= @user.terse_url %></hm:Host>
|
||||
<hm:Host><%= terse_url(root_url) %></hm:Host>
|
||||
<Link rel='lrdd'
|
||||
template='<%=@user.url%>webfinger?q={uri}'>
|
||||
template='<%= root_url %>webfinger?q={uri}'>
|
||||
<Title>Resource Descriptor</Title>
|
||||
</Link>
|
||||
</XRD>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Subject>acct:<%=@user.email%></Subject>
|
||||
<Alias>"<%=@user.url%>hcard"</Alias>
|
||||
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="<%=@user.url%>hcard"/>
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@user.url%>status_messages.atom"/>
|
||||
<Link rel="http://joindiaspora.com/seed_location" type = 'text/html' href="<%=@user.url%>"/>
|
||||
<Subject>acct:<%=@person.email%></Subject>
|
||||
<Alias>"<%= @person.url %>users/#{@user.id}/hcard"</Alias>
|
||||
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="<%=@person.url%>hcard"/>
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@person.url%>status_messages.atom"/>
|
||||
<Link rel="http://joindiaspora.com/seed_location" type = 'text/html' href="<%=@person.receive_url%>"/>
|
||||
</XRD>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
= form_for @request do |f|
|
||||
%h1
|
||||
Add a new friend to
|
||||
%i= @group.name
|
||||
|
||||
= form_for Request.new do |f|
|
||||
= f.error_messages
|
||||
|
||||
Enter a Diaspora URL, Diaspora username, or random email address:
|
||||
.field_with_submit
|
||||
= f.text_field :destination_url
|
||||
= f.submit
|
||||
= f.text_field :destination_url
|
||||
= f.hidden_field :group, :value => @group.id
|
||||
= f.submit
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,23 @@
|
|||
:javascript
|
||||
$(document).ready(function(){
|
||||
$(".group_selector").change( function() {
|
||||
var id = $(this).children(":selected").val();
|
||||
$(this).parent().children(".accept").html( "<a href=\"/requests/#{request.id}/?accept=true&group_id="+id+"\" data-method=\"delete\" rel=\"nofollow\" class=\"button\">Accept</a>");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
%li.message{:id => request.id}
|
||||
|
||||
%span.from
|
||||
= link_to "#{request.person.real_name}", '#'
|
||||
|
||||
%ul.request_buttons
|
||||
%li= link_to 'Accept', request_path(request, :accept => true), :method => :delete
|
||||
%li= link_to 'Ignore', request_path(request), :confirm => 'Are you sure?', :method => :delete
|
||||
%select{ :class => "group_selector", :style=>"display:inline;"}
|
||||
%option Add to group
|
||||
%option
|
||||
- for group in current_user.groups
|
||||
%option{:value => group.id}= group.name
|
||||
%li.accept= link_to 'Accept', request_path(request, :accept => true), :method => :delete, :class => "button"
|
||||
%li.ignore= link_to 'Ignore', request_path(request), :confirm => 'Are you sure?', :method => :delete, :class => "button"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,7 @@
|
|||
= link_to "⇧ home", root_path
|
||||
Requests
|
||||
|
||||
= render "requests/new_request", :request => @request
|
||||
|
||||
%h3= "currently #{@request_count} requests"
|
||||
|
||||
%ul#stream
|
||||
- for request in @remote_requests
|
||||
= render "request", :request => request
|
||||
|
|
|
|||
21
app/views/shared/_group_nav.haml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#group
|
||||
%ul
|
||||
- for group in @groups
|
||||
%li{:class => ("selected" if group.id.to_s == params[:id])}
|
||||
= link_to group.name, group
|
||||
|
||||
%li.new_group= link_to("NEW GROUP", "#add_group_pane", :id => "add_group_button")
|
||||
|
||||
.yo{ :style => "display:none;"}
|
||||
#add_group_pane
|
||||
= render "groups/new_group"
|
||||
|
||||
- if @group
|
||||
#friend_pictures
|
||||
- for friend in @group.people
|
||||
= person_image_link(friend)
|
||||
= link_to "+", "#add_request_pane", :id => 'add_request_button', :class => "add_new"
|
||||
|
||||
.yo{:style => 'display:none'}
|
||||
#add_request_pane
|
||||
= render "requests/new_request"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||
%li.message{:id => post.id, :class => ("mine" if current_user.owns?(post))}
|
||||
= person_image_link(post.person)
|
||||
= yield post_yield_tag(post)
|
||||
= = render type_partial(post), :post => post
|
||||
= = render type_partial(post), :post => post
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||
%li.message{:id => post.id, :class => ("mine" if current_user.owns?(post))}
|
||||
|
||||
= person_image_link(post.person)
|
||||
|
||||
%span.from
|
||||
= link_to post.person.real_name, post.person
|
||||
= auto_link post.message
|
||||
= auto_link sanitize post.message
|
||||
|
||||
%div.time
|
||||
= link_to(how_long_ago(post), object_path(post))
|
||||
|
|
@ -12,6 +12,6 @@
|
|||
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
|
||||
= render "comments/comments", :post => post
|
||||
|
||||
- if mine?(post)
|
||||
- if current_user.owns?(post)
|
||||
.destroy_link
|
||||
= link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true
|
||||
= link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "delete"
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@
|
|||
%p
|
||||
= @user.url
|
||||
%p
|
||||
%b Key Fingerprint
|
||||
%b Serialized Key
|
||||
%p
|
||||
= @user.key_fingerprint
|
||||
= @user.serialized_key
|
||||
|
|
|
|||
2
config/initializers/logging.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Rails.logger = Logger.new(
|
||||
Rails.root.join("log",Rails.env + ".log"),3,5*1024*1024)
|
||||
|
|
@ -1,41 +1,21 @@
|
|||
require 'em-websocket'
|
||||
require 'eventmachine'
|
||||
|
||||
module WebSocket
|
||||
require "lib/diaspora/websocket"
|
||||
EM.next_tick {
|
||||
initialize_channel
|
||||
Diaspora::WebSocket.initialize_channels
|
||||
|
||||
EventMachine::WebSocket.start(
|
||||
:host => "0.0.0.0",
|
||||
:port => APP_CONFIG[:socket_port],
|
||||
:debug =>APP_CONFIG[:debug]) do |ws|
|
||||
ws.onopen {
|
||||
@ws = ws
|
||||
sid = @channel.subscribe{ |msg| ws.send msg }#SocketsController.new.new_subscriber
|
||||
|
||||
sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws)
|
||||
|
||||
ws.onmessage { |msg| SocketsController.new.incoming(msg) }#@channel.push msg; puts msg}
|
||||
|
||||
ws.onclose { SocketsController.new.delete_subscriber(sid) }
|
||||
ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) }
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
def self.initialize_channel
|
||||
@channel = EM::Channel.new
|
||||
end
|
||||
|
||||
def self.push_to_clients(html)
|
||||
@channel.push(html)
|
||||
end
|
||||
|
||||
def self.unsubscribe(sid)
|
||||
@channel.unsubscribe(sid)
|
||||
end
|
||||
|
||||
|
||||
def self.subscribe
|
||||
@channel.subscribe{ |msg| ws.send msg }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,28 +8,29 @@ Diaspora::Application.routes.draw do |map|
|
|||
resources :requests
|
||||
resources :photos
|
||||
resources :albums
|
||||
resources :groups
|
||||
|
||||
match "/images/files/*path" => "gridfs#serve"
|
||||
|
||||
match 'warzombie', :to => "dev_utilities#warzombie"
|
||||
match 'zombiefriends', :to => "dev_utilities#zombiefriends"
|
||||
match 'warzombie', :to => "dev_utilities#warzombie"
|
||||
match 'zombiefriends', :to => "dev_utilities#zombiefriends"
|
||||
match 'zombiefriendaccept', :to => "dev_utilities#zombiefriendaccept"
|
||||
match 'set_backer_number', :to => "dev_utilities#set_backer_number"
|
||||
|
||||
#routes for devise, not really sure you will need to mess with this in the future, lets put default,
|
||||
#non mutable stuff in anohter file
|
||||
devise_for :users, :path_names => {:sign_up => "signup", :sign_in => "login", :sign_out => "logout"}
|
||||
match 'login', :to => 'devise/sessions#new', :as => "new_user_session"
|
||||
match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session"
|
||||
#match 'signup', :to => 'devise/registrations#new', :as => "new_user_registration"
|
||||
resources :users
|
||||
|
||||
devise_for :users, :path_names => {:sign_up => "get_to_the_choppa", :sign_in => "login", :sign_out => "logout"}
|
||||
match 'login', :to => 'devise/sessions#new', :as => "new_user_session"
|
||||
match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session"
|
||||
match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration"
|
||||
|
||||
#public routes
|
||||
match 'receive', :to => 'publics#receive'
|
||||
match '.well-known/host-meta',:to => 'publics#host_meta'
|
||||
match 'webfinger', :to => 'publics#webfinger'
|
||||
match 'hcard', :to => 'publics#hcard'
|
||||
|
||||
#
|
||||
match 'webfinger', :to => 'publics#webfinger'
|
||||
match 'users/:id/hcard', :to => 'publics#hcard'
|
||||
|
||||
match '.well-known/host-meta',:to => 'publics#host_meta'
|
||||
match 'receive/users/:id', :to => 'publics#receive'
|
||||
#root
|
||||
root :to => 'dashboards#index'
|
||||
root :to => 'groups#index'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,26 +8,21 @@
|
|||
|
||||
require 'config/environment'
|
||||
|
||||
def create(backer_number)
|
||||
def create
|
||||
config = YAML.load_file(File.dirname(__FILE__) + '/../../config/deploy_config.yml')
|
||||
backer_info = config['servers']['backer']
|
||||
|
||||
|
||||
backer_number = YAML.load_file(Rails.root.join('config','backer_number.yml'))[:seed_number].to_i
|
||||
# Create seed user
|
||||
username = backer_info[backer_number]['username'].gsub(/ /,'').downcase
|
||||
user = User.create( :email => "#{username}@#{username}.joindiaspora.com",
|
||||
:password => "#{username+backer_info[backer_number]['pin'].to_s}",
|
||||
:profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'] ),
|
||||
:url=> "#{username}.joindiaspora.com")
|
||||
|
||||
# Make connection with Diaspora Tom
|
||||
#Person.create( :email => "tom@joindiaspora.com", :url => "http://tom.joindiaspora.com/", :active => true, :profile => Profile.new(:first_name => "Alexander", :last_name => "Hamiltom"))
|
||||
# Make people
|
||||
|
||||
# (0..10).each { |n|
|
||||
#domain_name = backer_info[n][2].gsub(/ /,'').downcase
|
||||
#url = "http://#{domain_name}.joindiaspora.com/"
|
||||
#User.owner.send_friend_request_to(url)
|
||||
#}
|
||||
:person => Person.new(
|
||||
:email => "#{username}@#{username}.joindiaspora.com",
|
||||
:profile => Profile.new( :first_name => backer_info[backer_number]['given_name'], :last_name => backer_info[backer_number]['family_name'] ),
|
||||
:url=> "http://#{username}.joindiaspora.com/")
|
||||
)
|
||||
user.person.save
|
||||
user.group(:name => "Presidents")
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,5 +9,17 @@
|
|||
require 'config/environment'
|
||||
|
||||
# Create seed user
|
||||
user = User.create( :email => "robert@joindiaspora.com", :password => "evankorth", :profile => Profile.new( :first_name => "bobert", :last_name => "brin" ))
|
||||
user = User.create( :email => "robert@joindiaspora.com",
|
||||
:password => "evankorth",
|
||||
:person => Person.new(
|
||||
:email => "robert@joindiaspora.com",
|
||||
:url => "http://localhost:3000/",
|
||||
:profile => Profile.new(
|
||||
:first_name => "bobert",
|
||||
:last_name => "brin" )))
|
||||
|
||||
puts user.save
|
||||
puts user.person.save!
|
||||
puts user.save!
|
||||
puts user.person.inspect
|
||||
puts user.inspect
|
||||
|
|
|
|||
|
|
@ -1,13 +1,27 @@
|
|||
#This file should contain all the record creation needed to seed the database with its default values.
|
||||
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
|
||||
#
|
||||
# Examples:
|
||||
#
|
||||
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
|
||||
# Mayor.create(:name => 'Daley', :city => citie
|
||||
|
||||
require 'config/environment'
|
||||
|
||||
remote_url = "http://tom.joindiaspora.com/"
|
||||
# Create seed user
|
||||
user = User.create( :email => "tom@tom.joindiaspora.com", :password => "evankorth", :url => "http://tom.joindiaspora.com/", :profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
|
||||
user = User.create!( :email => "tom@tom.joindiaspora.com",
|
||||
:password => "evankorth",
|
||||
:person => Person.new(
|
||||
:email => "tom@tom.joindiaspora.com",
|
||||
:url => remote_url,
|
||||
:profile => Profile.new( :first_name => "Alexander", :last_name => "Hamiltom" ))
|
||||
)
|
||||
user.person.save!
|
||||
|
||||
user2 = User.create!( :email => "korth@tom.joindiaspora.com",
|
||||
:password => "evankorth",
|
||||
:person => Person.new( :email => "korth@tom.joindiaspora.com",
|
||||
:url => remote_url,
|
||||
:profile => Profile.new( :first_name => "Evan",
|
||||
:last_name => "Korth")))
|
||||
|
||||
user2.person.save!
|
||||
|
||||
# friending users
|
||||
group = user.group(:name => "other dudes")
|
||||
request = user.send_friend_request_to(user2.receive_url, group.id)
|
||||
reversed_request = user2.accept_friend_request( request.id, user2.group(:name => "presidents").id )
|
||||
user.receive reversed_request.to_diaspora_xml
|
||||
|
|
|
|||
|
|
@ -1,57 +1,33 @@
|
|||
module Diaspora
|
||||
module Parser
|
||||
def parse_owner_from_xml(xml)
|
||||
def self.owner_id_from_xml(xml)
|
||||
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
||||
email = doc.xpath("//person/email").text.to_s
|
||||
Person.first(:email => email)
|
||||
end
|
||||
|
||||
def parse_body_contents_from_xml(xml)
|
||||
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
||||
doc.xpath("/XML/posts/post")
|
||||
end
|
||||
|
||||
def parse_owner_id_from_xml(doc)
|
||||
id = doc.xpath("//person_id").text.to_s
|
||||
Person.first(:id => id)
|
||||
end
|
||||
|
||||
def parse_objects_from_xml(xml)
|
||||
objects = []
|
||||
body = parse_body_contents_from_xml(xml)
|
||||
body.children.each do |post|
|
||||
begin
|
||||
object = post.name.camelize.constantize.from_xml post.to_s
|
||||
if object.respond_to? :person
|
||||
object.person = parse_owner_from_xml post.to_s
|
||||
elsif object.is_a? Profile
|
||||
puts "got into parse objects from xml PROFILE"
|
||||
person = parse_owner_id_from_xml post
|
||||
person.profile = object
|
||||
person.save
|
||||
end
|
||||
objects << object
|
||||
rescue
|
||||
Rails.logger.info "Not a real type: #{object.to_s}"
|
||||
end
|
||||
end
|
||||
objects
|
||||
def self.get_or_create_person_object_from_xml(xml)
|
||||
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
||||
person_xml = doc.xpath("//request/person").to_s
|
||||
person_id = doc.xpath("//request/person/_id").text.to_s
|
||||
person = Person.first(:_id => person_id)
|
||||
person ? person : Person.from_xml( person_xml)
|
||||
end
|
||||
|
||||
def store_objects_from_xml(xml)
|
||||
objects = parse_objects_from_xml(xml)
|
||||
objects.each do |p|
|
||||
Rails.logger.info("Receiving object:\n#{p.inspect}")
|
||||
if p.is_a? Retraction
|
||||
p.perform
|
||||
elsif p.is_a? Request
|
||||
User.owner.receive_friend_request(p)
|
||||
elsif p.is_a? Profile
|
||||
p.save
|
||||
elsif p.respond_to?(:person) && !(p.person.nil?) && !(p.person.is_a? User)
|
||||
Rails.logger.info("Saving object with success: #{p.save}")
|
||||
def self.from_xml(xml)
|
||||
|
||||
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
||||
return unless body = doc.xpath("/XML/post").children.first
|
||||
|
||||
begin
|
||||
body.name.camelize.constantize.from_xml body.to_s
|
||||
rescue NameError => e
|
||||
if e.message.include? 'wrong constant name'
|
||||
Rails.logger.info "Not a real type: #{object.to_s}"
|
||||
end
|
||||
raise e
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ module Diaspora
|
|||
@@queue = MessageHandler.new
|
||||
|
||||
def notify_people
|
||||
if self.person_id == User.owner.id
|
||||
unless self.person.owner.nil?
|
||||
push_to(people_with_permissions)
|
||||
end
|
||||
end
|
||||
|
|
@ -18,37 +18,37 @@ module Diaspora
|
|||
|
||||
def push_to(recipients)
|
||||
unless recipients.empty?
|
||||
recipients.map!{|x| x = x.url + "receive/"}
|
||||
xml = Post.build_xml_for(self)
|
||||
Rails.logger.info("Adding xml for #{self} to message queue to #{recipients}")
|
||||
recipients.map!{|x| x = x.receive_url }
|
||||
xml = to_diaspora_xml
|
||||
Rails.logger.debug("Adding xml for #{self} to message queue to #{recipients}")
|
||||
@@queue.add_post_request( recipients, xml )
|
||||
end
|
||||
@@queue.process
|
||||
end
|
||||
|
||||
def push_to_url(url)
|
||||
hook_url = url + "receive/"
|
||||
xml = self.class.build_xml_for(self)
|
||||
Rails.logger.info("Adding xml for #{self} to message queue to #{url}")
|
||||
hook_url = url
|
||||
xml = to_diaspora_xml
|
||||
Rails.logger.debug("Adding xml for #{self} to message queue to #{url}")
|
||||
@@queue.add_post_request( hook_url, xml )
|
||||
@@queue.process
|
||||
end
|
||||
|
||||
def to_diaspora_xml
|
||||
"<post>#{self.to_xml.to_s}</post>"
|
||||
xml = "<XML>"
|
||||
xml += "<post>#{self.to_xml.to_s}</post>"
|
||||
xml += "</XML>"
|
||||
end
|
||||
|
||||
def people_with_permissions
|
||||
Person.friends.all
|
||||
end
|
||||
|
||||
def self.build_xml_for(posts)
|
||||
xml = "<XML>"
|
||||
xml += "\n <posts>"
|
||||
[*posts].each {|x| xml << x.to_diaspora_xml}
|
||||
xml += "</posts>"
|
||||
xml += "</XML>"
|
||||
|
||||
begin
|
||||
friends = self.person.owner.friends.all
|
||||
Rails.logger.error("Dan is wrong!") if friends.nil?
|
||||
friends ||= []
|
||||
rescue
|
||||
Rails.logger.fatal("Called people_with_permissions on a post from a remote user. We need to implement this shit.")
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
43
lib/diaspora/websocket.rb
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
module Diaspora
|
||||
module WebSocket
|
||||
def self.initialize_channels
|
||||
@channels = {}
|
||||
end
|
||||
|
||||
def self.push_to_user(uid, data)
|
||||
Rails.logger.debug "Websocketing to #{uid}"
|
||||
@channels[uid.to_s][0].push(data) if @channels[uid.to_s]
|
||||
end
|
||||
|
||||
def self.subscribe(uid, ws)
|
||||
Rails.logger.debug "Subscribing socket to #{User.first(:id => uid).email}"
|
||||
self.ensure_channel(uid)
|
||||
@channels[uid][0].subscribe{ |msg| ws.send msg }
|
||||
@channels[uid][1] += 1
|
||||
end
|
||||
|
||||
def self.ensure_channel(uid)
|
||||
@channels[uid] ||= [EM::Channel.new, 0 ]
|
||||
end
|
||||
|
||||
def self.unsubscribe(uid,sid)
|
||||
Rails.logger.debug "Unsubscribing socket #{sid} from #{uid}"
|
||||
@channels[uid][0].unsubscribe(sid) if @channels[uid]
|
||||
@channels[uid][1] -= 1
|
||||
if @channels[uid][1] <= 0
|
||||
@channels.delete(uid)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Socketable
|
||||
def socket_to_uid id
|
||||
SocketsController.new.outgoing(id, self)
|
||||
end
|
||||
|
||||
def unsocket_from_uid id
|
||||
SocketsController.new.outgoing(id, Retraction.for(self))
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -10,32 +10,26 @@
|
|||
if person.nil?
|
||||
Rails.logger.info("Verifying sig on #{signable_string} but no person is here")
|
||||
return false
|
||||
elsif person.key.nil?
|
||||
elsif person.encryption_key.nil?
|
||||
Rails.logger.info("Verifying sig on #{signable_string} but #{person.real_name} has no key")
|
||||
return false
|
||||
elsif signature.nil?
|
||||
Rails.logger.info("Verifying sig on #{signable_string} but #{person.real_name} did not sign")
|
||||
return false
|
||||
end
|
||||
Rails.logger.info("Verifying sig on #{signable_string} from person #{person.real_name}")
|
||||
validity = person.key.verify "SHA", Base64.decode64(signature), signable_string
|
||||
Rails.logger.info("Validity: #{validity}")
|
||||
Rails.logger.debug("Verifying sig on #{signable_string} from person #{person.real_name}")
|
||||
validity = person.encryption_key.verify "SHA", Base64.decode64(signature), signable_string
|
||||
Rails.logger.debug("Validity: #{validity}")
|
||||
validity
|
||||
end
|
||||
|
||||
protected
|
||||
def sign_if_mine
|
||||
if self.person == User.owner
|
||||
self.creator_signature = sign
|
||||
end
|
||||
end
|
||||
|
||||
def sign
|
||||
sign_with_key(User.owner.key)
|
||||
self.creator_signature = sign_with_key(person.encryption_key) unless person.owner_id.nil?
|
||||
end
|
||||
|
||||
def sign_with_key(key)
|
||||
Rails.logger.info("Signing #{signable_string}")
|
||||
Rails.logger.debug("Signing #{signable_string}")
|
||||
Base64.encode64(key.sign "SHA", signable_string)
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ namespace :db do
|
|||
require 'db/seeds/dev'
|
||||
end
|
||||
|
||||
task :backer, :num do |t, args|
|
||||
task :backer do
|
||||
puts "Seeding the database for #{Rails.env}..."
|
||||
require 'db/seeds/backer'
|
||||
create( Integer(args.num))
|
||||
create
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -27,6 +27,9 @@ namespace :db do
|
|||
# Specifiy what models to remove
|
||||
# No! Drop the fucking database.
|
||||
MongoMapper::connection.drop_database(MongoMapper::database.name)
|
||||
|
||||
puts 'Deleting tmp folder...'
|
||||
`rm -rf #{File.dirname(__FILE__)}/../../public/uploads/tmp`
|
||||
end
|
||||
|
||||
desc 'Purge and seed the current RAILS_ENV database using information from db/seeds.rb'
|
||||
|
|
|
|||
BIN
public/images/ajax-loader.gif
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 7.2 KiB |
BIN
public/javascripts/fancybox/blank.gif
Normal file
|
After Width: | Height: | Size: 43 B |
BIN
public/javascripts/fancybox/fancy_close.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
public/javascripts/fancybox/fancy_loading.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
public/javascripts/fancybox/fancy_nav_left.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
public/javascripts/fancybox/fancy_nav_right.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
public/javascripts/fancybox/fancy_shadow_e.png
Normal file
|
After Width: | Height: | Size: 107 B |
BIN
public/javascripts/fancybox/fancy_shadow_n.png
Normal file
|
After Width: | Height: | Size: 106 B |
BIN
public/javascripts/fancybox/fancy_shadow_ne.png
Normal file
|
After Width: | Height: | Size: 347 B |
BIN
public/javascripts/fancybox/fancy_shadow_nw.png
Normal file
|
After Width: | Height: | Size: 324 B |
BIN
public/javascripts/fancybox/fancy_shadow_s.png
Normal file
|
After Width: | Height: | Size: 111 B |
BIN
public/javascripts/fancybox/fancy_shadow_se.png
Normal file
|
After Width: | Height: | Size: 352 B |
BIN
public/javascripts/fancybox/fancy_shadow_sw.png
Normal file
|
After Width: | Height: | Size: 340 B |
BIN
public/javascripts/fancybox/fancy_shadow_w.png
Normal file
|
After Width: | Height: | Size: 103 B |
BIN
public/javascripts/fancybox/fancy_title_left.png
Normal file
|
After Width: | Height: | Size: 503 B |
BIN
public/javascripts/fancybox/fancy_title_main.png
Normal file
|
After Width: | Height: | Size: 96 B |
BIN
public/javascripts/fancybox/fancy_title_over.png
Normal file
|
After Width: | Height: | Size: 70 B |
BIN
public/javascripts/fancybox/fancy_title_right.png
Normal file
|
After Width: | Height: | Size: 506 B |
BIN
public/javascripts/fancybox/fancybox-x.png
Normal file
|
After Width: | Height: | Size: 203 B |
BIN
public/javascripts/fancybox/fancybox-y.png
Normal file
|
After Width: | Height: | Size: 176 B |
BIN
public/javascripts/fancybox/fancybox.png
Normal file
|
After Width: | Height: | Size: 15 KiB |