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:
parent
f58c477673
commit
9d7611f8d8
11 changed files with 138 additions and 80 deletions
|
|
@ -1,11 +1,13 @@
|
|||
class ConversationsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
|
||||
respond_to :html
|
||||
respond_to :html, :json
|
||||
|
||||
def index
|
||||
@conversations = Conversation.joins(:conversation_visibilities).where(
|
||||
: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
|
||||
|
||||
def create
|
||||
|
|
@ -18,7 +20,7 @@ class ConversationsController < ApplicationController
|
|||
|
||||
@conversation = Conversation.create(params[:conversation])
|
||||
|
||||
respond_with @conversation
|
||||
redirect_to conversations_path(:conversation_id => @conversation.id)
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
@ -26,7 +28,7 @@ class ConversationsController < ApplicationController
|
|||
:conversation_visibilities => {:person_id => current_user.person.id}).first
|
||||
|
||||
if @conversation
|
||||
respond_with @conversation
|
||||
render :layout => false
|
||||
else
|
||||
redirect_to conversations_path
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,13 +14,13 @@ class MessagesController < ApplicationController
|
|||
:conversation_visibilities => {:person_id => current_user.person.id}).first
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
respond_with cnv
|
||||
redirect_to conversations_path(:conversation_id => cnv.id)
|
||||
else
|
||||
render :nothing => true, :status => 406
|
||||
end
|
||||
|
|
|
|||
20
app/views/conversations/_conversation.haml
Normal file
20
app/views/conversations/_conversation.haml
Normal 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))
|
||||
|
||||
22
app/views/conversations/_show.haml
Normal file
22
app/views/conversations/_show.haml
Normal 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', '#'
|
||||
|
|
@ -2,29 +2,36 @@
|
|||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# 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
|
||||
|
||||
%h2
|
||||
.right
|
||||
= link_to 'new message', new_conversation_path, :class => 'button'
|
||||
Inbox
|
||||
|
||||
.span-24.last{:style => 'position:relative;'}
|
||||
.right
|
||||
= link_to 'New Message', new_conversation_path, :class => 'button'
|
||||
= 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
|
||||
.stream
|
||||
- for conversation in @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
|
||||
|
||||
= render :partial => 'conversations/conversation', :collection => @conversations
|
||||
- else
|
||||
%i
|
||||
You have no messages
|
||||
|
||||
#conversation_show.span-17.last
|
||||
- if @conversation
|
||||
= render 'conversations/show', :conversation => @conversation
|
||||
- else
|
||||
%i
|
||||
no conversation selected
|
||||
|
|
|
|||
|
|
@ -9,16 +9,15 @@
|
|||
= form_for Conversation.new do |conversation|
|
||||
%h4
|
||||
to
|
||||
= text_field_tag "private_message[contact_ids]"
|
||||
= text_field_tag "conversation[contact_ids]"
|
||||
|
||||
%h4
|
||||
subject
|
||||
= conversation.text_field :subject
|
||||
|
||||
= fields_for :message do |message|
|
||||
%h4
|
||||
message
|
||||
= message.text_area :text, :rows => 5
|
||||
%h4
|
||||
message
|
||||
= text_area_tag "conversation[text]", '', :rows => 5
|
||||
|
||||
= conversation.submit :send
|
||||
= link_to 'cancel', conversations_path
|
||||
|
|
|
|||
|
|
@ -2,31 +2,4 @@
|
|||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
= link_to 'back', conversations_path
|
||||
|
||||
%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')
|
||||
|
||||
|
||||
= render 'show', :conversation => @conversation
|
||||
|
|
|
|||
17
app/views/messages/_message.haml
Normal file
17
app/views/messages/_message.haml
Normal 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
|
||||
|
||||
|
|
@ -38,9 +38,7 @@ namespace :db do
|
|||
|
||||
puts "Purging the database for #{Rails.env}..."
|
||||
|
||||
# Specifiy what models to remove
|
||||
# No! Drop the fucking database.
|
||||
MongoMapper::connection.drop_database(MongoMapper::database.name)
|
||||
Rake::Task['db:rebuild'].invoke
|
||||
|
||||
puts 'Deleting tmp folder...'
|
||||
`rm -rf #{File.dirname(__FILE__)}/../../public/uploads/*`
|
||||
|
|
@ -51,17 +49,10 @@ namespace :db do
|
|||
|
||||
puts "Resetting the database for #{Rails.env}".upcase
|
||||
Rake::Task['db:purge'].invoke
|
||||
Rake::Task['db:seed:dev'].invoke
|
||||
Rake::Task['db:seed'].invoke
|
||||
puts "Success!"
|
||||
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"
|
||||
task :first_user, :username, :password, :email do |t, args|
|
||||
Rake::Task['db:purge'].invoke
|
||||
|
|
|
|||
|
|
@ -2480,4 +2480,31 @@ ul.show_comments
|
|||
:position static
|
||||
|
||||
.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
|
||||
|
||||
|
|
|
|||
|
|
@ -21,19 +21,18 @@ describe MessagesController do
|
|||
before do
|
||||
@create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id],
|
||||
:subject => "cool stuff", :text => "stuff"}
|
||||
|
||||
end
|
||||
context "on my own post" do
|
||||
before do
|
||||
@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
|
||||
it 'responds to format js' do
|
||||
it 'redirects to conversation' do
|
||||
lambda{
|
||||
post :create, @message_hash
|
||||
}.should change(Message, :count).by(1)
|
||||
response.code.should == '201'
|
||||
response.should redirect_to(@cnv)
|
||||
response.code.should == '302'
|
||||
response.should redirect_to(conversations_path(:conversation_id => @cnv))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -41,17 +40,18 @@ describe MessagesController do
|
|||
before do
|
||||
@create_hash[:author] = @user2.person
|
||||
@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
|
||||
it 'comments' do
|
||||
post :create, @message_hash
|
||||
response.code.should == '201'
|
||||
response.code.should == '302'
|
||||
response.should redirect_to(conversations_path(:conversation_id => @cnv))
|
||||
end
|
||||
it "doesn't overwrite author_id" do
|
||||
new_user = Factory.create(:user)
|
||||
@message_hash[:author_id] = new_user.person.id.to_s
|
||||
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
|
||||
it "doesn't overwrite id" do
|
||||
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
|
||||
before do
|
||||
@create_hash[:author] = eve.person
|
||||
@create_hash[:participant_ids] = [eve.person.id, bob.person.id]
|
||||
@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
|
||||
it 'posts no comment' do
|
||||
Message.should_not_receive(:new)
|
||||
post :create, @message_hash
|
||||
response.code.should == '406'
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue