Skip to content
Extraits de code Groupes Projets
Valider 4bc28f22 rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

Merge pull request #4547 from Raven24/conversations

refactor conversations_controller a bit
parents 6e62a997 260d86d5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
* Ported fileuploader to Backbone and refactored publisher views [#4480](https://github.com/diaspora/diaspora/pull/4480) * Ported fileuploader to Backbone and refactored publisher views [#4480](https://github.com/diaspora/diaspora/pull/4480)
* Refactor 404.html, fix [#4078](https://github.com/diaspora/diaspora/issues/4078) * Refactor 404.html, fix [#4078](https://github.com/diaspora/diaspora/issues/4078)
* Remove the (now useless) last post link from the user profile. [#4540](https://github.com/diaspora/diaspora/pull/4540) * Remove the (now useless) last post link from the user profile. [#4540](https://github.com/diaspora/diaspora/pull/4540)
* Refactor ConversationsController, move query building to User model. [#4547](https://github.com/diaspora/diaspora/pull/4547)
## Bug fixes ## Bug fixes
* Highlight down arrow at the user menu on hover [#4441](https://github.com/diaspora/diaspora/pull/4441) * Highlight down arrow at the user menu on hover [#4441](https://github.com/diaspora/diaspora/pull/4441)
......
...@@ -4,19 +4,18 @@ class ConversationsController < ApplicationController ...@@ -4,19 +4,18 @@ class ConversationsController < ApplicationController
respond_to :html, :mobile, :json, :js respond_to :html, :mobile, :json, :js
def index def index
@conversations = Conversation.joins(:conversation_visibilities).where( @conversations = current_user.conversations.paginate(
:conversation_visibilities => {:person_id => current_user.person_id}).paginate( :page => params[:page], :per_page => 15)
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@visibilities = current_user.conversation_visibilities.paginate(
:page => params[:page], :per_page => 15)
@visibilities = ConversationVisibility.where(:person_id => current_user.person_id).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@conversation = Conversation.joins(:conversation_visibilities).where( @conversation = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person_id, :conversation_id => params[:conversation_id]}).first :conversation_visibilities => {:person_id => current_user.person_id, :conversation_id => params[:conversation_id]}).first
@unread_counts = {} @unread_counts = {}
@visibilities.each { |v| @unread_counts[v.conversation_id] = v.unread } @visibilities.each { |v| @unread_counts[v.conversation_id] = v.unread }
@first_unread_message_id = @conversation.try(:first_unread_message, current_user).try(:id) @first_unread_message_id = @conversation.try(:first_unread_message, current_user).try(:id)
@authors = {} @authors = {}
...@@ -60,8 +59,7 @@ class ConversationsController < ApplicationController ...@@ -60,8 +59,7 @@ class ConversationsController < ApplicationController
end end
def show def show
if @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id], if @conversation = current_user.conversations.where(id: params[:id]).first
:conversation_visibilities => {:person_id => current_user.person_id}).first
@first_unread_message_id = @conversation.first_unread_message(current_user).try(:id) @first_unread_message_id = @conversation.first_unread_message(current_user).try(:id)
if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
......
...@@ -45,6 +45,7 @@ class Person < ActiveRecord::Base ...@@ -45,6 +45,7 @@ class Person < ActiveRecord::Base
has_many :photos, :foreign_key => :author_id, :dependent => :destroy # This person's own photos has_many :photos, :foreign_key => :author_id, :dependent => :destroy # This person's own photos
has_many :comments, :foreign_key => :author_id, :dependent => :destroy # This person's own comments has_many :comments, :foreign_key => :author_id, :dependent => :destroy # This person's own comments
has_many :participations, :foreign_key => :author_id, :dependent => :destroy has_many :participations, :foreign_key => :author_id, :dependent => :destroy
has_many :conversation_visibilities
has_many :roles has_many :roles
......
...@@ -61,6 +61,9 @@ class User < ActiveRecord::Base ...@@ -61,6 +61,9 @@ class User < ActiveRecord::Base
has_many :blocks has_many :blocks
has_many :ignored_people, :through => :blocks, :source => :person has_many :ignored_people, :through => :blocks, :source => :person
has_many :conversation_visibilities, through: :person, order: 'updated_at DESC'
has_many :conversations, through: :conversation_visibilities, order: 'updated_at DESC'
has_many :notifications, :foreign_key => :recipient_id has_many :notifications, :foreign_key => :recipient_id
before_save :guard_unconfirmed_email, before_save :guard_unconfirmed_email,
...@@ -338,7 +341,7 @@ class User < ActiveRecord::Base ...@@ -338,7 +341,7 @@ class User < ActiveRecord::Base
def update_profile_with_omniauth( user_info ) def update_profile_with_omniauth( user_info )
update_profile( self.profile.from_omniauth_hash( user_info ) ) update_profile( self.profile.from_omniauth_hash( user_info ) )
end end
def deliver_profile_update def deliver_profile_update
Postzord::Dispatcher.build(self, profile).post Postzord::Dispatcher.build(self, profile).post
......
...@@ -29,7 +29,7 @@ class AccountDeleter ...@@ -29,7 +29,7 @@ class AccountDeleter
remove_share_visibilities_on_persons_posts remove_share_visibilities_on_persons_posts
delete_contacts_of_me delete_contacts_of_me
tombstone_person_and_profile tombstone_person_and_profile
if self.user if self.user
#user deletion methods #user deletion methods
remove_share_visibilities_on_contacts_posts remove_share_visibilities_on_contacts_posts
...@@ -50,7 +50,7 @@ class AccountDeleter ...@@ -50,7 +50,7 @@ class AccountDeleter
end end
def ignored_ar_user_associations def ignored_ar_user_associations
[:followed_tags, :invited_by, :contact_people, :aspect_memberships, :ignored_people] [:followed_tags, :invited_by, :contact_people, :aspect_memberships, :ignored_people, :conversation_visibilities, :conversations]
end end
def delete_standard_user_associations def delete_standard_user_associations
...@@ -101,12 +101,12 @@ class AccountDeleter ...@@ -101,12 +101,12 @@ class AccountDeleter
def delete_contacts_of_me def delete_contacts_of_me
Contact.all_contacts_of_person(self.person).destroy_all Contact.all_contacts_of_person(self.person).destroy_all
end end
def normal_ar_person_associates_to_delete def normal_ar_person_associates_to_delete
[:posts, :photos, :mentions, :participations, :roles] [:posts, :photos, :mentions, :participations, :roles]
end end
def ignored_or_special_ar_person_associations def ignored_or_special_ar_person_associations
[:comments, :contacts, :notification_actors, :notifications, :owner, :profile ] [:comments, :contacts, :notification_actors, :notifications, :owner, :profile, :conversation_visibilities]
end end
end end
...@@ -208,6 +208,37 @@ FactoryGirl.define do ...@@ -208,6 +208,37 @@ FactoryGirl.define do
association(:post, :factory => :status_message) association(:post, :factory => :status_message)
end end
factory(:conversation) do
association(:author, factory: :person)
sequence(:subject) { |n| "conversation ##{n}" }
after(:build) do |c|
c.participants << c.author
end
end
factory(:conversation_with_message, parent: :conversation) do
after(:build) do |c|
msg = FactoryGirl.build(:message)
msg.conversation_id = c.id
c.participants << msg.author
msg.save
end
end
factory(:message) do
association(:author, factory: :person)
sequence(:text) { |n| "message text ##{n}" }
end
factory(:message_with_conversation, parent: :message) do
after(:build) do |msg|
c = FactoryGirl.build(:conversation)
c.participants << msg.author
msg.conversation_id = c.id
end
end
#templates #templates
factory(:status_with_photo_backdrop, :parent => :status_message_with_photo) factory(:status_with_photo_backdrop, :parent => :status_message_with_photo)
......
...@@ -5,6 +5,31 @@ ...@@ -5,6 +5,31 @@
require 'spec_helper' require 'spec_helper'
describe User do describe User do
context "relations" do
context "#conversations" do
it "doesn't find anything when there is nothing to find" do
u = FactoryGirl.create(:user)
u.conversations.should be_empty
end
it "finds the users conversations" do
c = FactoryGirl.create(:conversation, { author: alice.person })
alice.conversations.should include c
end
it "doesn't find other users conversations" do
c1 = FactoryGirl.create(:conversation)
c2 = FactoryGirl.create(:conversation)
c_own = FactoryGirl.create(:conversation, { author: alice.person })
alice.conversations.should include c_own
alice.conversations.should_not include c1
alice.conversations.should_not include c2
end
end
end
describe "private key" do describe "private key" do
it 'has a key' do it 'has a key' do
alice.encryption_key.should_not be nil alice.encryption_key.should_not be nil
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter