博客回复,加入消息提醒

This commit is contained in:
daiao 2017-01-11 17:32:04 +08:00
parent 3126d8312f
commit 13e17dd5a3
12 changed files with 2708 additions and 2572 deletions

View File

@ -173,12 +173,19 @@ class BlogCommentsController < ApplicationController
render_attachment_warning_if_needed(@blogComment)
#@article.save
# redirect_to user_blogs_path(:user_id=>params[:user_id])
# 给回复的人发消息
reply_user_id = params[:reply_id].nil? ? @blogComment.blog.author_id: params[:reply_id].to_i
# 回复的作业与评论的作者不是同一人则发送消息
if ( params[:reply_id].nil? && @blogComment.author.id != @blogComment.blog.author_id )|| (!params[:reply_id].nil? && @blogComment.author.id != params[:reply_id].to_i)
BlogMessage.create(:user_id => reply_user_id, :blog_id => params[:blog_id].to_i, :content => params[:blog_comment][:content],
:blog_commont_id => @blogComment.id, :blog_message_type => "BlogComment", :user_operator_id => @blogComment.author.id)
end
respond_to do |format|
format.html {
if params[:course_id] #如果呆了course_id过来了那么这是要跳到课程大纲去的
redirect_to syllabus_course_path(:id=>params[:course_id])
else
redirect_to user_blog_blog_comment_path(:user_id=>@article.author_id,:blog_id=>@article.blog_id,:id=>@article)
redirect_to user_blog_blog_comment_path(:user_id => @article.author_id, :blog_id => @article.blog_id, :id => @article)
end
}

View File

@ -388,6 +388,16 @@ class UsersController < ApplicationController
comment.reply_id = params[:reply_id]
comment.root_id = reply.root_id
reply.children << comment
# 评论后,给回复人发消息(如果是本人就不发)
if comment.author.id != BlogComment.find(comment.reply_id).author_id
BlogMessage.create(:user_id => BlogComment.find(comment.reply_id).author_id,
:blog_commont_id => comment.id,
:blog_id => comment.blog_id,
:blog_message_type => "BlogComment",
:content => comment.content,
:user_operator_id => comment.author.id
)
end
when 'OrgDocumentComment'
@root = reply.root
comment = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:reply_id])

View File

@ -0,0 +1,20 @@
class BlogMessage < ActiveRecord::Base
# attr_accessible :title, :body
attr_accessible :content, :blog_commont_id, :blog_message_type, :viewed, :user_id, :blog_id, :user_operator_id
belongs_to :blog_comment ,:polymorphic => true
belongs_to :user
has_many :message_alls, :class_name => 'MessageAll', :as => :message, :dependent => :destroy
validates :user_id, presence: true
validates :blog_id, presence: true
validates :blog_commont_id, presence: true
validates :blog_message_type, presence: true
after_create :add_user_message
def add_user_message
if MessageAll.where("message_type = '#{self.class.to_s}' and message_id = '#{self.id}'").first.nil?
self.message_alls << MessageAll.new(:user_id => self.user_id)
end
end
end

View File

@ -48,6 +48,7 @@ class Message < ActiveRecord::Base
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy
has_many :contest_messages, :class_name =>'ContestMessage', :as => :contest_message, :dependent => :destroy
has_many :at_messages, as: :at_message, dependent: :destroy
has_many :blog_messages, :class_name => 'BlogMessage', :as => :blog_message, :dependent => :destroy
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy

View File

@ -13,6 +13,8 @@
<%# 竞赛消息 %>
<%= render :partial => 'users/user_message_contest', :locals => {:ma => ma} %>
<%# 博客消息 %>
<%= render :partial => 'users/user_message_blog', :locals => {:ma => ma} %>
<!--公共贴吧-->
<%= render :partial => 'users/user_message_forum', :locals => {:ma => ma} %>

View File

@ -0,0 +1,22 @@
<% if ma.class == BlogMessage %>
<% if ma.blog_message_type == "BlogComment" %>
<ul class="homepageNewsList fl">
<div class="longMessageWidth">
<li class="homepageNewsPortrait fl">
<%= link_to image_tag(url_to_avatar(User.find(ma.user_operator_id)), :width => "30", :height => "30"), user_path(ma.user_operator_id), :target => '_blank' %>
</li>
<li class="homepageNewsPubType fl">
<%= link_to User.find(ma.user_operator_id).show_name, user_path(ma.user_operator_id), :class => "newsBlue homepageNewsPublisher", :target => '_blank' %>
<span class="homepageNewsType fl">回复了博客:</span>
</li>
<li class="messageInformationContents">
<% user_id = User.find(BlogComment.find(ma.blog_commont_id).blog.author_id) %>
<% blog_id = BlogComment.find(ma.blog_commont_id).root_id %>
<%= link_to message_content(ma.content), user_blog_blog_comment_path(:user_id => user_id, :blog_id => ma.blog_id, :id => blog_id),
:class => "#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}", :target => '_blank' %>
</li>
</div>
<li class="homepageNewsTime fr"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>
<% end %>

View File

