博客回复,加入消息提醒

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

File diff suppressed because it is too large Load Diff

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