diff options
Diffstat (limited to 'app/models/message.rb')
-rw-r--r-- | app/models/message.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/message.rb b/app/models/message.rb index 909c06a9e..038665cce 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -30,9 +30,15 @@ class Message < ActiveRecord::Base :description => :content, :url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id, :id => o.id}} + attr_protected :locked, :sticky validates_presence_of :subject, :content validates_length_of :subject, :maximum => 255 + def validate_on_create + # Can not reply to a locked topic + errors.add_to_base 'Topic is locked' if root.locked? + end + def after_create board.update_attribute(:last_message_id, self.id) board.increment! :messages_count @@ -43,6 +49,18 @@ class Message < ActiveRecord::Base end end + def after_destroy + # The following line is required so that the previous counter + # updates (due to children removal) are not overwritten + board.reload + board.decrement! :messages_count + board.decrement! :topics_count unless parent + end + + def sticky? + sticky == 1 + end + def project board.project end |