@ -2,7 +2,7 @@ if($("#comment_reply_<%=@parent_id %> #reply_message_<%= @reply.id%>").length >
$("#comment_reply_<%=@parent_id %> #reply_message_<%= @reply.id%>").replaceWith("<%= escape_javascript(render :partial => 'users/reply_to_comment', :locals => {:reply => @reply}) %>");
$("#comment_reply_<%=@parent_id %> #reply_iconup_<%=@reply.id %>").show();
$(function(){
sd_create_editor_from_data(<%= @reply.id%>,null,"100%", "<%=@reply.class.to_s%>");
sd_create_editor_from_data(<%= @reply.id%>,null,"100%", "<%= @reply.class.to_s %>");
});
}else if($("#comment_reply_<%=@parent_id %> #reply_to_message_<%= @reply.id%>").length >0) {
$("#comment_reply_<%=@parent_id %> #reply_to_message_<%= @reply.id%>").replaceWith("<p id='reply_message_<%= @reply.id%>'></p>");

View File

@ -0,0 +1,15 @@
class CreateBlogMessages < ActiveRecord::Migration
def change
create_table :blog_messages do |t|
t.references :user
t.references :blog_commont
t.integer :blog_id
t.string :blog_message_type
t.boolean :viewed, :default => false
t.text :content
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
class AddUserOperaterIdToBlogMessage < ActiveRecord::Migration
def change
add_column :blog_messages, :user_operator_id, :integer
end
end

View File

@ -11,7 +11,8 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20161223083022) do
ActiveRecord::Schema.define(:version => 20170111030006) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
t.string "act_type", :null => false
@ -277,6 +278,18 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
add_index "blog_comments", ["root_id"], :name => "index_blog_comments_on_root_id"
create_table "blog_messages", :force => true do |t|
t.integer "user_id"
t.integer "blog_commont_id"
t.integer "blog_id"
t.string "blog_message_type"
t.boolean "viewed", :default => false
t.text "content"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_operator_id"
end
create_table "blogs", :force => true do |t|
t.string "name", :default => "", :null => false
t.text "description"
@ -337,14 +350,16 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
add_index "changeset_parents", ["parent_id"], :name => "changeset_parents_parent_ids"
create_table "changesets", :force => true do |t|
t.integer "repository_id", :null => false
t.string "revision", :null => false
t.integer "repository_id", :null => false
t.string "revision", :null => false
t.string "committer"
t.datetime "committed_on", :null => false
t.datetime "committed_on", :null => false
t.text "comments"
t.date "commit_date"
t.string "scmid"
t.integer "user_id"
t.integer "project_id"
t.integer "type", :default => 0
end
add_index "changesets", ["committed_on"], :name => "index_changesets_on_committed_on"
@ -566,6 +581,7 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
t.boolean "is_delete", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "judge_score"
end
add_index "contestant_works", ["project_id"], :name => "index_contestant_works_on_project_id"
@ -614,20 +630,6 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
t.integer "container_id", :default => 0
end
create_table "course_class_post", :id => false, :force => true do |t|
t.integer "班级id", :default => 0, :null => false
t.string "班级名"
t.integer "帖子id", :default => 0, :null => false
t.integer "主贴id"
t.string "帖子标题", :default => "", :null => false
t.text "帖子内容"
t.integer "帖子用户id"
t.integer "帖子回复数", :default => 0, :null => false
t.integer "最后回帖id"
t.datetime "发帖时间", :null => false
t.datetime "帖子更新时间", :null => false
end
create_table "course_contributor_scores", :force => true do |t|
t.integer "course_id"
t.integer "user_id"
@ -802,6 +804,21 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
add_index "delayed_jobs", ["priority", "run_at"], :name => "delayed_jobs_priority"
create_table "delayed_jobs_20161218", :id => false, :force => true do |t|
t.integer "id", :default => 0, :null => false
t.integer "priority", :default => 0, :null => false
t.integer "attempts", :default => 0, :null => false
t.text "handler", :null => false
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "discuss_demos", :force => true do |t|
t.string "title"
t.text "body"
@ -927,13 +944,11 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
t.integer "exercise_status"
t.integer "user_id"
t.integer "time"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "publish_time"
t.datetime "end_time"
t.integer "show_result"
t.integer "question_random", :default => 0
t.integer "choice_random", :default => 0
end
create_table "first_pages", :force => true do |t|
@ -1078,6 +1093,7 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
t.datetime "updated_at", :null => false
t.integer "no_anon_penalty", :default => 1
t.integer "appeal_penalty", :default => 0
t.integer "ta_mode", :default => 1
end
create_table "homework_detail_programings", :force => true do |t|
@ -1122,6 +1138,23 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
t.datetime "updated_at", :null => false
end
create_table "ii", :force => true do |t|
t.integer "project_id"
t.string "author_login"
t.string "rep_identifier"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "sonar_version", :default => 0
t.string "path"
t.string "branch"
t.string "language"
t.string "sonar_name"
end
create_table "innodb_monitor", :id => false, :force => true do |t|
t.integer "a"
end
create_table "invite_lists", :force => true do |t|
t.integer "project_id"
t.integer "user_id"
@ -2433,6 +2466,16 @@ ActiveRecord::Schema.define(:version => 20161223083022) do
t.datetime "updated_at", :null => false
end
create_table "wechat_logs", :force => true do |t|
t.string "openid", :null => false
t.text "request_raw"
t.text "response_raw"
t.text "session_raw"
t.datetime "created_at", :null => false
end
add_index "wechat_logs", ["openid"], :name => "index_wechat_logs_on_openid"
create_table "wiki_content_versions", :force => true do |t|
t.integer "wiki_content_id", :null => false
t.integer "page_id", :null => false

View File

@ -0,0 +1,6 @@
FactoryGirl.define do
factory :blog_message do
end
end

View File

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