addedthe controllers and the views for the message and the conversation inbox, going to pull in some left nav styling

This commit is contained in:
zhitomirskiyi 2011-03-02 12:22:08 -08:00
parent f58c477673
commit 9d7611f8d8
11 changed files with 138 additions and 80 deletions

View file

@ -1,11 +1,13 @@
class ConversationsController < ApplicationController class ConversationsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
respond_to :html respond_to :html, :json
def index def index
@conversations = Conversation.joins(:conversation_visibilities).where( @conversations = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person.id}).all :conversation_visibilities => {:person_id => current_user.person.id}).all
@conversation = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first
end end
def create def create
@ -18,7 +20,7 @@ class ConversationsController < ApplicationController
@conversation = Conversation.create(params[:conversation]) @conversation = Conversation.create(params[:conversation])
respond_with @conversation redirect_to conversations_path(:conversation_id => @conversation.id)
end end
def show def show
@ -26,7 +28,7 @@ class ConversationsController < ApplicationController
:conversation_visibilities => {:person_id => current_user.person.id}).first :conversation_visibilities => {:person_id => current_user.person.id}).first
if @conversation if @conversation
respond_with @conversation render :layout => false
else else
redirect_to conversations_path redirect_to conversations_path
end end

View file

@ -14,13 +14,13 @@ class MessagesController < ApplicationController
:conversation_visibilities => {:person_id => current_user.person.id}).first :conversation_visibilities => {:person_id => current_user.person.id}).first
if cnv if cnv
message = Message.new(:conversation_id => cnv.id, :text => params[:text], :author => current_user.person) message = Message.new(:conversation_id => cnv.id, :text => params[:message][:text], :author => current_user.person)
if message.save if message.save
Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:text].length}") Rails.logger.info("event=create type=comment user=#{current_user.diaspora_handle} status=success message=#{message.id} chars=#{params[:message][:text].length}")
Postzord::Dispatch.new(current_user, message).post Postzord::Dispatch.new(current_user, message).post
respond_with cnv redirect_to conversations_path(:conversation_id => cnv.id)
else else
render :nothing => true, :status => 406 render :nothing => true, :status => 406
end end

View file

@ -0,0 +1,20 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.stream_element.conversation{:data=>{:guid=>conversation.id}}
- if conversation.author.owner_id == current_user.id
.right.hidden.controls
/= link_to image_tag('deletelabel.png'), status_message_path(conversation), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete", :title => t('delete')
%strong
= person_link(conversation.author)
.subject
= conversation.subject
.message
= "#{conversation.messages.first.text[0..20]}..."
.info
/%span.timeago= link_to(how_long_ago(conversation), status_message_path(conversation))

View file

@ -0,0 +1,22 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.conversation_participants
.right
= link_to t('delete'), conversation_conversation_visibility_path(conversation), :method => 'delete', :confirm => t('are_you_sure')
- for participant in conversation.participants
= person_image_link(participant)
.stream
= render :partial => 'messages/message', :collection => conversation.messages
.stream_element.new_message
= owner_image_tag
.content
= form_for [conversation, Message.new] do |message|
= message.text_area :text, :rows => 5
.right
= message.submit 'Reply'
= link_to 'Cancel', '#'

View file

@ -2,29 +2,36 @@
-# licensed under the Affero General Public License version 3 or later. See -# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file. -# the COPYRIGHT file.
:javascript
$(document).ready(function(){
$('.conversation', '.stream').click(function(){
var conversationGuid = $(this).attr('data-guid');
$.get("conversations/"+conversationGuid, function(data){
$('#conversation_show').html(data);
});
});
});
.span-12.last .span-24.last{:style => 'position:relative;'}
%h2
.right .right
= link_to 'new message', new_conversation_path, :class => 'button' = link_to 'New Message', new_conversation_path, :class => 'button'
Inbox = link_to 'Inbox', conversations_path, :class => 'button'
= link_to 'Sent', conversations_path, :class => 'button'
%br
%br
%br
.span-6.append-1
- if @conversations.count > 0 - if @conversations.count > 0
.stream .stream
- for conversation in @conversations = render :partial => 'conversations/conversation', :collection => @conversations
.stream_element
.right
= link_to image_tag('deletelabel.png'), conversation_conversation_visibility_path(conversation), :method => 'delete', :confirm => t('are_you_sure')
.from
= conversation.messages.last.author.name
%p
= link_to conversation.subject, conversation
%p
= link_to conversation.messages.last, conversation
- else - else
%i %i
You have no messages You have no messages
#conversation_show.span-17.last
- if @conversation
= render 'conversations/show', :conversation => @conversation
- else
%i
no conversation selected

View file

@ -9,16 +9,15 @@
= form_for Conversation.new do |conversation| = form_for Conversation.new do |conversation|
%h4 %h4
to to
= text_field_tag "private_message[contact_ids]" = text_field_tag "conversation[contact_ids]"
%h4 %h4
subject subject
= conversation.text_field :subject = conversation.text_field :subject
= fields_for :message do |message|
%h4 %h4
message message
= message.text_area :text, :rows => 5 = text_area_tag "conversation[text]", '', :rows => 5
= conversation.submit :send = conversation.submit :send
= link_to 'cancel', conversations_path = link_to 'cancel', conversations_path

View file

