Class: PostService

Inherits:
Object
  • Object
show all
Defined in:
app/services/post_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(user = nil) ⇒ PostService

Returns a new instance of PostService.


4
5
6
# File 'app/services/post_service.rb', line 4

def initialize(user=nil)
  @user = user
end

Instance Method Details

#destroy(post_id, private_allowed = true) ⇒ Object

Raises:


38
39
40
41
42
43
44
45
46
47
# File 'app/services/post_service.rb', line 38

def destroy(post_id, private_allowed=true)
  post = if private_allowed
           find_non_public_by_guid_or_id_with_user!(post_id)
         else
           find_public!(post_id)
         end
  raise Diaspora::NotMine unless post.author == user.person

  user.retract(post)
end

#find(id) ⇒ Object


8
9
10
11
12
13
14
# File 'app/services/post_service.rb', line 8

def find(id)
  if user
    user.find_visible_shareable_by_id(Post, id)
  else
    Post.find_by_id_and_public(id, true)
  end
end

#find!(id_or_guid) ⇒ Object


16
17
18
19
20
21
22
# File 'app/services/post_service.rb', line 16

def find!(id_or_guid)
  if user
    find_non_public_by_guid_or_id_with_user!(id_or_guid)
  else
    find_public!(id_or_guid)
  end
end

#mark_user_notifications(post_id) ⇒ Object


32
33
34
35
36
# File 'app/services/post_service.rb', line 32

def mark_user_notifications(post_id)
  return unless user
  mark_comment_reshare_like_notifications_read(post_id)
  mark_mention_notifications_read(post_id)
end

#mentionable_in_comment(post_id, query) ⇒ Object


49
50
51
52
53
54
55
56
57
58
# File 'app/services/post_service.rb', line 49

def mentionable_in_comment(post_id, query)
  post = find!(post_id)
  Person
    .allowed_to_be_mentioned_in_a_comment_to(post)
    .where.not(id: user.person_id)
    .find_by_substring(query)
    .sort_for_mention_suggestion(post, user)
    .for_json
    .limit(15)
end

#present_interactions_jsonObject


28
29
30
# File 'app/services/post_service.rb', line 28

def present_interactions_json
  PostInteractionPresenter.new(post, user)
end

#present_jsonObject


24
25
26
# File 'app/services/post_service.rb', line 24

def present_json
  PostPresenter.new(post, user)
end