From 78e30ff459d6bf8cf7a4a08c8bf89dddab6e10f6 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Tue, 8 Mar 2011 11:36:33 -0800 Subject: [PATCH] update unread count in conversation visibility when hitting conversationscontroller#show --- app/controllers/conversations_controller.rb | 17 ++++++++++++++--- app/controllers/posts_controller.rb | 2 +- app/controllers/publics_controller.rb | 2 +- app/views/conversations/_conversation.haml | 3 ++- app/views/conversations/_show.haml | 2 +- app/views/conversations/index.haml | 4 +--- app/views/conversations/new.haml | 7 +++++-- app/views/people/show.html.haml | 9 +++++++-- config/assets.yml | 1 + public/javascripts/inbox.js | 3 ++- public/stylesheets/sass/application.sass | 6 +++++- 11 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index dd0838602..5806f4358 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -4,11 +4,16 @@ class ConversationsController < ApplicationController respond_to :html, :json def index - @all_contacts_and_ids = current_user.contacts.map{|c| {:value => c.id, :name => c.person.name}} - @conversations = Conversation.joins(:conversation_visibilities).where( :conversation_visibilities => {:person_id => current_user.person.id}).paginate( :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 = {} @conversations.each{|c| @authors[c.id] = c.last_author} @@ -17,7 +22,7 @@ class ConversationsController < ApplicationController end 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 end @@ -40,6 +45,11 @@ class ConversationsController < ApplicationController @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id], :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 render :layout => false else @@ -48,6 +58,7 @@ class ConversationsController < ApplicationController end 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] render :layout => false end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 73ed1f772..9ab139566 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -3,7 +3,7 @@ # the COPYRIGHT file. 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 :set_invites skip_before_filter :set_locale diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 64db524f6..85806c76d 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -6,7 +6,7 @@ class PublicsController < ApplicationController require File.join(Rails.root, '/lib/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 :set_invites skip_before_filter :set_locale diff --git a/app/views/conversations/_conversation.haml b/app/views/conversations/_conversation.haml index bcf865746..604ae5125 100644 --- a/app/views/conversations/_conversation.haml +++ b/app/views/conversations/_conversation.haml @@ -2,7 +2,7 @@ -# licensed under the Affero General Public License version 3 or later. See -# 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]) .subject @@ -15,6 +15,7 @@ .timestamp = time_ago_in_words conversation.updated_at = authors[conversation.id].name + - if conversation.participants.size > 2 %span.participant_count = "(+#{conversation.participants.size - 1})" diff --git a/app/views/conversations/_show.haml b/app/views/conversations/_show.haml index bee452285..85adf3bef 100644 --- a/app/views/conversations/_show.haml +++ b/app/views/conversations/_show.haml @@ -33,5 +33,5 @@ = form_for [conversation, Message.new] do |message| = message.text_area :text, :rows => 5 .right - = message.submit 'Reply' + = message.submit 'Reply', :class => 'button' = link_to 'Cancel', '#' diff --git a/app/views/conversations/index.haml b/app/views/conversations/index.haml index 0ac8a517d..6fdc0f141 100644 --- a/app/views/conversations/index.haml +++ b/app/views/conversations/index.haml @@ -12,8 +12,6 @@ :css footer{ display:none;} -= hidden_field_tag :contact_json, @all_contacts_and_ids.to_json - #left_pane #left_pane_header %h3 @@ -24,7 +22,7 @@ #conversation_inbox - if @conversations.count > 0 .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 - else %i diff --git a/app/views/conversations/new.haml b/app/views/conversations/new.haml index 88ec08275..9be57e181 100644 --- a/app/views/conversations/new.haml +++ b/app/views/conversations/new.haml @@ -12,13 +12,16 @@ searchObjProps: "name", asHtmlID: "contact_ids", keyDelay: 0, - startText: '' + startText: '', + preFill: [{ 'name' : "#{params[:name]}", + 'value' : "#{params[:contact_id]}"}] }); autocompleteInput.focus(); - }); += hidden_field_tag :contact_json, @all_contacts_and_ids.to_json + #new_message_pane .span-12.last #facebox_header diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index 6e6a73e6b..d37df6b7c 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -2,6 +2,10 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. + +- content_for :head do + = include_javascripts :people + - content_for :page_title do = @person.name @@ -41,8 +45,9 @@ - else - .right - = link_to 'Message', new_conversation_path(:contact_id => @contact.id, :name => @contact.person.name, :contact_id => @contact.id), :class => 'button', :rel => 'facebox' + - if @contact.person + .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 / = link_to t('layouts.header.view_profile'), person_path(@person) diff --git a/config/assets.yml b/config/assets.yml index 0f56bf764..4476666a7 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -53,6 +53,7 @@ javascripts: - public/javascripts/aspect-filters.js - public/javascripts/contact-list.js people: + - public/javascripts/vendor/jquery.autoSuggest.js - public/javascripts/contact-list.js photos: - public/javascripts/photo-show.js diff --git a/public/javascripts/inbox.js b/public/javascripts/inbox.js index 769b6a0c8..1172b61c7 100644 --- a/public/javascripts/inbox.js +++ b/public/javascripts/inbox.js @@ -11,8 +11,9 @@ $(document).ready(function(){ $.get("conversations/"+conversationGuid, function(data){ $('.conversation', '.stream').removeClass('selected'); - conversationSummary.addClass('selected'); + conversationSummary.addClass('selected').removeClass('unread'); $('#conversation_show').html(data); + Diaspora.widgets.timeago.updateTimeAgo(); }); if (typeof(history.pushState) == 'function') { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index af049954b..89045d0bb 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -2306,7 +2306,7 @@ ul.show_comments #new_message_pane input:not([type='submit']), textarea - :width 377px + :width 378px :margin :right 0 @@ -2615,6 +2615,10 @@ ul.show_comments &:hover :cursor pointer +.conversation.unread + :background + :color lighten($background,5%) + .conversation.selected :background :color $blue