Module: User::SocialActions

Included in:
User
Defined in:
app/models/user/social_actions.rb

Instance Method Summary collapse

Instance Method Details

#build_conversation(opts = {}) ⇒ Object


36
37
38
39
40
41
42
43
44
45
# File 'app/models/user/social_actions.rb', line 36

def build_conversation(opts={})
  Conversation.new do |c|
    c.author = self.person
    c.subject = opts[:subject]
    c.participant_ids = [*opts[:participant_ids]] | [self.person_id]
    c.messages_attributes = [
      { author: self.person, text: opts[:message][:text] }
    ]
  end
end

#build_message(conversation, opts = {}) ⇒ Object


47
48
49
50
51
52
# File 'app/models/user/social_actions.rb', line 47

def build_message(conversation, opts={})
  conversation.messages.build(
    text: opts[:text],
    author: self.person
  )
end

#comment!(target, text, opts = {}) ⇒ Object


4
5
6
7
8
# File 'app/models/user/social_actions.rb', line 4

def comment!(target, text, opts={})
  Comment::Generator.new(self, target, text).create!(opts).tap do
    update_or_create_participation!(target)
  end
end

#like!(target, opts = {}) ⇒ Object


14
15
16
17
18
# File 'app/models/user/social_actions.rb', line 14

def like!(target, opts={})
  Like::Generator.new(self, target).create!(opts).tap do
    update_or_create_participation!(target)
  end
end

#participate!(target, opts = {}) ⇒ Object


10
11
12
# File 'app/models/user/social_actions.rb', line 10

def participate!(target, opts={})
  Participation::Generator.new(self, target).create!(opts)
end

#participate_in_poll!(target, answer, opts = {}) ⇒ Object


20
21
22
23
24
# File 'app/models/user/social_actions.rb', line 20

def participate_in_poll!(target, answer, opts={})
  PollParticipation::Generator.new(self, target, answer).create!(opts).tap do
    update_or_create_participation!(target)
  end
end

#reshare!(target, opts = {}) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'app/models/user/social_actions.rb', line 26

def reshare!(target, opts={})
  raise I18n.t("reshares.create.error") if target.author.guid == guid

  build_post(:reshare, :root_guid => target.guid).tap do |reshare|
    reshare.save!
    update_or_create_participation!(target)
    Diaspora::Federation::Dispatcher.defer_dispatch(self, reshare)
  end
end

#update_or_create_participation!(target) ⇒ Object


54
55
56
57
58
59
60
61
62
# File 'app/models/user/social_actions.rb', line 54

def update_or_create_participation!(target)
  return if target.author == person
  participation = participations.find_by(target_id: target)
  if participation.present?
    participation.update!(count: participation.count.next)
  else
    participate!(target)
  end
end