Class: InstagramConnect::Message

Inherits:
ApplicationRecord show all
Defined in:
app/models/instagram_connect/message.rb

Overview

One message bubble in a DM thread (or a story reply mirrored as a DM).

Constant Summary collapse

DIRECTIONS =
%w[inbound outbound].freeze
STATUSES =
%w[received pending sending sent failed].freeze
KINDS =
%w[dm story_reply story_mention reaction postback share unsupported].freeze
SOURCES =
%w[inbound manual api operator_app].freeze
MEDIA_STATUSES =
%w[none pending downloadable attached unavailable].freeze
PREVIEW_LIMIT =
140

Instance Method Summary collapse

Instance Method Details

#attachment_delivered?Boolean

The attachment half of this send is done. Mirrors delivered_parts_count for the text half, so a resumed job never re-sends the photo.

Returns:

  • (Boolean)


47
48
49
# File 'app/models/instagram_connect/message.rb', line 47

def attachment_delivered?
  attachment_delivered_at.present?
end

#broadcast_refreshObject

Extension point: a host rendering this record live overrides it to re-broadcast current state after a callback-free write (update_all, which the send and media paths both use to stay atomic). A no-op here keeps the gem free of any Turbo dependency.



39
# File 'app/models/instagram_connect/message.rb', line 39

def broadcast_refresh; end

#deleted?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/instagram_connect/message.rb', line 51

def deleted?
  deleted_at.present?
end

#inbound?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/instagram_connect/message.rb', line 55

def inbound?
  direction == "inbound"
end

#occurred_atObject



41
42
43
# File 'app/models/instagram_connect/message.rb', line 41

def occurred_at
  sent_at || created_at
end

#outbound?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/instagram_connect/message.rb', line 59

def outbound?
  direction == "outbound"
end

#previewObject

Short summary used for the inbox row preview.



64
65
66
67
# File 'app/models/instagram_connect/message.rb', line 64

def preview
  return body.to_s.truncate(PREVIEW_LIMIT) if body.present?
  "[#{kind}]"
end