Add Conversation#to_message_id for class/id/date portion of conversation thread header

This commit is contained in:
Matt Jankowski 2024-09-16 13:08:23 -04:00
parent ca8e892c1a
commit c3f0ce4b31
3 changed files with 16 additions and 3 deletions

View file

@ -84,9 +84,9 @@ class NotificationMailer < ApplicationMailer
def thread_by_conversation(conversation) def thread_by_conversation(conversation)
return if conversation.nil? return if conversation.nil?
msg_id = "<conversation-#{conversation.id}.#{conversation.created_at.strftime('%Y-%m-%d')}@#{Rails.configuration.x.local_domain}>" message_id = "<#{conversation.to_message_id}@#{Rails.configuration.x.local_domain}>"
headers['In-Reply-To'] = msg_id headers['In-Reply-To'] = message_id
headers['References'] = msg_id headers['References'] = message_id
end end
end end

View file

@ -18,4 +18,8 @@ class Conversation < ApplicationRecord
def local? def local?
uri.nil? uri.nil?
end end
def to_message_id
"#{self.class.name.downcase}-#{id}.#{created_at.to_date}"
end
end end

View file

@ -12,4 +12,13 @@ RSpec.describe Conversation do
expect(Fabricate(:conversation, uri: 'abc').local?).to be false expect(Fabricate(:conversation, uri: 'abc').local?).to be false
end end
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 end