From 476077ab846e046b48fc183625137af2e48ba158 Mon Sep 17 00:00:00 2001 From: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:23:43 +0530 Subject: [PATCH] fix: Update location component to avoid overflow, handle location title from Telegram payload (#9113) Co-authored-by: Pranav --- .../widgets/conversation/bubble/Location.vue | 90 ++++++++----------- .../telegram/incoming_message_service.rb | 11 +++ .../telegram/incoming_message_service_spec.rb | 24 +++++ 3 files changed, 71 insertions(+), 54 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/bubble/Location.vue b/app/javascript/dashboard/components/widgets/conversation/bubble/Location.vue index 3b8fcbaa0..e72233b88 100644 --- a/app/javascript/dashboard/components/widgets/conversation/bubble/Location.vue +++ b/app/javascript/dashboard/components/widgets/conversation/bubble/Location.vue @@ -1,17 +1,45 @@ + + - - - - diff --git a/app/services/telegram/incoming_message_service.rb b/app/services/telegram/incoming_message_service.rb index d18994a00..a36231634 100644 --- a/app/services/telegram/incoming_message_service.rb +++ b/app/services/telegram/incoming_message_service.rb @@ -130,6 +130,7 @@ class Telegram::IncomingMessageService @message.attachments.new( account_id: @message.account_id, file_type: :location, + fallback_title: location_fallback_title, coordinates_lat: location['latitude'], coordinates_long: location['longitude'] ) @@ -139,6 +140,16 @@ class Telegram::IncomingMessageService @file ||= visual_media_params || params[:message][:voice].presence || params[:message][:audio].presence || params[:message][:document].presence end + def location_fallback_title + return '' if venue.blank? + + venue[:title] || '' + end + + def venue + @venue ||= params.dig(:message, :venue).presence + end + def location @location ||= params.dig(:message, :location).presence end diff --git a/spec/services/telegram/incoming_message_service_spec.rb b/spec/services/telegram/incoming_message_service_spec.rb index 795202894..3cade6343 100644 --- a/spec/services/telegram/incoming_message_service_spec.rb +++ b/spec/services/telegram/incoming_message_service_spec.rb @@ -255,6 +255,30 @@ describe Telegram::IncomingMessageService do expect(Contact.all.first.name).to eq('Sojan Jose') expect(telegram_channel.inbox.messages.first.attachments.first.file_type).to eq('location') end + + it 'creates appropriate conversations, message and contacts if venue is present' do + params = { + 'update_id' => 2_342_342_343_242, + 'message' => { + 'location': { + 'latitude': 37.7893768, + 'longitude': -122.3895553 + }, + venue: { + title: 'San Francisco' + } + }.merge(message_params) + }.with_indifferent_access + described_class.new(inbox: telegram_channel.inbox, params: params).perform + expect(telegram_channel.inbox.conversations.count).not_to eq(0) + expect(Contact.all.first.name).to eq('Sojan Jose') + + attachment = telegram_channel.inbox.messages.first.attachments.first + expect(attachment.file_type).to eq('location') + expect(attachment.coordinates_lat).to eq(37.7893768) + expect(attachment.coordinates_long).to eq(-122.3895553) + expect(attachment.fallback_title).to eq('San Francisco') + end end context 'when valid callback_query params' do