Merge branch 'master' of github.com:diaspora/diaspora
This commit is contained in:
commit
c30e3ee362
18 changed files with 28 additions and 79 deletions
|
|
@ -59,7 +59,7 @@ class Comment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def notification_type(user, person)
|
def notification_type(user, person)
|
||||||
if (self.post.author == user.person) && (self.author != user.person)
|
if self.post.author == user.person
|
||||||
return Notifications::CommentOnPost
|
return Notifications::CommentOnPost
|
||||||
elsif self.post.comments.where(:author_id => user.person.id) != [] && self.author_id != user.person.id
|
elsif self.post.comments.where(:author_id => user.person.id) != [] && self.author_id != user.person.id
|
||||||
return Notifications::AlsoCommented
|
return Notifications::AlsoCommented
|
||||||
|
|
|
||||||
|
|
@ -36,19 +36,11 @@ class Conversation < ActiveRecord::Base
|
||||||
def participant_handles
|
def participant_handles
|
||||||
self.participants.map{|p| p.diaspora_handle}.join(";")
|
self.participants.map{|p| p.diaspora_handle}.join(";")
|
||||||
end
|
end
|
||||||
|
|
||||||
def participant_handles= handles
|
def participant_handles= handles
|
||||||
handles.split(';').each do |handle|
|
handles.split(';').each do |handle|
|
||||||
self.participants << Webfinger.new(handle).fetch
|
self.participants << Webfinger.new(handle).fetch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def participant_users
|
|
||||||
@participant_users ||= lambda do
|
|
||||||
user_ids = self.participants.map {|p| p.owner_id}.compact
|
|
||||||
User.where(:id => user_ids)
|
|
||||||
end.call
|
|
||||||
end
|
|
||||||
|
|
||||||
def last_author
|
def last_author
|
||||||
self.messages.last.author if self.messages.size > 0
|
self.messages.last.author if self.messages.size > 0
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,6 @@ module Jobs
|
||||||
|
|
||||||
def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_string)
|
def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_string)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
|
||||||
#could be bad here
|
|
||||||
people = Person.where(:id => person_ids)
|
people = Person.where(:id => person_ids)
|
||||||
|
|
||||||
dispatcher = dispatcher_class_as_string.constantize
|
dispatcher = dispatcher_class_as_string.constantize
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,17 @@ module Jobs
|
||||||
require File.join(Rails.root, 'app/models/notification')
|
require File.join(Rails.root, 'app/models/notification')
|
||||||
|
|
||||||
def self.perform(user_ids, object_klass, object_id, person_id)
|
def self.perform(user_ids, object_klass, object_id, person_id)
|
||||||
|
|
||||||
object = object_klass.constantize.find_by_id(object_id)
|
object = object_klass.constantize.find_by_id(object_id)
|
||||||
users = object.participant_users
|
|
||||||
|
#hax
|
||||||
|
return if (object.author.diaspora_handle == 'diasporahq@joindiaspora.com' || (object.respond_to?(:relayable?) && object.parent.author.diaspora_handle == 'diasporahq@joindiaspora.com'))
|
||||||
|
#end hax
|
||||||
|
|
||||||
|
users = User.where(:id => user_ids)
|
||||||
person = Person.find_by_id(person_id)
|
person = Person.find_by_id(person_id)
|
||||||
users.each do |user|
|
|
||||||
Notification.notify(user, object, person)
|
users.each{|user| Notification.notify(user, object, person) }
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,7 @@ module Jobs
|
||||||
@queue = :receive
|
@queue = :receive
|
||||||
|
|
||||||
def self.perform(object_class_string, object_id, recipient_user_ids)
|
def self.perform(object_class_string, object_id, recipient_user_ids)
|
||||||
|
|
||||||
|
|
||||||
object = object_class_string.constantize.find(object_id)
|
object = object_class_string.constantize.find(object_id)
|
||||||
|
|
||||||
#recipient user ids could be really bad
|
|
||||||
receiver = Postzord::Receiver::LocalBatch.new(object, recipient_user_ids)
|
receiver = Postzord::Receiver::LocalBatch.new(object, recipient_user_ids)
|
||||||
receiver.perform!
|
receiver.perform!
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
# 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.
|
||||||
|
#
|
||||||
class Notification < ActiveRecord::Base
|
class Notification < ActiveRecord::Base
|
||||||
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
||||||
include Diaspora::Socketable
|
include Diaspora::Socketable
|
||||||
|
|
@ -16,8 +16,6 @@ class Notification < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.notify(recipient, target, actor)
|
def self.notify(recipient, target, actor)
|
||||||
return false if recipient.person == actor #never notify someone if they are the actor, derp
|
|
||||||
|
|
||||||
if target.respond_to? :notification_type
|
if target.respond_to? :notification_type
|
||||||
if note_type = target.notification_type(recipient, actor)
|
if note_type = target.notification_type(recipient, actor)
|
||||||
if(target.is_a? Comment) || (target.is_a? Like)
|
if(target.is_a? Comment) || (target.is_a? Like)
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ class Person < ActiveRecord::Base
|
||||||
has_many :posts, :foreign_key => :author_id, :dependent => :destroy # This person's own posts
|
has_many :posts, :foreign_key => :author_id, :dependent => :destroy # This person's own posts
|
||||||
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 :likes, :foreign_key => :author_id, :dependent => :destroy # This person's own likes
|
|
||||||
|
|
||||||
belongs_to :owner, :class_name => 'User'
|
belongs_to :owner, :class_name => 'User'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
%span#publisher_service_icons
|
%span#publisher_service_icons
|
||||||
- if current_user.services
|
- if current_user.services
|
||||||
- for service in current_user.services
|
- for service in current_user.services
|
||||||
= image_tag "social_media_logos/#{service.provider}-16x16.png", :title => service.provider.titleize, :class => "service_icon dim", :id =>"#{service.provider}", :maxchar => "#{service.class::MAX_CHARACTERS}"
|
= image_tag "social_media_logos/#{service.provider}-32x32.png", :title => service.provider.titleize, :class => "service_icon dim", :id =>"#{service.provider}", :maxchar => "#{service.class::MAX_CHARACTERS}"
|
||||||
|
|
||||||
%select{:id => "aspect_ids_", :name => "aspect_ids[]", :style => "float:right;"}
|
%select{:id => "aspect_ids_", :name => "aspect_ids[]", :style => "float:right;"}
|
||||||
%option{:value => 'public'}
|
%option{:value => 'public'}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,10 @@ defaults: &defaults
|
||||||
# Websocket port - should normally be 8080 or 8081.
|
# Websocket port - should normally be 8080 or 8081.
|
||||||
socket_port: 8080
|
socket_port: 8080
|
||||||
|
|
||||||
# Setting the root certificate bundle (this is operating system specific). Defaults:
|
# Setting the root certificate bundle (this is operating system specific). Examples, uncomment one:
|
||||||
# CentOS: '/etc/pki/tls/certs/ca-bundle.crt'
|
ca_file: '/etc/pki/tls/certs/ca-bundle.crt' # CentOS
|
||||||
# Debian: '/etc/ssl/certs/ca-certificates.crt'
|
#ca_file: '/etc/ssl/certs/ca-certificates.crt' # Debian
|
||||||
# Gentoo: '/etc/ssl/certs/ca-certificates.crt'
|
#ca_file: '/etc/ssl/certs/ca-certificates.crt' # Gentoo
|
||||||
ca_file: '/etc/pki/tls/certs/ca-bundle.crt'
|
|
||||||
|
|
||||||
# Secure websocket confguration (wss://).
|
# Secure websocket confguration (wss://).
|
||||||
# Requires SSL cert and key
|
# Requires SSL cert and key
|
||||||
|
|
|
||||||
|
|
@ -46,14 +46,6 @@ module Diaspora
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def particpants
|
|
||||||
self.parent.participants
|
|
||||||
end
|
|
||||||
|
|
||||||
def participant_users
|
|
||||||
self.parent.participant_users
|
|
||||||
end
|
|
||||||
|
|
||||||
def receive(user, person=nil)
|
def receive(user, person=nil)
|
||||||
comment_or_like = self.class.where(:guid => self.guid).first || self
|
comment_or_like = self.class.where(:guid => self.guid).first || self
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,28 +107,6 @@ module Diaspora
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Array<Person>] The list of participants to this shareable
|
|
||||||
def participants
|
|
||||||
@participants ||= lambda do
|
|
||||||
share_type = self.class.base_class.to_s
|
|
||||||
people = []
|
|
||||||
if self.respond_to? :comments
|
|
||||||
people += Person.joins(:comments).where(:comments => {:commentable_id => self.id, :commentable_type => share_type}).all
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.respond_to? :likes
|
|
||||||
people += Person.joins(:likes).where(:likes => {:target_id => self.id, :target_type => share_type}).all
|
|
||||||
end
|
|
||||||
people
|
|
||||||
end.call
|
|
||||||
end
|
|
||||||
|
|
||||||
def participant_users
|
|
||||||
@participant_users ||= lambda do
|
|
||||||
user_ids = participants.map{|x| x.owner_id}.compact
|
|
||||||
User.where(:id => user_ids)
|
|
||||||
end.call
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,15 @@ class Postzord::Dispatcher
|
||||||
# @param services [Array<User>]
|
# @param services [Array<User>]
|
||||||
def notify_users(users)
|
def notify_users(users)
|
||||||
return unless users.present? && @object.respond_to?(:persisted?)
|
return unless users.present? && @object.respond_to?(:persisted?)
|
||||||
Resque.enqueue(Jobs::NotifyLocalUsers, users.map{|u| u.id}, @object.class.to_s, @object.id, @object.author.id)
|
|
||||||
|
#temp hax
|
||||||
|
unless object_is_related_to_diaspora_hq?
|
||||||
|
Resque.enqueue(Jobs::NotifyLocalUsers, users.map{|u| u.id}, @object.class.to_s, @object.id, @object.author.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def object_is_related_to_diaspora_hq?
|
||||||
|
(@object.author.diaspora_handle == 'diasporahq@joindiaspora.com' || (@object.respond_to?(:relayable?) && @object.parent.author.diaspora_handle == 'diasporahq@joindiaspora.com'))
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param services [Array<User>]
|
# @param services [Array<User>]
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ class Postzord::Receiver::LocalBatch < Postzord::Receiver
|
||||||
def initialize(object, recipient_user_ids)
|
def initialize(object, recipient_user_ids)
|
||||||
@object = object
|
@object = object
|
||||||
@recipient_user_ids = recipient_user_ids
|
@recipient_user_ids = recipient_user_ids
|
||||||
#this is a nightmare
|
|
||||||
@users = User.where(:id => @recipient_user_ids)
|
@users = User.where(:id => @recipient_user_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -117,4 +117,5 @@ class Stream::Multi < Stream::Base
|
||||||
def ids(query)
|
def ids(query)
|
||||||
Post.connection.select_values(query.for_a_stream(max_time, order).select('posts.id').to_sql)
|
Post.connection.select_values(query.for_a_stream(max_time, order).select('posts.id').to_sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ $cookie_parser = Rack::Builder.new do
|
||||||
use ActionDispatch::Session::CookieStore, :key => "_diaspora_session"
|
use ActionDispatch::Session::CookieStore, :key => "_diaspora_session"
|
||||||
use Warden::Manager do |warden|
|
use Warden::Manager do |warden|
|
||||||
warden.default_scope = :user
|
warden.default_scope = :user
|
||||||
|
warden.failure_app = Proc.new {|env| [0, {}, nil]}
|
||||||
end
|
end
|
||||||
|
|
||||||
run Proc.new {|env| [0, {}, env['warden'].user]}
|
run Proc.new {|env| [0, {}, env['warden'].user]}
|
||||||
|
|
|
||||||
|
|
@ -36,12 +36,6 @@ describe Comment do
|
||||||
@comment.notification_type(alice, alice.person).should == Notifications::AlsoCommented
|
@comment.notification_type(alice, alice.person).should == Notifications::AlsoCommented
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not return if you are author of the object being commented on' do
|
|
||||||
p = Factory(:status_message, :author => bob.person)
|
|
||||||
c = bob.comment("dfs", :post => p)
|
|
||||||
c.notification_type(bob, bob.person).should be_false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'User#comment' do
|
describe 'User#comment' do
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ describe Jobs::NotifyLocalUsers do
|
||||||
post = Factory :status_message
|
post = Factory :status_message
|
||||||
|
|
||||||
StatusMessage.should_receive(:find_by_id).with(post.id).and_return(post)
|
StatusMessage.should_receive(:find_by_id).with(post.id).and_return(post)
|
||||||
post.should_receive(:participant_users).and_return([alice, eve])
|
#User.should_receive(:where).and_return([alice, eve])
|
||||||
Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)).twice
|
Notification.should_receive(:notify).with(instance_of(User), instance_of(StatusMessage), instance_of(Person)).twice
|
||||||
|
|
||||||
Jobs::NotifyLocalUsers.perform([alice.id, eve.id], post.class.to_s, post.id, person.id)
|
Jobs::NotifyLocalUsers.perform([alice.id, eve.id], post.class.to_s, post.id, person.id)
|
||||||
|
|
|
||||||
|
|
@ -195,17 +195,6 @@ describe Post do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#participants' do
|
|
||||||
it 'only returns the people that commented and liked the post' do
|
|
||||||
status = Factory(:status_message, :author => bob.person, :public => true)
|
|
||||||
alice.comment('too', :post => status)
|
|
||||||
eve.like(true, :target => status)
|
|
||||||
|
|
||||||
status.participants.map(&:id).should =~ [alice, eve].map{|x| x.person.id}
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#comments' do
|
describe '#comments' do
|
||||||
it 'returns the comments of a post in created_at order' do
|
it 'returns the comments of a post in created_at order' do
|
||||||
post = bob.post :status_message, :text => "hello", :to => 'all'
|
post = bob.post :status_message, :text => "hello", :to => 'all'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue