Class: InstagramConnect::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/instagram_connect/comments_controller.rb

Overview

Moderate comments on the account's media: list, reply, hide/unhide, delete. Moderation calls the Graph API synchronously (fast, operator-facing) and only updates local state on success.

Instance Method Summary collapse

Instance Method Details

#destroyObject



32
33
34
35
36
# File 'app/controllers/instagram_connect/comments_controller.rb', line 32

def destroy
  moderate(notice: "Comment deleted.",
           call: ->(client) { client.delete_comment(comment_id: @comment.comment_id) },
           on_success: -> { @comment.destroy! })
end

#hideObject



20
21
22
23
24
# File 'app/controllers/instagram_connect/comments_controller.rb', line 20

def hide
  moderate(notice: "Comment hidden.",
           call: ->(client) { client.hide_comment(comment_id: @comment.comment_id, hidden: true) },
           on_success: -> { @comment.update!(hidden_at: Time.current) })
end

#indexObject



8
9
10
11
12
# File 'app/controllers/instagram_connect/comments_controller.rb', line 8

def index
  per = InstagramConnect.configuration.default_per_page
  @page = [ params[:page].to_i, 1 ].max
  @comments = Comment.order(created_at: :desc).limit(per).offset((@page - 1) * per)
end

#replyObject



14
15
16
17
18
# File 'app/controllers/instagram_connect/comments_controller.rb', line 14

def reply
  moderate(notice: "Reply posted.",
           call: ->(client) { client.reply_comment(comment_id: @comment.comment_id, text: params[:text].to_s) },
           on_success: -> { @comment.update!(replied_at: Time.current) })
end

#unhideObject



26
27
28
29
30
# File 'app/controllers/instagram_connect/comments_controller.rb', line 26

def unhide
  moderate(notice: "Comment unhidden.",
           call: ->(client) { client.hide_comment(comment_id: @comment.comment_id, hidden: false) },
           on_success: -> { @comment.update!(hidden_at: nil) })
end