Commit 78e30ff4 authored by danielgrippi's avatar danielgrippi

update unread count in conversation visibility when hitting conversationscontroller#show

parent fb5e5cc3
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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})"
......@@ -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', '#'
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
......@@ -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') {
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment