个人主页留言消息推送

This commit is contained in:
huang 2015-08-20 09:25:48 +08:00
parent c8399cdf58
commit 6b6f6e0b0d
7 changed files with 19 additions and 52 deletions

View File

@ -116,7 +116,7 @@ class UsersController < ApplicationController
@user_forge_messages = @user.forge_messages.reverse
@user_memo_messages = @user.memo_messages.reverse
@user_course_messages_count = @user_course_messages.count
@user_forge_messages_count = @user_forum_messages.count
@user_forge_messages_count = @user_forge_messages.count
@user_memo_messages_count = @user_memo_messages.count
when 'homework'
@user_course_messages = CourseMessage.where("course_message_type =? and user_id =?", "HomeworkCommon", @user).order("created_at desc")
@ -147,8 +147,8 @@ 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 = Memo.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc")
@user_forum_messages_count = @user_forum_messages.count
@user_memo_messages = Memo.where("memo_type =? and user_id =?", "Memo", @user).order("created_at desc")
@user_memo_messages_count = @user_memo_messages.count
else
render_404
return

View File

@ -207,19 +207,20 @@ class JournalsForMessage < ActiveRecord::Base
if self.user_id != self.jour_id # 过滤自己给自己的留言消息
receivers << self.jour
end
else # 回帖
# 添加吧主
if self.author_id != self.forum.creator_id
receivers << self.jour
else # 留言回复
# 添加留言回复人
if self.user_id != self.parent.user_id # 如果回帖人不是用户自己
receivers << User.find(self.reply_id)
end
# 添加发帖人
if self.author_id != self.parent.author_id
receivers << self.parent.author
if self.user_id != self.parent.jour_id
receivers << self.parent.jour
end
end
if self.jour_type == 'Principal'
if self.user_id != self.jour_id
self.user_feedback_messages << UserFeedbackMessage.new(:user_id => self.jour_id, :user_message_id => self.id, :user_message_type => "Forum", :viewed => false)
receivers.each do |r|
self.user_feedback_messages << UserFeedbackMessage.new(:user_id => r.id, :journals_for_message_id => self.id, :journals_for_message_type => "Principal", :viewed => false)
end
end
end
end

View File

@ -1,10 +0,0 @@
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

View File

@ -2,8 +2,8 @@ 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 :journals_for_message_id
t.string :journals_for_message_type
t.integer :viewed
t.timestamps

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20150819090720) do
ActiveRecord::Schema.define(:version => 20150820004659) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -572,16 +572,6 @@ ActiveRecord::Schema.define(:version => 20150819090720) do
t.datetime "updated_at", :null => false
end
create_table "forum_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 "forums", :force => true do |t|
t.string "name", :null => false
t.text "description"
@ -1436,11 +1426,11 @@ ActiveRecord::Schema.define(:version => 20150819090720) do
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 "journals_for_message_id"
t.string "journals_for_message_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 "user_grades", :force => true do |t|

View File

@ -1,9 +0,0 @@
FactoryGirl.define do
factory :user_feedback_message do
user_id 1
user_message_id 1
user_message_type "MyString"
viewed 1
end
end

View File

@ -1,5 +0,0 @@
require 'rails_helper'
RSpec.describe UserFeedbackMessage, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end