Class: InstagramConnect::Ingest::Handlers::Comments

Inherits:
Base
  • Object
show all
Defined in:
lib/instagram_connect/ingest/handlers/comments.rb

Overview

A comment on the account's own media. Also covers live_comments, which carry the same shape — the difference is that a private reply to a live comment is only valid while the broadcast is running.

Instance Attribute Summary

Attributes inherited from Base

#notification

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from InstagramConnect::Ingest::Handlers::Base

Class Method Details

.dedupe_key(event) ⇒ Object



8
9
10
# File 'lib/instagram_connect/ingest/handlers/comments.rb', line 8

def self.dedupe_key(event)
  event.dig("value", "id").presence
end

.requires_dedupe_key?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/instagram_connect/ingest/handlers/comments.rb', line 12

def self.requires_dedupe_key?
  true
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/instagram_connect/ingest/handlers/comments.rb', line 16

def call
  comment = InstagramConnect::Comment.record(
    account: ,
    comment_id: value["id"].to_s,
    media_id: value.dig("media", "id"),
    text: value["text"],
    from_username: value.dig("from", "username"),
    parent_id: value["parent_id"]
  )
  comment.update!(
    from_ig_id: value.dig("from", "id"),
    commented_at: commented_at,
    # A private reply to a live comment is only valid while the
    # broadcast is running, so which field delivered this decides
    # whether that action can be offered at all.
    is_live: envelope.field == "live_comments"
  )

  record_media(comment)
  notify(config.on_comment, comment)
  comment
end