diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 4eb38ec340..7763fd99bc 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -84,9 +84,9 @@ class NotificationMailer < ApplicationMailer def thread_by_conversation(conversation) return if conversation.nil? - msg_id = "" + message_id = "<#{conversation.to_message_id}@#{Rails.configuration.x.local_domain}>" - headers['In-Reply-To'] = msg_id - headers['References'] = msg_id + headers['In-Reply-To'] = message_id + headers['References'] = message_id end end diff --git a/app/models/conversation.rb b/app/models/conversation.rb index a7fe148840..02ab01d3bc 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -18,4 +18,8 @@ class Conversation < ApplicationRecord def local? uri.nil? end + + def to_message_id + "#{self.class.name.downcase}-#{id}.#{created_at.to_date}" + end end diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index c1d6659aa7..22f3f85929 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -12,4 +12,13 @@ RSpec.describe Conversation do expect(Fabricate(:conversation, uri: 'abc').local?).to be false end end + + describe '#to_message_id' do + it 'converts the conversation details into a string ID' do + conversation = described_class.new(id: 123, created_at: DateTime.new(2024, 1, 1)) + + expect(conversation.to_message_id) + .to eq('conversation-123.2024-01-01') + end + end end