@ -2,31 +2,4 @@
-# licensed under the Affero General Public License version 3 or later. See -# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file. -# the COPYRIGHT file.
= link_to 'back', conversations_path = render 'show', :conversation => @conversation
%br
%br
%br
%br
- for participant in @conversation.participants
= participant.name
- for message in @conversation.messages
%h4
from
= message.author.name
%br
%br
%h4
message
= message.text
%hr
= link_to t('delete'), conversation_conversation_visibility_path(@conversation), :method => 'delete', :confirm => t('are_you_sure')

View file

@ -0,0 +1,17 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
.stream_element{:data=>{:guid=>message.id}}
= person_image_link(message.author, :size => :thumb_small)
.right
%span.timeago= link_to(how_long_ago(message), status_message_path(message))
.content
%strong
= person_link(message.author)
.message
= message.text

View file

@ -38,9 +38,7 @@ namespace :db do
puts "Purging the database for #{Rails.env}..." puts "Purging the database for #{Rails.env}..."
# Specifiy what models to remove Rake::Task['db:rebuild'].invoke
# No! Drop the fucking database.
MongoMapper::connection.drop_database(MongoMapper::database.name)
puts 'Deleting tmp folder...' puts 'Deleting tmp folder...'
`rm -rf #{File.dirname(__FILE__)}/../../public/uploads/*` `rm -rf #{File.dirname(__FILE__)}/../../public/uploads/*`
@ -51,17 +49,10 @@ namespace :db do
puts "Resetting the database for #{Rails.env}".upcase puts "Resetting the database for #{Rails.env}".upcase
Rake::Task['db:purge'].invoke Rake::Task['db:purge'].invoke
Rake::Task['db:seed:dev'].invoke Rake::Task['db:seed'].invoke
puts "Success!" puts "Success!"
end end
task :reset_dev do
puts "making a new base user"
Rake::Task['db:purge'].invoke
Rake::Task['db:seed:dev'].invoke
puts "you did it!"
end
desc "Purge database and then add the first user" desc "Purge database and then add the first user"
task :first_user, :username, :password, :email do |t, args| task :first_user, :username, :password, :email do |t, args|
Rake::Task['db:purge'].invoke Rake::Task['db:purge'].invoke

View file

@ -2481,3 +2481,30 @@ ul.show_comments
.public_icon, .service_icon .public_icon, .service_icon
:cursor pointer :cursor pointer
.stream_element
.subject
:font
:weight bold
.conversation_participants
:background
:color #eee
:border
:bottom 1px solid #999
:padding 1em
.stream_element.new_message
:border
:top 1px solid #999
:bottom none
&:hover
:border
:bottom none
textarea
:margin 0
:bottom 0.5em
:width 100%
.right
:right -11px

View file

@ -21,19 +21,18 @@ describe MessagesController do
before do before do
@create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id], @create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id],
:subject => "cool stuff", :text => "stuff"} :subject => "cool stuff", :text => "stuff"}
end end
context "on my own post" do context "on my own post" do
before do before do
@cnv = Conversation.create(@create_hash) @cnv = Conversation.create(@create_hash)
@message_hash = {:conversation_id => @cnv.id, :text => "here is something else"} @message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}}
end end
it 'responds to format js' do it 'redirects to conversation' do
lambda{ lambda{
post :create, @message_hash post :create, @message_hash
}.should change(Message, :count).by(1) }.should change(Message, :count).by(1)
response.code.should == '201' response.code.should == '302'
response.should redirect_to(@cnv) response.should redirect_to(conversations_path(:conversation_id => @cnv))
end end
end end
@ -41,17 +40,18 @@ describe MessagesController do
before do before do
@create_hash[:author] = @user2.person @create_hash[:author] = @user2.person
@cnv = Conversation.create(@create_hash) @cnv = Conversation.create(@create_hash)
@message_hash = {:conversation_id => @cnv.id, :text => "here is something else"} @message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}}
end end
it 'comments' do it 'comments' do
post :create, @message_hash post :create, @message_hash
response.code.should == '201' response.code.should == '302'
response.should redirect_to(conversations_path(:conversation_id => @cnv))
end end
it "doesn't overwrite author_id" do it "doesn't overwrite author_id" do
new_user = Factory.create(:user) new_user = Factory.create(:user)
@message_hash[:author_id] = new_user.person.id.to_s @message_hash[:author_id] = new_user.person.id.to_s
post :create, @message_hash post :create, @message_hash
Message.find_by_text(@message_hash[:text]).author_id.should == @user1.person.id Message.find_by_text(@message_hash[:message][:text]).author_id.should == @user1.person.id
end end
it "doesn't overwrite id" do it "doesn't overwrite id" do
old_message = Message.create(:text => "hello", :author_id => @user1.person.id, :conversation_id => @cnv.id) old_message = Message.create(:text => "hello", :author_id => @user1.person.id, :conversation_id => @cnv.id)
@ -63,11 +63,11 @@ describe MessagesController do
context 'on a post from a stranger' do context 'on a post from a stranger' do
before do before do
@create_hash[:author] = eve.person @create_hash[:author] = eve.person
@create_hash[:participant_ids] = [eve.person.id, bob.person.id]
@cnv = Conversation.create(@create_hash) @cnv = Conversation.create(@create_hash)
@message_hash = {:conversation_id => @cnv.id, :text => "here is something else"} @message_hash = {:conversation_id => @cnv.id, :message => {:text => "here is something else"}}
end end
it 'posts no comment' do it 'posts no comment' do
Message.should_not_receive(:new)
post :create, @message_hash post :create, @message_hash
response.code.should == '406' response.code.should == '406'
end end