fix: set default content type as text for message (#3060)

Fixes #2974
This commit is contained in:
Murtaza Bagwala
2021-10-06 00:10:29 +05:30
committed by GitHub
parent bd7aeba484
commit f874925f0e
5 changed files with 26 additions and 4 deletions

View File

@@ -5,7 +5,7 @@
# id :integer not null, primary key
# content :text
# content_attributes :json
# content_type :integer default("text")
# content_type :integer default("text"), not null
# external_source_ids :jsonb
# message_type :integer not null
# private :boolean default(FALSE)
@@ -32,10 +32,13 @@ class Message < ApplicationRecord
include MessageFilterHelpers
NUMBER_OF_PERMITTED_ATTACHMENTS = 15
before_validation :ensure_content_type
validates :account_id, presence: true
validates :inbox_id, presence: true
validates :conversation_id, presence: true
validates_with ContentAttributeValidator
validates :content_type, presence: true
# when you have a temperory id in your frontend and want it echoed back via action cable
attr_accessor :echo_id
@@ -133,6 +136,10 @@ class Message < ApplicationRecord
private
def ensure_content_type
self.content_type ||= Message.content_types[:text]
end
def execute_after_create_commit_callbacks
# rails issue with order of active record callbacks being executed https://github.com/rails/rails/issues/20911
reopen_conversation