Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Individual chat conversations now get their own "num unread" indicators.

  • Loading branch information...
commit da7046caaa5db0243be9a8dbfc42a62bdf236879 1 parent 6be3191
@Pistos authored
View
2  app/controllers/chat_messages_controller.rb
@@ -71,7 +71,7 @@ def new_conversation
partner = Person.find( params['person_id'].to_i )
if partner
render :json => {
- 'partner' => render_to_string( :partial => 'chat_messages/partner.html.erb', :locals => { :partner => partner, :first => true } ),
+ 'partner' => render_to_string( :partial => 'chat_messages/partner.html.erb', :locals => { :partner => partner, :num_unread => 0, :first => true } ),
'conversation' => render_to_string(
:partial => 'chat_messages/conversation.html.erb',
:locals => {
View
7 app/views/chat_messages/_partner.html.erb
@@ -1 +1,6 @@
-<span class="partner <%= 'active' if first %>" data-person_id="<%=partner.id%>" data-person_name="<%=partner.name%>"><%= person_image_tag(partner) %></span>
+<span class="partner <%= 'active' if first %>" data-person_id="<%=partner.id%>" data-person_name="<%=partner.name%>">
+ <span class="tab"><%= person_image_tag(partner) %></span>
+ <span class="badge_count <%= 'hidden' if num_unread == 0 %>">
+ <%= num_unread %>
+ </span>
+</span>
View
4 app/views/chat_messages/index.html.erb
@@ -1 +1,3 @@
-<a href="/chat-make">make</a>
+<p>
+Nothing to see here. :)
+</p>
View
2  app/views/layouts/_header.html.haml
@@ -60,7 +60,7 @@
.incoming
.partners
- @chat_partners.each_with_index do |partner,i|
- = render :partial => 'chat_messages/partner', :locals => { :partner => partner, :first => i == 0 }
+ = render :partial => 'chat_messages/partner', :locals => { :partner => partner, :num_unread => @chat_messages_unread[partner].size, :first => i == 0 }
%h4.partner-current
= @chat_partners.any? ? @chat_partners[0].name : ''
.conversations
View
17 public/javascripts/chat.js
@@ -10,12 +10,24 @@ function updateChatBadge(n) {
}
}
+function updateConversationBadge( person_id, n ) {
+ var badge = $('.partner[data-person_id="' + person_id + '"] .badge_count');
+ badge.html(n);
+ if( n == 0 ) {
+ badge.hide();
+ } else {
+ badge.show();
+ }
+}
+
function markActiveConversationRead() {
+ var person_id = $('.partner.active').data('person_id');
$.post(
'/chat_messages_mark_conversation_read',
- { person_id: $('.partner.active').data('person_id') },
+ { person_id: person_id },
function(response) {
updateChatBadge( parseInt(response.num_unread) );
+ updateConversationBadge(person_id, 0)
}
);
}
@@ -59,6 +71,9 @@ function addChatMessageToConversation( message, conversation ) {
updateChatBadge( n+1 );
} else if( conversation.hasClass('active') ) {
markActiveConversationRead();
+ } else {
+ var n = parseInt( $('.partner[data-person_id="' + message.person_id + '"] .badge_count').html() );
+ updateConversationBadge(message.person_id, n+1)
}
}
View
28 public/stylesheets/sass/application.sass
@@ -3236,17 +3236,25 @@ a.toggle_selector
.incoming
.partner
- :cursor pointer
- :opacity 0.6
- img
- :height 32px
- :width 32px
+ .tab
+ :cursor pointer
+ :opacity 0.6
+ img
+ :height 32px
+ :width 32px
+ :position relative
+ .badge_count
+ :top -27px
+ :left 19px
.partner.active
- :opacity 1.0
- img
- :border-top 2px solid #3F8FBA
- :border-right 2px solid #3F8FBA
- :border-left 2px solid #3F8FBA
+ .tab
+ :opacity 1.0
+ img
+ :border-top 2px solid #3F8FBA
+ :border-right 2px solid #3F8FBA
+ :border-left 2px solid #3F8FBA
+ .badge_count
+ :left 22px
.conversation
:display none
Please sign in to comment.
Something went wrong with that request. Please try again.