Module: User::SocialActions

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

Instance Method Summary collapse

Instance Method Details

#build_comment(options = {}) ⇒ Object


29
30
31
# File 'app/models/user/social_actions.rb', line 29

def build_comment(options={})
  Comment::Generator.new(self, options.delete(:post), options.delete(:text)).build(options)
end

#build_conversation(opts = {}) ⇒ Object


33
34
35
36
37
38
39
40
41
42
# File 'app/models/user/social_actions.rb', line 33

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


44
45
46
47
48
49
# File 'app/models/user/social_actions.rb', line 44

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

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


2
3
4
5
# File 'app/models/user/social_actions.rb', line 2

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

#find_or_create_participation!(target) ⇒ Object


51
52
53
# File 'app/models/user/social_actions.rb', line 51

def find_or_create_participation!(target)
  participations.where(:target_id => target).first || participate!(target)
end

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


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

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

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


7
8
9
# File 'app/models/user/social_actions.rb', line 7

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

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


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

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

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


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

def reshare!(target, opts={})
  find_or_create_participation!(target)
  reshare = build_post(:reshare, :root_guid => target.guid)
  reshare.save!
  Postzord::Dispatcher.defer_build_and_post(self, reshare)
  reshare
end