DG IZ; friend requests pass through the webhook, need to refactor the parser because now the XML does not make sense, no big deal. P.S. WTF is send_to_seed in message_handler
This commit is contained in:
parent
027d953cf4
commit
0587688d18
14 changed files with 161 additions and 15 deletions
39
app/controllers/friend_requests_controller.rb
Normal file
39
app/controllers/friend_requests_controller.rb
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
class FriendRequestsController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
|
def index
|
||||||
|
@friend_requests = FriendRequest.paginate :page => params[:page], :order => 'created_at DESC'
|
||||||
|
@friend_request = FriendRequest.new
|
||||||
|
@person = Person.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@friend_request = FriendRequest.where(:id => params[:id]).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@friend_request = FriendRequest.where(:id => params[:id]).first
|
||||||
|
@friend_request.destroy
|
||||||
|
flash[:notice] = "Successfully destroyed friend request."
|
||||||
|
redirect_to friend_requests_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@friend_request = FriendRequest.new
|
||||||
|
@receiver = Person.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
|
||||||
|
puts params.inspect
|
||||||
|
@friend_request = FriendRequest.new(params[:friend_request])
|
||||||
|
|
||||||
|
|
||||||
|
if @friend_request.save
|
||||||
|
flash[:notice] = "Successfully created friend request."
|
||||||
|
redirect_to @friend_request
|
||||||
|
else
|
||||||
|
render :action => 'new'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
class FriendRequest
|
class FriendRequest
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
include ROXML
|
include ROXML
|
||||||
|
include Diaspora::Webhooks
|
||||||
|
|
||||||
|
xml_name :friend_request
|
||||||
xml_accessor :sender, :as => Person
|
xml_accessor :sender, :as => Person
|
||||||
xml_accessor :recipient, :as => Person
|
xml_accessor :recipient, :as => Person
|
||||||
|
|
||||||
|
|
@ -9,6 +11,7 @@ class FriendRequest
|
||||||
key :recipient, Person
|
key :recipient, Person
|
||||||
|
|
||||||
validates_presence_of :sender, :recipient
|
validates_presence_of :sender, :recipient
|
||||||
|
after_create :send_off
|
||||||
|
|
||||||
def accept
|
def accept
|
||||||
f = Friend.new
|
f = Friend.new
|
||||||
|
|
@ -21,5 +24,9 @@ class FriendRequest
|
||||||
def reject
|
def reject
|
||||||
self.destroy
|
self.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_off
|
||||||
|
push_to [self.recipient]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
13
app/views/friend_requests/_form.html.haml
Normal file
13
app/views/friend_requests/_form.html.haml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
= form_for @friend_request do |f|
|
||||||
|
= f.error_messages
|
||||||
|
|
||||||
|
|
||||||
|
= f.fields_for :receiver do |r|
|
||||||
|
%p
|
||||||
|
= r.label :email
|
||||||
|
= r.text_field :email
|
||||||
|
%p
|
||||||
|
= r.label :url
|
||||||
|
= r.text_field :url
|
||||||
|
%p
|
||||||
|
= f.submit
|
||||||
18
app/views/friend_requests/_friend_request.html.haml
Normal file
18
app/views/friend_requests/_friend_request.html.haml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
|
||||||
|
%span.from
|
||||||
|
= link_to_person post.person
|
||||||
|
%b shared a link
|
||||||
|
%br
|
||||||
|
= post.title
|
||||||
|
|
||||||
|
%a{:href => "#{post.link}"}
|
||||||
|
= post.link
|
||||||
|
%div.time
|
||||||
|
= link_to(how_long_ago(post), bookmark_path(post))
|
||||||
|
\--
|
||||||
|
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
|
||||||
|
= render "comments/comments", :post => post
|
||||||
|
|
||||||
|
- if mine?(post)
|
||||||
|
.destroy_link
|
||||||
|
= link_to 'Delete', bookmark_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true
|
||||||
12
app/views/friend_requests/_new_friend_request.haml
Normal file
12
app/views/friend_requests/_new_friend_request.haml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
= form_for @friend_request, :remote => true do |f|
|
||||||
|
= f.error_messages
|
||||||
|
|
||||||
|
= f.fields_for :receiver do |r|
|
||||||
|
%p
|
||||||
|
= r.label :email
|
||||||
|
= r.text_field :email
|
||||||
|
%p
|
||||||
|
= r.label :url
|
||||||
|
= r.text_field :url
|
||||||
|
%p
|
||||||
|
= f.submit
|
||||||
8
app/views/friend_requests/edit.html.haml
Normal file
8
app/views/friend_requests/edit.html.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
- title "Edit Bookmark"
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to "Show", bookmark_path(@bookmark)
|
||||||
|
|
|
||||||
|
= link_to "View All", bookmarks_path
|
||||||
7
app/views/friend_requests/index.html.haml
Normal file
7
app/views/friend_requests/index.html.haml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
%h1 friend requests
|
||||||
|
= render "friend_requests/new_friend_request", :friend_request => @friend_request
|
||||||
|
%ul#stream
|
||||||
|
- for friend_request in @friend_requests
|
||||||
|
= render "friend_request", :post => friend_request
|
||||||
|
#pagination
|
||||||
|
= will_paginate @friend_requests
|
||||||
5
app/views/friend_requests/new.html.haml
Normal file
5
app/views/friend_requests/new.html.haml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
- title "New Friend Request"
|
||||||
|
|
||||||
|
= render 'form'
|
||||||
|
|
||||||
|
%p= link_to "Back to List", friend_requests_path
|
||||||
18
app/views/friend_requests/show.html.haml
Normal file
18
app/views/friend_requests/show.html.haml
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
- title "Bookmark"
|
||||||
|
|
||||||
|
%p
|
||||||
|
%strong Title:
|
||||||
|
= @bookmark.title
|
||||||
|
%p
|
||||||
|
%strong Link:
|
||||||
|
= link_to @bookmark.link
|
||||||
|
%p
|
||||||
|
%strong Owner:
|
||||||
|
= @bookmark.person.real_name
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to "Edit", edit_bookmark_path(@bookmark)
|
||||||
|
|
|
||||||
|
= link_to "Destroy", @bookmark, :confirm => 'Are you sure?', :method => :delete
|
||||||
|
|
|
||||||
|
= link_to "View All", bookmarks_path
|
||||||
|
|
@ -4,6 +4,8 @@ Diaspora::Application.routes.draw do |map|
|
||||||
resources :friends
|
resources :friends
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
resources :comments
|
resources :comments
|
||||||
|
resources :friend_requests
|
||||||
|
|
||||||
match 'warzombie', :to => "dashboard#warzombie"
|
match 'warzombie', :to => "dashboard#warzombie"
|
||||||
|
|
||||||
#routes for devise, not really sure you will need to mess with this in the future, lets put default,
|
#routes for devise, not really sure you will need to mess with this in the future, lets put default,
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ module Diaspora
|
||||||
if p.is_a? Retraction
|
if p.is_a? Retraction
|
||||||
|
|
||||||
p.perform
|
p.perform
|
||||||
|
elsif p.is_a? FriendRequest
|
||||||
|
p.save
|
||||||
#This line checks if the sender was in the database, among other things?
|
#This line checks if the sender was in the database, among other things?
|
||||||
elsif p.respond_to?(:person) && !(p.person.nil?) #WTF
|
elsif p.respond_to?(:person) && !(p.person.nil?) #WTF
|
||||||
p.save
|
p.save
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,7 @@ class MessageHandler
|
||||||
}
|
}
|
||||||
} unless @queue.size == 0
|
} unless @queue.size == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def send_to_seed(message, http_response)
|
def send_to_seed(message, http_response)
|
||||||
#DO SOMETHING!
|
#DO SOMETHING!
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,17 @@ describe "parser in application helper" do
|
||||||
store_objects_from_xml( request )
|
store_objects_from_xml( request )
|
||||||
StatusMessage.count.should == 0
|
StatusMessage.count.should == 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should marshal friend requests' do
|
||||||
|
sender = Factory.build(:user, :email => "bob@aol.com", :url => "http://google.com/")
|
||||||
|
recipient = Factory.build(:person, :email => "robert@grimm.com", :url => "http://localhost:3000/")
|
||||||
|
friend_request = FriendRequest.new(:sender => sender, :recipient => recipient)
|
||||||
|
xml_request = Post.build_xml_for([friend_request])
|
||||||
|
|
||||||
|
FriendRequest.count.should be 0
|
||||||
|
store_objects_from_xml( xml_request )
|
||||||
|
FriendRequest.count.should be 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,28 +3,28 @@ require 'spec_helper'
|
||||||
describe FriendRequest do
|
describe FriendRequest do
|
||||||
before do
|
before do
|
||||||
sender = Factory.build(:user, :email => "bob@aol.com", :url => "http://google.com/")
|
sender = Factory.build(:user, :email => "bob@aol.com", :url => "http://google.com/")
|
||||||
recipient = Factory.build(:person, :email => "robert@grimm.com", :url => "http://robert.com")
|
recipient = Factory.build(:person, :email => "robert@grimm.com", :url => "http://localhost:3000/")
|
||||||
@r = FriendRequest.create(:sender => sender, :recipient => recipient)
|
@request = FriendRequest.create(:sender => sender, :recipient => recipient)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should have sender and recipient credentials after serialization' do
|
it 'should have sender and recipient credentials after serialization' do
|
||||||
xml = @r.to_xml.to_s
|
xml = @request.to_xml.to_s
|
||||||
xml.include?(@r.sender.url).should be true
|
xml.include?(@request.sender.url).should be true
|
||||||
xml.include?(@r.sender.email).should be true
|
xml.include?(@request.sender.email).should be true
|
||||||
xml.include?(@r.recipient.url).should be true
|
xml.include?(@request.recipient.url).should be true
|
||||||
xml.include?(@r.recipient.email).should be true
|
xml.include?(@request.recipient.email).should be true
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "acceptance" do
|
describe "acceptance" do
|
||||||
it 'should create a friend' do
|
it 'should create a friend' do
|
||||||
Friend.count.should be 0
|
Friend.count.should be 0
|
||||||
@r.accept
|
@request.accept
|
||||||
Friend.count.should be 1
|
Friend.count.should be 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should remove the request' do
|
it 'should remove the request' do
|
||||||
FriendRequest.count.should be 1
|
FriendRequest.count.should be 1
|
||||||
@r.accept
|
@request.accept
|
||||||
FriendRequest.count.should be 0
|
FriendRequest.count.should be 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -32,15 +32,21 @@ describe FriendRequest do
|
||||||
describe "rejection" do
|
describe "rejection" do
|
||||||
it 'should not create a friend' do
|
it 'should not create a friend' do
|
||||||
Friend.count.should be 0
|
Friend.count.should be 0
|
||||||
@r.reject
|
@request.reject
|
||||||
Friend.count.should be 0
|
Friend.count.should be 0
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should remove the request' do
|
it 'should remove the request' do
|
||||||
FriendRequest.count.should be 1
|
FriendRequest.count.should be 1
|
||||||
@r.reject
|
@request.reject
|
||||||
FriendRequest.count.should be 0
|
FriendRequest.count.should be 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should dispatch upon creation' do
|
||||||
|
FriendRequest.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||||
|
sender = Factory.build(:user, :email => "bob@aol.com", :url => "http://google.com/")
|
||||||
|
recipient = Factory.build(:person, :email => "robert@grimm.com", :url => "http://localhost:3000/")
|
||||||
|
FriendRequest.create(:sender => sender, :recipient => recipient)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue