parent
425e0dd89a
commit
d18d1a9d81
|
@ -146,7 +146,7 @@ class UsersController < ApplicationController
|
|||
@user_forge_messages = ForgeMessage.where("forge_message_type =? and user_id =?", "Forum", @user).order("created_at desc")
|
||||
@user_forge_messages_count = @user_forge_messages.count
|
||||
when 'forum'
|
||||
@user_forum_messages = ForumMessage.where("memo_message_type =? and user_id =?", "Forum", @user).order("created_at desc")
|
||||
@user_forum_messages = Memo.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc")
|
||||
@user_forum_messages_count = @user_forum_messages.count
|
||||
else
|
||||
render_404
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
class ForumMessage < ActiveRecord::Base
|
||||
attr_accessible :forum_id, :memo_message_id, :memo_message_type, :user_id, :viewed
|
||||
|
||||
belongs_to :memo
|
||||
belongs_to :user
|
||||
|
||||
validates :user_id,presence: true
|
||||
validates :forum_id,presence: true
|
||||
validates :memo_message_id,presence: true
|
||||
validates :memo_message_type, presence: true
|
||||
end
|
|
@ -60,9 +60,10 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
|
||||
# 消息关联
|
||||
has_many :course_messages, :class_name => 'CourseMessage',:as =>:course_message ,:dependent => :destroy
|
||||
has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:user_feeback_message, :dependent => :destroy
|
||||
|
||||
validates :notes, presence: true, if: :is_homework_jour?
|
||||
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message
|
||||
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message
|
||||
after_create :reset_counters!
|
||||
after_destroy :reset_counters!
|
||||
after_save :be_user_score
|
||||
|
@ -193,7 +194,32 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
def act_as_course_message
|
||||
if self.jour_type == 'StudentWorksScore'
|
||||
if self.user_id != self.jour.user_id
|
||||
self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.student_work.homework_common.course.id)
|
||||
self.course_messages << CourseMessage.new(:user_id => self.jour.user_id,:course_id => self.jour.student_work.homework_common.course.id, :viewed => false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 用户留言消息通知
|
||||
def act_as_user_feedback_message
|
||||
# 主留言
|
||||
receivers = []
|
||||
if self.reply_id == 0
|
||||
if self.author_id != self.jour_id # 过滤自己给自己的留言消息
|
||||
receivers << self.jour
|
||||
end
|
||||
else # 回帖
|
||||
# 添加吧主
|
||||
if self.author_id != self.forum.creator_id
|
||||
receivers << self.jour
|
||||
end
|
||||
# 添加发帖人
|
||||
if self.author_id != self.parent.author_id
|
||||
receivers << self.parent.author
|
||||
end
|
||||
end
|
||||
if self.jour_type == 'Principal'
|
||||
if self.user_id != self.jour.user_id
|
||||
self.user_feedback_messages << UserFeedbackMessage.new(:user_id => self.jour.user_id, :memo_message_id => self.id, :memo_message_type => "Forum", :viewed => false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,7 +17,8 @@ class Memo < ActiveRecord::Base
|
|||
has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj
|
||||
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
|
||||
# 消息
|
||||
has_many :forum_messages, dependent: :destroy
|
||||
has_many :memo_messages, :class_name =>'MemoMessage', :dependent => :destroy
|
||||
# end
|
||||
belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id'
|
||||
# acts_as_searchable :column => ['subject', 'content'],
|
||||
# #:include => { :forum => :p}
|
||||
|
@ -83,7 +84,7 @@ class Memo < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
receivers.each do |r|
|
||||
self.forum_messages << ForumMessage.new(:user_id => r.id, :forum_id => self.forum_id, :memo_message_id => self.id, :memo_message_type => "Forum", :viewed => false)
|
||||
self.memo_messages << MemoMessage.new(:user_id => r.id, :forum_id => self.forum_id, :memo_id => self.id, :memo_type => "Memo", :viewed => false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class MemoMessage < ActiveRecord::Base
|
||||
attr_accessible :forum_id, :memo_id, :memo_type, :user_id, :viewed
|
||||
|
||||
belongs_to :memo
|
||||
belongs_to :user
|
||||
|
||||
validates :user_id,presence: true
|
||||
validates :forum_id,presence: true
|
||||
validates :memo_id,presence: true
|
||||
validates :memo_type, presence: true
|
||||
end
|
|
@ -130,7 +130,8 @@ class User < Principal
|
|||
# 关联消息表
|
||||
has_many :forge_messages
|
||||
has_many :course_messages
|
||||
has_many :forum_messages
|
||||
has_many :memo_messages
|
||||
has_many :user_feedback_messages
|
||||
|
||||
# 虚拟转换
|
||||
has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1"
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class UserFeedbackMessage < ActiveRecord::Base
|
||||
attr_accessible :user_id, :user_message_id, :user_message_type, :viewed
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :journals_for_message
|
||||
|
||||
validates :user_id,presence: true
|
||||
validates :user_message_id,presence: true
|
||||
validates :user_message_type, presence: true
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
class CreateForumMessages < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :forum_messages do |t|
|
||||
t.integer :user_id
|
||||
t.integer :forum_id
|
||||
t.integer :memo_message_id
|
||||
t.string :memo_message_type
|
||||
t.integer :viewed
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
class CreateUserFeedbackMessages < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :user_feedback_messages do |t|
|
||||
t.integer :user_id
|
||||
t.integer :user_message_id
|
||||
t.string :user_message_type
|
||||
t.integer :viewed
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
class CreateMemoMessages < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :memo_messages do |t|
|
||||
t.integer :user_id
|
||||
t.integer :forum_id
|
||||
t.integer :memo_id
|
||||
t.string :memo_type
|
||||
t.integer :viewed
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
34
db/schema.rb
34
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20150818091800) do
|
||||
ActiveRecord::Schema.define(:version => 20150819090720) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -575,8 +575,8 @@ ActiveRecord::Schema.define(:version => 20150818091800) do
|
|||
create_table "forum_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "forum_id"
|
||||
t.integer "memo_message_id"
|
||||
t.string "memo_message_type"
|
||||
t.integer "memo_id"
|
||||
t.string "memo_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
|
@ -859,6 +859,16 @@ ActiveRecord::Schema.define(:version => 20150818091800) do
|
|||
add_index "members", ["user_id", "project_id", "course_id"], :name => "index_members_on_user_id_and_project_id", :unique => true
|
||||
add_index "members", ["user_id"], :name => "index_members_on_user_id"
|
||||
|
||||
create_table "memo_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "forum_id"
|
||||
t.integer "memo_id"
|
||||
t.string "memo_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "memos", :force => true do |t|
|
||||
t.integer "forum_id", :null => false
|
||||
t.integer "parent_id"
|
||||
|
@ -1424,6 +1434,15 @@ ActiveRecord::Schema.define(:version => 20150818091800) do
|
|||
t.string "description", :default => ""
|
||||
end
|
||||
|
||||
create_table "user_feedback_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "user_message_id"
|
||||
t.string "user_message_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "user_grades", :force => true do |t|
|
||||
t.integer "user_id", :null => false
|
||||
t.integer "project_id", :null => false
|
||||
|
@ -1489,6 +1508,15 @@ ActiveRecord::Schema.define(:version => 20150818091800) do
|
|||
add_index "user_statuses", ["grade"], :name => "index_user_statuses_on_grade"
|
||||
add_index "user_statuses", ["watchers_count"], :name => "index_user_statuses_on_watchers_count"
|
||||
|
||||
create_table "userfeedback_messages", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "user_message_id"
|
||||
t.string "user_message_type"
|
||||
t.integer "viewed"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "login", :default => "", :null => false
|
||||
t.string "hashed_password", :limit => 40, :default => "", :null => false
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
FactoryGirl.define do
|
||||
factory :forum_message do
|
||||
user_id 1
|
||||
forum_id 1
|
||||
memo_message_id 1
|
||||
memo_message_type "MyString"
|
||||
viewed 1
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
FactoryGirl.define do
|
||||
factory :memo_message do
|
||||
user_id 1
|
||||
forum_id 1
|
||||
memo_id 1
|
||||
memo_type "MyString"
|
||||
viewed 1
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
FactoryGirl.define do
|
||||
factory :user_feedback_message do
|
||||
user_id 1
|
||||
user_message_id 1
|
||||
user_message_type "MyString"
|
||||
viewed 1
|
||||
end
|
||||
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ForumMessage, :type => :model do
|
||||
RSpec.describe MemoMessage, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe UserFeedbackMessage, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue