2015-08-11 16:52:04 +08:00
|
|
|
class ForgeMessage < ActiveRecord::Base
|
|
|
|
# 公共表中活动类型,命名规则:TYPE_OF_{类名}_ACT
|
|
|
|
TYPE_OF_ISSUE_ACT = "Issue"
|
|
|
|
TYPE_OF_MESSAGE_ACT = "Message"
|
|
|
|
TYPE_OF_ATTACHMENT_ACT = "Attachment"
|
|
|
|
TYPE_OF_DOCUMENT_ACT = "Document"
|
|
|
|
TYPE_OF_JOURNAL_ACT = "Journal"
|
|
|
|
TYPE_OF_WIKI_ACT = "Wiki"
|
|
|
|
TYPE_OF_NEWS_ACT = "News"
|
|
|
|
|
|
|
|
attr_accessible :forge_message_id, :forge_message_type, :project_id, :user_id, :viewed
|
|
|
|
|
|
|
|
belongs_to :forge_message ,:polymorphic => true
|
|
|
|
belongs_to :project
|
|
|
|
belongs_to :user
|
2015-08-24 17:51:19 +08:00
|
|
|
has_many :message_alls, :class_name => 'MessageAll',:as =>:message
|
2015-08-11 16:52:04 +08:00
|
|
|
validates :user_id,presence: true
|
|
|
|
validates :project_id,presence: true
|
|
|
|
validates :forge_message_id,presence: true
|
|
|
|
validates :forge_message_type, presence: true
|
2015-08-24 17:51:19 +08:00
|
|
|
after_save :add_user_activity
|
|
|
|
|
|
|
|
def add_user_activity
|
|
|
|
message_all = MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first
|
|
|
|
if message_all
|
|
|
|
message_all.save
|
|
|
|
else
|
|
|
|
message_all = MessageAll.new
|
|
|
|
message_all.message_id = self.id
|
|
|
|
message_all.message_type = self.class.to_s
|
|
|
|
message_all.container_type = "Project"
|
|
|
|
message_all.container_id = self.project_id
|
|
|
|
message_all.save
|
|
|
|
end
|
|
|
|
end
|
2015-08-11 16:52:04 +08:00
|
|
|
end
|