feat: Add support for after
param in messages API (#5861)
This commit is contained in:
parent
86e0ff76c5
commit
9b9c019de0
2 changed files with 14 additions and 1 deletions
|
@ -21,7 +21,9 @@ class MessageFinder
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_messages
|
def current_messages
|
||||||
if @params[:before].present?
|
if @params[:after].present?
|
||||||
|
messages.reorder('created_at asc').where('id >= ?', @params[:before].to_i).limit(20)
|
||||||
|
elsif @params[:before].present?
|
||||||
messages.reorder('created_at desc').where('id < ?', @params[:before].to_i).limit(20).reverse
|
messages.reorder('created_at desc').where('id < ?', @params[:before].to_i).limit(20).reverse
|
||||||
else
|
else
|
||||||
messages.reorder('created_at desc').limit(20).reverse
|
messages.reorder('created_at desc').limit(20).reverse
|
||||||
|
|
|
@ -47,5 +47,16 @@ describe ::MessageFinder do
|
||||||
expect(result.count).to be 6
|
expect(result.count).to be 6
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'with after attribute' do
|
||||||
|
let(:params) { { after: conversation.messages.first.id } }
|
||||||
|
|
||||||
|
it 'filter conversations by status' do
|
||||||
|
result = message_finder.perform
|
||||||
|
expect(result.count).to be 6
|
||||||
|
expect(result.first.id).to be conversation.messages.first.id
|
||||||
|
expect(result.last.message_type).to eq 'outgoing'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue