mirror of
https://github.com/chatwoot/chatwoot.git
synced 2026-06-04 21:02:35 +08:00
Twilio voice now uses first-class `Call` records as the source of truth for call state, instead of storing it on `conversation.additional_attributes` and `conversation.identifier`. Each call gets its own record, its own `voice_call` bubble matched by `call_sid`, and its own conference name keyed off `Call.id`. Multiple calls on the same conversation (for `lock_to_single_conversation` inboxes) now work correctly, and the conversation card stays in sync with the real latest message. Fixes https://linear.app/chatwoot/issue/PLA-121/lock-to-single-thread --------- Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com>
53 lines
1.3 KiB
Ruby
53 lines
1.3 KiB
Ruby
class MessageFinder
|
|
def initialize(conversation, params)
|
|
@conversation = conversation
|
|
@params = params
|
|
end
|
|
|
|
def perform
|
|
current_messages
|
|
end
|
|
|
|
private
|
|
|
|
def conversation_messages
|
|
@conversation.messages.includes(:attachments, :sender, sender: { avatar_attachment: [:blob] })
|
|
end
|
|
|
|
def messages
|
|
return conversation_messages if @params[:filter_internal_messages].blank?
|
|
|
|
conversation_messages.where.not('private = ? OR message_type = ?', true, 2)
|
|
end
|
|
|
|
def current_messages
|
|
if @params[:after].present? && @params[:before].present?
|
|
messages_between(@params[:after].to_i, @params[:before].to_i)
|
|
elsif @params[:before].present?
|
|
messages_before(@params[:before].to_i)
|
|
elsif @params[:after].present?
|
|
messages_after(@params[:after].to_i)
|
|
else
|
|
messages_latest
|
|
end
|
|
end
|
|
|
|
def messages_after(after_id)
|
|
messages.reorder('created_at asc').where('id > ?', after_id).limit(100)
|
|
end
|
|
|
|
def messages_before(before_id)
|
|
messages.reorder('created_at desc').where('id < ?', before_id).limit(20).reverse
|
|
end
|
|
|
|
def messages_between(after_id, before_id)
|
|
messages.reorder('created_at asc').where('id >= ? AND id < ?', after_id, before_id).limit(1000)
|
|
end
|
|
|
|
def messages_latest
|
|
messages.reorder('created_at desc').limit(20).reverse
|
|
end
|
|
end
|
|
|
|
MessageFinder.prepend_mod_with('MessageFinder')
|