From fed4275403345d2bdaf6bda91e5a74bd0c1e2902 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 6 Nov 2017 12:15:26 +0000 Subject: [PATCH] Factor out code that gets message content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The nesting is getting pretty deep here. Let’s make it into its own method so it doesn’t get out of hand when we add more functionality to it. --- app/main/views/conversation.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/main/views/conversation.py b/app/main/views/conversation.py index abdd416de..3d1c7ccc4 100644 --- a/app/main/views/conversation.py +++ b/app/main/views/conversation.py @@ -120,12 +120,7 @@ def get_sms_thread(service_id, user_number): yield { 'inbound': is_inbound, 'content': SMSPreviewTemplate( - { - 'content': ( - notification['content'] if is_inbound else - notification['template']['content'] - ) - }, + {'content': get_sms_content(notification, is_inbound)}, notification.get('personalisation'), downgrade_non_gsm_characters=(not is_inbound), redact_missing_personalisation=redact_personalisation, @@ -134,3 +129,10 @@ def get_sms_thread(service_id, user_number): 'status': notification.get('status'), 'id': notification['id'], } + + +def get_sms_content(notification, is_inbound): + return ( + notification['content'] if is_inbound else + notification['template']['content'] + )