From d18d1a9d81fced1e9f0d2dba6a6da5165710fe24 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 19 Aug 2015 17:29:05 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=95=99=E8=A8=80=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20=E5=85=AC=E5=85=B1=E8=AE=A8=E8=AE=BA=E5=8C=BA?= =?UTF-8?q?=E7=95=99=E8=A8=80=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- app/models/forum_message.rb | 11 ------ app/models/journals_for_message.rb | 30 ++++++++++++++- app/models/memo.rb | 5 ++- app/models/memo_message.rb | 11 ++++++ app/models/user.rb | 3 +- app/models/user_feedback_message.rb | 10 +++++ .../20150818091800_create_forum_messages.rb | 13 ------- ...819072608_create_user_feedback_messages.rb | 12 ++++++ .../20150819090720_create_memo_messages.rb | 13 +++++++ db/schema.rb | 38 ++++++++++++++++--- spec/factories/forum_messages.rb | 10 ----- spec/factories/memo_messages.rb | 10 +++++ spec/factories/user_feedback_messages.rb | 9 +++++ ...m_message_spec.rb => memo_message_spec.rb} | 2 +- spec/models/user_feedback_message_spec.rb | 5 +++ 16 files changed, 138 insertions(+), 46 deletions(-) delete mode 100644 app/models/forum_message.rb create mode 100644 app/models/memo_message.rb create mode 100644 app/models/user_feedback_message.rb delete mode 100644 db/migrate/20150818091800_create_forum_messages.rb create mode 100644 db/migrate/20150819072608_create_user_feedback_messages.rb create mode 100644 db/migrate/20150819090720_create_memo_messages.rb delete mode 100644 spec/factories/forum_messages.rb create mode 100644 spec/factories/memo_messages.rb create mode 100644 spec/factories/user_feedback_messages.rb rename spec/models/{forum_message_spec.rb => memo_message_spec.rb} (63%) create mode 100644 spec/models/user_feedback_message_spec.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bc3719685..f9ddc58f2 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/forum_message.rb b/app/models/forum_message.rb deleted file mode 100644 index c7b07e164..000000000 --- a/app/models/forum_message.rb +++ /dev/null @@ -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 diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index da19ba1f2..f1bdc7e7c 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -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 diff --git a/app/models/memo.rb b/app/models/memo.rb index e4dabf131..7225ae524 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -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 diff --git a/app/models/memo_message.rb b/app/models/memo_message.rb new file mode 100644 index 000000000..051fac317 --- /dev/null +++ b/app/models/memo_message.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 82ecdbd47..3a57d6217 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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" diff --git a/app/models/user_feedback_message.rb b/app/models/user_feedback_message.rb new file mode 100644 index 000000000..7cd8f5132 --- /dev/null +++ b/app/models/user_feedback_message.rb @@ -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 diff --git a/db/migrate/20150818091800_create_forum_messages.rb b/db/migrate/20150818091800_create_forum_messages.rb deleted file mode 100644 index 20ad1ca51..000000000 --- a/db/migrate/20150818091800_create_forum_messages.rb +++ /dev/null @@ -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 diff --git a/db/migrate/20150819072608_create_user_feedback_messages.rb b/db/migrate/20150819072608_create_user_feedback_messages.rb new file mode 100644 index 000000000..382841c47 --- /dev/null +++ b/db/migrate/20150819072608_create_user_feedback_messages.rb @@ -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 diff --git a/db/migrate/20150819090720_create_memo_messages.rb b/db/migrate/20150819090720_create_memo_messages.rb new file mode 100644 index 000000000..d050a7815 --- /dev/null +++ b/db/migrate/20150819090720_create_memo_messages.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5471381d7..fd1d98e58 100644 --- a/db/schema.rb +++ b/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,11 +575,11 @@ 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 + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "forums", :force => true do |t| @@ -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 diff --git a/spec/factories/forum_messages.rb b/spec/factories/forum_messages.rb deleted file mode 100644 index adb114d3c..000000000 --- a/spec/factories/forum_messages.rb +++ /dev/null @@ -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 diff --git a/spec/factories/memo_messages.rb b/spec/factories/memo_messages.rb new file mode 100644 index 000000000..edd5f7f54 --- /dev/null +++ b/spec/factories/memo_messages.rb @@ -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 diff --git a/spec/factories/user_feedback_messages.rb b/spec/factories/user_feedback_messages.rb new file mode 100644 index 000000000..945d6d8b3 --- /dev/null +++ b/spec/factories/user_feedback_messages.rb @@ -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 diff --git a/spec/models/forum_message_spec.rb b/spec/models/memo_message_spec.rb similarity index 63% rename from spec/models/forum_message_spec.rb rename to spec/models/memo_message_spec.rb index e0159c3ca..a7921fc84 100644 --- a/spec/models/forum_message_spec.rb +++ b/spec/models/memo_message_spec.rb @@ -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 diff --git a/spec/models/user_feedback_message_spec.rb b/spec/models/user_feedback_message_spec.rb new file mode 100644 index 000000000..4ea61c36a --- /dev/null +++ b/spec/models/user_feedback_message_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe UserFeedbackMessage, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end