Skip to content

Commit

Permalink
Separated private messages and business proposals. Closes fredwu#2.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredwu committed Jul 17, 2011
1 parent 5c51dfe commit b8a1fdf
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 15 deletions.
9 changes: 8 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def show
end

def message_inboxes
@messages = case params[:type].try(:to_sym)
message_type = params[:type].try(:to_sym)

@messages = case message_type
when :inbox_messages then current_user.inbox_messages
when :sent_messages then current_user.sent_messages
when :archived_messages then current_user.archived_messages
Expand All @@ -30,6 +32,11 @@ def message_inboxes
when :archived_proposals then current_user.archived_proposals
else redirect_to my_message_inbox_path(:inbox_messages)
end

case message_type
when /_messages/ then render 'message_inboxes'
when /_proposals/ then render 'proposal_inboxes'
end
end

def add_micro_post
Expand Down
12 changes: 8 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def archived_proposals
incoming_messages.with_proposal.archived
end

def has_new_messages?
inbox_messages.unread.any?
end

def has_new_proposals?
inbox_proposals.unread.any?
end

def is_admin?
!!is_admin
end
Expand All @@ -103,10 +111,6 @@ def avatar(size = 80)
"http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email)}?s=#{size}"
end

def has_new_messages?
incoming_messages.unread.any?
end

def send_private_message(target_user, content, extras = {})
messages.create!({
:content => content,
Expand Down
7 changes: 6 additions & 1 deletion app/views/layouts/userbars/_topnav.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ h3
| ! (
= link_to t('label.edit'), edit_registration_path(current_user)
' ) |
- if current_user.has_new_proposals?
= link_to "#{pluralize(current_user.inbox_proposals.unread.count, t('label.new_proposal'))}!", my_message_inbox_path(:inbox_proposals), :class => 'new'
- else
= link_to t('label.proposals_inbox'), my_message_inbox_path(:inbox_proposals)
' |
- if current_user.has_new_messages?
= link_to "#{pluralize(current_user.inbox_messages.unread.count, t('label.new_message'))}!", my_message_inbox_path(:inbox_messages), :class => 'new'
- else
= link_to "#{t('label.messages')} (#{current_user.inbox_messages.count})", my_message_inbox_path(:inbox_messages)
= link_to t('label.messages_inbox'), my_message_inbox_path(:inbox_messages)
' |
= link_to t('label.sign_out'), destroy_user_session_path
5 changes: 4 additions & 1 deletion app/views/messages/show_private_message.html.slim
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.grid_3
= render 'users/message_inboxes'
- if @topic.is_with_proposal?
= render 'users/proposal_inboxes'
- else
= render 'users/message_inboxes'
.grid_9
- if @topic.is_with_proposal?
h1= t('label.business_proposal')
Expand Down
7 changes: 0 additions & 7 deletions app/views/users/_message_inboxes.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,3 @@ ul
li= link_to_current t('label.inbox_messages'), my_message_inbox_path(:inbox_messages)
li= link_to_current t('label.sent_messages') , my_message_inbox_path(:sent_messages)
li= link_to_current t('label.archived_messages') , my_message_inbox_path(:archived_messages)

hr
h3= t('label.startup_proposals')
ul
li= link_to_current t('label.inbox_proposals') , my_message_inbox_path(:inbox_proposals)
li= link_to_current t('label.sent_proposals') , my_message_inbox_path(:sent_proposals)
li= link_to_current t('label.archived_proposals') , my_message_inbox_path(:archived_proposals)
8 changes: 8 additions & 0 deletions app/views/users/_proposal_inboxes.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= render 'users/mini_profile', :user => current_user, :meta => {}

hr
h3= t('label.startup_proposals')
ul
li= link_to_current t('label.inbox_proposals') , my_message_inbox_path(:inbox_proposals)
li= link_to_current t('label.sent_proposals') , my_message_inbox_path(:sent_proposals)
li= link_to_current t('label.archived_proposals') , my_message_inbox_path(:archived_proposals)
2 changes: 1 addition & 1 deletion app/views/users/message_inboxes.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.grid_3
= render 'message_inboxes'
= render 'users/message_inboxes'
.grid_9
= render 'messages/index', :collection => @messages, :meta => { :linkable => true, :new_message? => true }
4 changes: 4 additions & 0 deletions app/views/users/proposal_inboxes.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.grid_3
= render 'users/proposal_inboxes'
.grid_9
= render 'messages/index', :collection => @messages, :meta => { :linkable => true }
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ en:
five_year_market: Market in Five Years
messages: Messages
new_message: New message
new_proposal: New Proposal
private_messages: Private messages
inbox: Inbox
inbox_messages: Inbox messages
Expand All @@ -135,6 +136,8 @@ en:
sent_proposals: Sent proposals
archived_proposals: Archived proposals
recipients: Recipients
messages_inbox: Messages inbox
proposals_inbox: Proposals inbox
message:
proposal_saved: The proposal has been saved!
proposal_submitted: The proposal has been submitted to the investors!
Expand Down
1 change: 1 addition & 0 deletions spec/models/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
subject.send_private_message(user, 'hey there!')

user.has_new_messages?.should == true
user.has_new_proposals?.should == false
end

context "private messages" do
Expand Down
1 change: 1 addition & 0 deletions spec/models/proposal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
startup.proposals.draft.count.should == 0
startup.proposals.submitted.count.should == 1
startup.founder.sent_proposals.count.should == 1
investor1.has_new_proposals?.should == true
investor1.proposals.count.should == 1
investor1.inbox_proposals.count.should == 1
startup.proposals.first.proposal_stage_identifier.should == 'submitted'
Expand Down

0 comments on commit b8a1fdf

Please sign in to comment.