Chore: Fix Deserialisation Error in Jobs (#1683)

- Ignore Jobs on de-serialization error
- Show empty conversations in chat UI
Fixes: #1480
This commit is contained in:
Sojan Jose 2021-01-31 13:05:07 +05:30 committed by GitHub
parent 0ff81e3b53
commit 5d5e75ce9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 5 deletions

View file

@ -35,6 +35,12 @@
{{ this.$t(`${attachmentIconKey}.CONTENT`) }}
</span>
</p>
<p v-else class="conversation--message">
<i class="ion-android-alert"></i>
<span>
{{ this.$t(`CHAT_LIST.NO_MESSAGES`) }}
</span>
</p>
<div class="conversation--meta">
<span class="timestamp">
{{ dynamicTime(chat.timestamp) }}

View file

@ -79,6 +79,7 @@
},
"RECEIVED_VIA_EMAIL": "Received via email",
"VIEW_TWEET_IN_TWITTER": "View tweet in Twitter",
"REPLY_TO_TWEET": "Reply to this tweet"
"REPLY_TO_TWEET": "Reply to this tweet",
"NO_MESSAGES": "No Messages"
}
}

View file

@ -1,2 +1,6 @@
class ApplicationJob < ActiveJob::Base
# https://api.rubyonrails.org/v5.2.1/classes/ActiveJob/Exceptions/ClassMethods.html
discard_on ActiveJob::DeserializationError do |_job, error|
Rails.logger.error("Skipping job because of ActiveJob::DeserializationError (#{error.message})")
end
end

View file

@ -11,7 +11,9 @@ json.meta do
end
json.id conversation.display_id
if conversation.unread_incoming_messages.count.zero?
if conversation.messages.count.zero?
json.messages []
elsif conversation.unread_incoming_messages.count.zero?
json.messages [conversation.messages.includes([{ attachments: [{ file_attachment: [:blob] }] }]).last.try(:push_event_data)]
else
json.messages conversation.unread_messages.includes([:user, { attachments: [{ file_attachment: [:blob] }] }]).last(10).map(&:push_event_data)

View file

@ -14,19 +14,33 @@ RSpec.describe 'Conversations API', type: :request do
context 'when it is an authenticated user' do
let(:agent) { create(:user, account: account, role: :agent) }
let(:conversation) { create(:conversation, account: account) }
before do
conversation = create(:conversation, account: account)
create(:inbox_member, user: agent, inbox: conversation.inbox)
end
it 'returns all conversations' do
it 'returns all conversations with messages' do
message = create(:message, conversation: conversation, account: account)
get "/api/v1/accounts/#{account.id}/conversations",
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
expect(JSON.parse(response.body, symbolize_names: true)[:data][:meta][:all_count]).to eq(1)
body = JSON.parse(response.body, symbolize_names: true)
expect(body[:data][:meta][:all_count]).to eq(1)
expect(body[:data][:payload].first[:messages].first[:id]).to eq(message.id)
end
it 'returns conversations with empty messages array for conversations with out messages ' do
get "/api/v1/accounts/#{account.id}/conversations",
headers: agent.create_new_auth_token,
as: :json
expect(response).to have_http_status(:success)
body = JSON.parse(response.body, symbolize_names: true)
expect(body[:data][:meta][:all_count]).to eq(1)
expect(body[:data][:payload].first[:messages]).to eq([])
end
end
end