update unread count in conversation visibility when hitting conversationscontroller#show

This commit is contained in:
danielgrippi 2011-03-08 11:36:33 -08:00
parent fb5e5cc341
commit 78e30ff459
11 changed files with 40 additions and 16 deletions

View file

@ -4,11 +4,16 @@ class ConversationsController < ApplicationController
respond_to :html, :json respond_to :html, :json
def index def index
@all_contacts_and_ids = current_user.contacts.map{|c| {:value => c.id, :name => c.person.name}}
@conversations = Conversation.joins(:conversation_visibilities).where( @conversations = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person.id}).paginate( :conversation_visibilities => {:person_id => current_user.person.id}).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC') :page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@visibilities = ConversationVisibility.where( :person_id => current_user.person.id ).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@unread_counts = {}
@visibilities.each{|v| @unread_counts[v.conversation_id] = v.unread}
@authors = {} @authors = {}
@conversations.each{|c| @authors[c.id] = c.last_author} @conversations.each{|c| @authors[c.id] = c.last_author}
@ -17,7 +22,7 @@ class ConversationsController < ApplicationController
end end
def create def create
person_ids = Contact.where(:id => params[:contact_ids]).map! do |contact| person_ids = Contact.where(:id => params[:contact_ids].split(',')).map! do |contact|
contact.person_id contact.person_id
end end
@ -40,6 +45,11 @@ class ConversationsController < ApplicationController
@conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id], @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
:conversation_visibilities => {:person_id => current_user.person.id}).first :conversation_visibilities => {:person_id => current_user.person.id}).first
if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
@visibility.unread = 0
@visibility.save
end
if @conversation if @conversation
render :layout => false render :layout => false
else else
@ -48,6 +58,7 @@ class ConversationsController < ApplicationController
end end
def new def new
@all_contacts_and_ids = current_user.contacts.map{|c| {:value => c.id, :name => c.person.name}}
@contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id] @contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id]
render :layout => false render :layout => false
end end

View file

@ -3,7 +3,7 @@
# the COPYRIGHT file. # the COPYRIGHT file.
class PostsController < ApplicationController class PostsController < ApplicationController
skip_before_filter :set_contacts_notifications_and_status skip_before_filter :set_contacts_notifications_unread_count_and_status
skip_before_filter :count_requests skip_before_filter :count_requests
skip_before_filter :set_invites skip_before_filter :set_invites
skip_before_filter :set_locale skip_before_filter :set_locale

View file

@ -6,7 +6,7 @@ class PublicsController < ApplicationController
require File.join(Rails.root, '/lib/diaspora/parser') require File.join(Rails.root, '/lib/diaspora/parser')
include Diaspora::Parser include Diaspora::Parser
skip_before_filter :set_contacts_notifications_and_status, :except => [:create, :update] skip_before_filter :set_contacts_notifications_unread_count_and_status, :except => [:create, :update]
skip_before_filter :count_requests skip_before_filter :count_requests
skip_before_filter :set_invites skip_before_filter :set_invites
skip_before_filter :set_locale skip_before_filter :set_locale

View file

@ -2,7 +2,7 @@
-# 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.
.stream_element.conversation{:data=>{:guid=>conversation.id}} .stream_element.conversation{:data=>{:guid=>conversation.id}, :class => ('unread' if unread_counts[conversation.id].to_i > 0)}
= person_image_tag(authors[conversation.id]) = person_image_tag(authors[conversation.id])
.subject .subject
@ -15,6 +15,7 @@
.timestamp .timestamp
= time_ago_in_words conversation.updated_at = time_ago_in_words conversation.updated_at
= authors[conversation.id].name = authors[conversation.id].name
- if conversation.participants.size > 2 - if conversation.participants.size > 2
%span.participant_count %span.participant_count
= "(+#{conversation.participants.size - 1})" = "(+#{conversation.participants.size - 1})"

View file

@ -33,5 +33,5 @@
= form_for [conversation, Message.new] do |message| = form_for [conversation, Message.new] do |message|
= message.text_area :text, :rows => 5 = message.text_area :text, :rows => 5
.right .right
= message.submit 'Reply' = message.submit 'Reply', :class => 'button'
= link_to 'Cancel', '#' = link_to 'Cancel', '#'

View file

@ -12,8 +12,6 @@
:css :css
footer{ display:none;} footer{ display:none;}
= hidden_field_tag :contact_json, @all_contacts_and_ids.to_json
#left_pane #left_pane
#left_pane_header #left_pane_header
%h3 %h3
@ -24,7 +22,7 @@
#conversation_inbox #conversation_inbox
- if @conversations.count > 0 - if @conversations.count > 0
.stream.conversations .stream.conversations
= render :partial => 'conversations/conversation', :collection => @conversations, :locals => {:authors => @authors} = render :partial => 'conversations/conversation', :collection => @conversations, :locals => {:authors => @authors, :unread_counts => @unread_counts}
= will_paginate @conversations = will_paginate @conversations
- else - else
%i %i

View file

@ -12,13 +12,16 @@
searchObjProps: "name", searchObjProps: "name",
asHtmlID: "contact_ids", asHtmlID: "contact_ids",
keyDelay: 0, keyDelay: 0,
startText: '' startText: '',
preFill: [{ 'name' : "#{params[:name]}",
'value' : "#{params[:contact_id]}"}]
}); });
autocompleteInput.focus(); autocompleteInput.focus();
}); });
= hidden_field_tag :contact_json, @all_contacts_and_ids.to_json
#new_message_pane #new_message_pane
.span-12.last .span-12.last
#facebox_header #facebox_header

View file

@ -2,6 +2,10 @@
-# 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.
- content_for :head do
= include_javascripts :people
- content_for :page_title do - content_for :page_title do
= @person.name = @person.name
@ -41,8 +45,9 @@
- else - else
.right - if @contact.person
= link_to 'Message', new_conversation_path(:contact_id => @contact.id, :name => @contact.person.name, :contact_id => @contact.id), :class => 'button', :rel => 'facebox' .right
= link_to 'Message', new_conversation_path(:contact_id => @contact.id, :name => @contact.person.name, :contact_id => @contact.id), :class => 'button', :rel => 'facebox'
/- if @post_type == :photos /- if @post_type == :photos
/ = link_to t('layouts.header.view_profile'), person_path(@person) / = link_to t('layouts.header.view_profile'), person_path(@person)

View file

@ -53,6 +53,7 @@ javascripts:
- public/javascripts/aspect-filters.js - public/javascripts/aspect-filters.js
- public/javascripts/contact-list.js - public/javascripts/contact-list.js
people: people:
- public/javascripts/vendor/jquery.autoSuggest.js
- public/javascripts/contact-list.js - public/javascripts/contact-list.js
photos: photos:
- public/javascripts/photo-show.js - public/javascripts/photo-show.js

View file

@ -11,8 +11,9 @@ $(document).ready(function(){
$.get("conversations/"+conversationGuid, function(data){ $.get("conversations/"+conversationGuid, function(data){
$('.conversation', '.stream').removeClass('selected'); $('.conversation', '.stream').removeClass('selected');
conversationSummary.addClass('selected'); conversationSummary.addClass('selected').removeClass('unread');
$('#conversation_show').html(data); $('#conversation_show').html(data);
Diaspora.widgets.timeago.updateTimeAgo();
}); });
if (typeof(history.pushState) == 'function') { if (typeof(history.pushState) == 'function') {

View file

@ -2306,7 +2306,7 @@ ul.show_comments
#new_message_pane #new_message_pane
input:not([type='submit']), input:not([type='submit']),
textarea textarea
:width 377px :width 378px
:margin :margin
:right 0 :right 0
@ -2615,6 +2615,10 @@ ul.show_comments
&:hover &:hover
:cursor pointer :cursor pointer
.conversation.unread
:background
:color lighten($background,5%)
.conversation.selected .conversation.selected
:background :background
:color $blue :color $blue