Class: Postzord::Receiver::LocalBatch

Inherits:
Postzord::Receiver show all
Defined in:
lib/postzord/receiver/local_batch.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Postzord::Receiver

#author_does_not_match_xml_author?, #perform!

Constructor Details

#initialize(object, recipient_user_ids) ⇒ LocalBatch


9
10
11
12
13
14
# File 'lib/postzord/receiver/local_batch.rb', line 9

def initialize(object, recipient_user_ids)
  @object = object
  @recipient_user_ids = recipient_user_ids
  @users = User.where(:id => @recipient_user_ids)

end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object


7
8
9
# File 'lib/postzord/receiver/local_batch.rb', line 7

def object
  @object
end

#recipient_user_idsObject (readonly)

Returns the value of attribute recipient_user_ids


7
8
9
# File 'lib/postzord/receiver/local_batch.rb', line 7

def recipient_user_ids
  @recipient_user_ids
end

#usersObject (readonly)

Returns the value of attribute users


7
8
9
# File 'lib/postzord/receiver/local_batch.rb', line 7

def users
  @users
end

Instance Method Details

#create_share_visibilitiesvoid

Note:

performs a bulk insert into mySQL

This method returns an undefined value.

Batch import post visibilities for the recipients of the given @object


45
46
47
48
# File 'lib/postzord/receiver/local_batch.rb', line 45

def create_share_visibilities
  contacts_ids = Contact.connection.select_values(Contact.where(:user_id => @recipient_user_ids, :person_id => @object.author_id).select("id").to_sql)
  ShareVisibility.batch_import(contacts_ids, object)
end

#notify_mentioned_usersvoid

This method returns an undefined value.

Notify any mentioned users within the @object's text


52
53
54
55
56
# File 'lib/postzord/receiver/local_batch.rb', line 52

def notify_mentioned_users
  @object.mentions.each do |mention|
    mention.notify_recipient
  end
end

#notify_usersObject

NOTE(these methods should be in their own module, included in this class) Notify users of the new object return [void]


61
62
63
64
65
66
# File 'lib/postzord/receiver/local_batch.rb', line 61

def notify_users
  return unless @object.respond_to?(:notification_type)
  @users.find_each do |user|
    Notification.notify(user, @object, @object.author)
  end
end

#receive!Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/postzord/receiver/local_batch.rb', line 16

def receive!
  FEDERATION_LOGGER.info("receiving local batch for #{@object.inspect}")
  if @object.respond_to?(:relayable?)
    receive_relayable
  else
    create_share_visibilities
  end
  notify_mentioned_users if @object.respond_to?(:mentions)

  # 09/27/11 this is slow
  notify_users

  FEDERATION_LOGGER.info("receiving local batch completed for #{@object.inspect}")
  true
end

#receive_relayableObject

NOTE(copied over from receiver public)


34
35
36
37
38
39
40
# File 'lib/postzord/receiver/local_batch.rb', line 34

def receive_relayable
  if @object.parent_author.local?
    # receive relayable object only for the owner of the parent object
    @object.receive(@object.parent_author.owner)
  end
  @object
end