diff --git a/app/models/forum_message.rb b/app/models/forum_message.rb index 34f2107..5203888 100644 --- a/app/models/forum_message.rb +++ b/app/models/forum_message.rb @@ -12,32 +12,34 @@ class ForumMessage < ActiveRecord::Base after_create do - topic = ForumTopic.find(self.forum_topic_id) - - user_to_notify = [] - - ForumUser.where(:new_messages_notifications => true).each do |forum_user| + topic = self.topic + if topic.forum_messages.count > 1 - user_to_notify << forum_user + + user_to_notify = [] + + ForumUser.where(:new_messages_notifications => true).each do |forum_user| + + user_to_notify << forum_user + end + FollowedTopic.where(:forum_topic_id => self.forum_topic_id).each do |followed_topic| + user_to_notify << followed_topic.forum_user + end + + if self.forum_user.follow_participated_topics + folowed_topic = forum_user.followed_topics.find_or_initialize_by_forum_topic_id(topic.id) + folowed_topic.save + end + + + user_to_notify.uniq! + + user_to_notify.each do |forum_user| + ForumMails.message_notification(self, forum_user).deliver + end end - FollowedTopic.where(:forum_topic_id => self.forum_topic_id).each do |followed_topic| - user_to_notify << followed_topic.forum_user - end - - if self.forum_user.follow_participated_topics - folowed_topic = forum_user.followed_topics.find_or_initialize_by_forum_topic_id(topic.id) - folowed_topic.save - end - - - user_to_notify.uniq! - - user_to_notify.each do |forum_user| - ForumMails.message_notification(self, forum_user).deliver - end - end