From 7d9b5c7f95846b3187be478ed8bb1e68f3ded82c Mon Sep 17 00:00:00 2001 From: luciajanikova <19lucia99@gmail.com> Date: Mon, 28 Oct 2024 14:37:38 +0100 Subject: [PATCH] Small syntax updates --- app/models/govbox/message.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/models/govbox/message.rb b/app/models/govbox/message.rb index fa6985e3..1de014cb 100644 --- a/app/models/govbox/message.rb +++ b/app/models/govbox/message.rb @@ -32,7 +32,8 @@ def self.create_message_with_thread!(govbox_message) MessageThread.with_advisory_lock!(govbox_message.correlation_id, transaction: true, timeout_seconds: 10) do message = create_message(govbox_message) - message.thread = (message_draft.thread if message_draft) || govbox_message.box.message_threads.find_or_create_by_merge_uuid!( + message.thread = message_draft&.thread + message.thread ||= govbox_message.box.message_threads.find_or_create_by_merge_uuid!( box: govbox_message.box, merge_uuid: govbox_message.correlation_id, title: message.metadata.dig("delivery_notification", "consignment", "subject").presence || message.title, @@ -44,11 +45,13 @@ def self.create_message_with_thread!(govbox_message) create_message_objects(message, govbox_message.payload) add_upvs_related_tags(message, govbox_message) - migrate_tags_from_draft(message, message_draft) if message_draft - MessageObject.mark_message_objects_externally_signed(message.objects) + if message_draft + copy_tags_from_draft(message, message_draft) + message_draft.destroy + end - message_draft.destroy if message_draft + MessageObject.mark_message_objects_externally_signed(message.objects) end EventBus.publish(:message_thread_created, message.thread) if message.thread.previously_new_record? @@ -145,7 +148,7 @@ def self.add_upvs_related_tags(message, govbox_message) add_delivery_notification_tag(message) if message.can_be_authorized? end - def self.migrate_tags_from_draft(message, message_draft) + def self.copy_tags_from_draft(message, message_draft) message_draft.objects.map do |message_draft_object| message_object = message.objects.find_by(uuid: message_draft_object.uuid) message_draft_object.tags.signed.each { |tag| message_object.assign_tag(tag) }