Class: Thredded::PrivateTopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/thredded/private_topics_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#signed_in?

Instance Method Details

#create ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/thredded/private_topics_controller.rb', line 34

def create
  @private_topic = PrivateTopicForm.new(new_private_topic_params)
  if @private_topic.save
    NotifyPrivateTopicUsersJob
      .perform_later(@private_topic.private_topic.id)

    UserResetsPrivateTopicToUnread
      .new(@private_topic.private_topic, thredded_current_user)
      .run

    redirect_to @private_topic.private_topic
  else
    render :new
  end
end

#index ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/thredded/private_topics_controller.rb', line 5

def index
  @new_private_topic = PrivateTopicForm.new(user: thredded_current_user)
  @private_topics = PrivateTopic
                      .uniq
                      .for_user(thredded_current_user)
                      .order('updated_at DESC')
                      .on_page(params[:page])
                      .load
  @decorated_private_topics = Thredded::UserPrivateTopicDecorator
    .decorate_all(thredded_current_user, @private_topics)
end

#new ⇒ Object



29
30
31
32
# File 'app/controllers/thredded/private_topics_controller.rb', line 29

def new
  @private_topic = PrivateTopicForm.new(user: thredded_current_user)
  authorize_creating @private_topic.private_topic
end

#show ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/thredded/private_topics_controller.rb', line 17

def show
  authorize! :read, private_topic
  UserReadsPrivateTopic.new(private_topic, thredded_current_user).run

  @posts = private_topic
    .posts
    .includes(:user)
    .order('id ASC')

  @post = private_topic.posts.build
end