Class: TopicConverter

Inherits:
Object
  • Object
show all
Defined in:
app/models/topic_converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(topic, user) ⇒ TopicConverter

Returns a new instance of TopicConverter.



6
7
8
9
# File 'app/models/topic_converter.rb', line 6

def initialize(topic, user)
  @topic = topic
  @user = user
end

Instance Attribute Details

#topicObject (readonly)

Returns the value of attribute topic.



4
5
6
# File 'app/models/topic_converter.rb', line 4

def topic
  @topic
end

Instance Method Details

#convert_to_private_messageObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/topic_converter.rb', line 41

def convert_to_private_message
  Topic.transaction do
    @topic.update_category_topic_count_by(-1) if @topic.visible

    PostRevisor.new(@topic.first_post, @topic).revise!(
      @user,
      category_id: nil,
      archetype: Archetype.private_message,
    )

    add_allowed_users
    update_post_uploads_secure_status
    UserProfile.remove_featured_topic_from_all_profiles(@topic)

    Jobs.enqueue(:topic_action_converter, topic_id: @topic.id)
    Jobs.enqueue(:delete_inaccessible_notifications, topic_id: @topic.id)

    watch_topic(topic)
  end
  @topic
end

#convert_to_public_topic(category_id = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/topic_converter.rb', line 11

def convert_to_public_topic(category_id = nil)
  Topic.transaction do
    category_id =
      if category_id
        category_id
      elsif SiteSetting.allow_uncategorized_topics
        SiteSetting.uncategorized_category_id
      else
        Category
          .where(read_restricted: false)
          .where.not(id: SiteSetting.uncategorized_category_id)
          .order("id asc")
          .pick(:id)
      end

    PostRevisor.new(@topic.first_post, @topic).revise!(
      @user,
      category_id: category_id,
      archetype: Archetype.default,
    )

    update_user_stats
    update_post_uploads_secure_status
    Jobs.enqueue(:topic_action_converter, topic_id: @topic.id)
    Jobs.enqueue(:delete_inaccessible_notifications, topic_id: @topic.id)
    watch_topic(topic)
  end
  @topic
end