消息通知
This commit is contained in:
parent
c0de5d55de
commit
fc63dfcb7b
|
@ -28,11 +28,17 @@ class AtController < ApplicationController
|
|||
find_message(id)
|
||||
when 'HomeworkCommon'
|
||||
find_homework(id)
|
||||
when 'Topic'
|
||||
find_topic(id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def find_topic(id)
|
||||
|
||||
end
|
||||
|
||||
def find_issue(id)
|
||||
#1. issues list persons
|
||||
#2. project persons
|
||||
|
@ -98,7 +104,7 @@ class AtController < ApplicationController
|
|||
def find_message(id)
|
||||
message = Message.find(id)
|
||||
at_persons = message.board.messages.map(&:author)
|
||||
|
||||
(at_persons || []) + (find_project(message.board.project_id)||[])
|
||||
end
|
||||
|
||||
#News
|
||||
|
|
|
@ -79,6 +79,11 @@ class BoardsController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
@project.boards.messages.each do |m|
|
||||
User.current.at_messages.unviewed('Message', m.id).each {|x| x.viewed!}
|
||||
end
|
||||
|
||||
elsif @course
|
||||
query_course_messages = @board.messages
|
||||
query_course_messages.each do |query_course_message|
|
||||
|
|
|
@ -19,6 +19,14 @@ class HomeworkCommonController < ApplicationController
|
|||
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
|
||||
@is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher))
|
||||
@is_new = params[:is_new]
|
||||
|
||||
#设置at已读
|
||||
@homeworks.each do |homework|
|
||||
homework.journals_for_messages.each do |j|
|
||||
User.current.at_messages.unviewed('JournalsForMessage', j.id).each {|x| x.viewed!}
|
||||
end
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html
|
||||
|
|
|
@ -115,6 +115,14 @@ class IssuesController < ApplicationController
|
|||
# 当前用户查看指派给他的缺陷消息,则设置消息为已读
|
||||
query = ForgeMessage.where("forge_message_type =? and user_id =? and forge_message_id =?", "Issue", User.current, @issue).first
|
||||
query.update_attribute(:viewed, true) unless query.nil?
|
||||
|
||||
# issue 新建的at消息
|
||||
User.current.at_messages.unviewed('Issue', @issue.id).each {|x| x.viewed!}
|
||||
# 回复的at消息
|
||||
@issue.journals.each do |j|
|
||||
User.current.at_messages.unviewed('Journal', j.id).each {|x| x.viewed!}
|
||||
end
|
||||
|
||||
# 缺陷状态更新
|
||||
query_journals = @issue.journals
|
||||
query_journals.each do |query_journal|
|
||||
|
|
|
@ -89,7 +89,8 @@ module UsersHelper
|
|||
forge_count = ForgeMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
user_memo_count = MemoMessage.where("user_id =? and viewed =?", user, 0).count
|
||||
messages_count = course_count + forge_count + user_feedback_count + user_memo_count
|
||||
at_count = user.at_messages.where(viewed: false).count
|
||||
messages_count = course_count + forge_count + user_feedback_count + user_memo_count + at_count
|
||||
end
|
||||
|
||||
def user_mail_notification_options(user)
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
class AtMessage < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
belongs_to :sender, class_name: "User", foreign_key: "sender_id"
|
||||
attr_accessible :at_message, :container, :viewed, :user_id, :sender_id
|
||||
belongs_to :at_message, polymorphic: true
|
||||
belongs_to :container, polymorphic: true
|
||||
|
||||
has_many :message_alls, :class_name => 'MessageAll',:as =>:message, :dependent => :destroy
|
||||
validates :user_id, :sender_id, :at_message_id, :at_message_type, presence: true
|
||||
|
||||
after_create :add_user_message
|
||||
|
||||
scope :unviewed, ->(type, id){
|
||||
where(at_message_type: type, at_message_id:id, viewed: false)
|
||||
}
|
||||
|
||||
def viewed!
|
||||
update_attribute :viewed, true
|
||||
end
|
||||
|
||||
def at_valid?
|
||||
return true if at_message_type == 'Issue'
|
||||
return true if 'Journal' == at_message_type
|
||||
return true if 'JournalsForMessage' == at_message_type
|
||||
return true if 'Message' == at_message_type
|
||||
false
|
||||
end
|
||||
|
||||
def add_user_message
|
||||
if MessageAll.where(message_type: self.class.name,message_id: self.id).empty?
|
||||
self.message_alls << MessageAll.new(:user_id => self.user_id)
|
||||
end
|
||||
end
|
||||
|
||||
def subject
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
"新建问题: " + at_message.subject
|
||||
when "Journal"
|
||||
"问题留言: " + at_message.journalized.subject
|
||||
when 'Message'
|
||||
if(at_message.topic?)
|
||||
"发布新帖: "
|
||||
else
|
||||
"回复帖子: "
|
||||
end + at_message.subject
|
||||
when 'JournalsForMessage'
|
||||
"作业留言: " + at_message.jour.description
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
end
|
||||
|
||||
def description
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
at_message.description
|
||||
when "Journal"
|
||||
at_message.notes
|
||||
when 'Message'
|
||||
at_message.content
|
||||
when "JournalsForMessage"
|
||||
at_message.notes
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
end
|
||||
|
||||
def author
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
at_message.author
|
||||
when "Journal"
|
||||
at_message.user
|
||||
when 'Message'
|
||||
at_message.author
|
||||
when 'JournalsForMessage'
|
||||
at_message.user
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
end
|
||||
|
||||
def url
|
||||
case at_message_type
|
||||
when "Issue"
|
||||
{controller: :issues, action: :show, id: at_message}
|
||||
when "Journal"
|
||||
{controller: :issues, action: :show, id: at_message.journalized}
|
||||
when 'Message'
|
||||
{controller: :boards, action: :show, project_id: at_message.board.project, id: at_message.board}
|
||||
when 'JournalsForMessage'
|
||||
{controller: :homework_common, action: :index, course: at_message.jour.course_id}
|
||||
else
|
||||
logger.error "error type: #{at_message_type}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -31,7 +31,9 @@ class Journal < ActiveRecord::Base
|
|||
has_many :forge_acts, :class_name => 'ForgeActivity',:as =>:forge_act ,:dependent => :destroy
|
||||
# 被ForgeMessage虚拟关联
|
||||
has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy
|
||||
# end
|
||||
|
||||
has_many :at_messages, as: :at_message, dependent: :destroy
|
||||
|
||||
attr_accessor :indice
|
||||
|
||||
acts_as_event :title =>Proc.new {|o| status = ((s = o.new_status) ? " (#{s})" : nil); "#{o.issue.tracker} ##{o.issue.project_index}#{status}: #{o.issue.subject}" },
|
||||
|
@ -50,7 +52,7 @@ class Journal < ActiveRecord::Base
|
|||
before_create :split_private_notes
|
||||
|
||||
# fq
|
||||
after_save :act_as_activity,:be_user_score,:act_as_forge_activity, :act_as_forge_message
|
||||
after_save :act_as_activity,:be_user_score,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message
|
||||
# end
|
||||
#after_destroy :down_user_score
|
||||
#before_save :be_user_score
|
||||
|
@ -184,6 +186,13 @@ class Journal < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def act_as_at_message
|
||||
users = self.notes.scan /<span class="at" data-user-id="(\d+?)">/m
|
||||
users && users.flatten.uniq.each do |uid|
|
||||
self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id)
|
||||
end
|
||||
end
|
||||
|
||||
# 更新用户分数 -by zjc
|
||||
def be_user_score
|
||||
#新建了缺陷留言且留言不为空,不为空白
|
||||
|
|
|
@ -64,8 +64,10 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
has_many :course_messages, :class_name => 'CourseMessage',:as =>:course_message ,:dependent => :destroy
|
||||
has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy
|
||||
|
||||
has_many :at_messages, as: :at_message, dependent: :destroy
|
||||
|
||||
validates :notes, presence: true, if: :is_homework_jour?
|
||||
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score
|
||||
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_at_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score
|
||||
after_create :reset_counters!
|
||||
after_destroy :reset_counters!
|
||||
after_save :be_user_score
|
||||
|
@ -240,6 +242,12 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def act_as_at_message
|
||||
users = self.notes.scan /<span class="at" data-user-id="(\d+?)">/m
|
||||
users && users.flatten.uniq.each do |uid|
|
||||
self.at_messages << AtMessage.new(user_id: uid, sender_id: self.user_id)
|
||||
end
|
||||
end
|
||||
# 用户留言消息通知
|
||||
def act_as_user_feedback_message
|
||||
# 主留言
|
||||
|
|
|
@ -38,7 +38,7 @@ class Message < ActiveRecord::Base
|
|||
# 课程/项目 消息
|
||||
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
|
||||
has_many :forge_messages, :class_name => 'ForgeMessage', :as => :forge_message, :dependent => :destroy
|
||||
#end
|
||||
has_many :at_messages, as: :at_message, dependent: :destroy
|
||||
|
||||
has_many :ActivityNotifies,:as => :activity, :dependent => :destroy
|
||||
|
||||
|
@ -74,7 +74,7 @@ class Message < ActiveRecord::Base
|
|||
after_update :update_messages_board
|
||||
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets
|
||||
|
||||
after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score
|
||||
after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score, :act_as_at_message
|
||||
#before_save :be_user_score
|
||||
|
||||
scope :visible, lambda {|*args|
|
||||
|
@ -96,6 +96,10 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
}
|
||||
|
||||
def topic?
|
||||
parent_id.nil?
|
||||
end
|
||||
|
||||
def visible?(user=User.current)
|
||||
if project
|
||||
!user.nil? && user.allowed_to?(:view_messages, project)
|
||||
|
@ -237,6 +241,13 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def act_as_at_message
|
||||
users = self.content.scan /<span class="at" data-user-id="(\d+?)">/m
|
||||
users && users.flatten.uniq.each do |uid|
|
||||
self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id)
|
||||
end
|
||||
end
|
||||
|
||||
#更新用户分数 -by zjc
|
||||
def be_user_score
|
||||
|
|
|
@ -161,6 +161,7 @@ class User < Principal
|
|||
has_many :user_feedback_messages
|
||||
has_one :onclick_time
|
||||
has_many :system_messages
|
||||
has_many :at_messages
|
||||
|
||||
# 虚拟转换
|
||||
has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%= content_for(:header_tags) do %>
|
||||
<%= import_ke(enable_at: false, prettify: false) %>
|
||||
<%= import_ke(enable_at: true, prettify: false) %>
|
||||
<%= javascript_include_tag "init_activity_KindEditor" %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<% end %>
|
||||
<div class="cl"></div>
|
||||
<div class=" talklist_box" >
|
||||
<div class="talk_new ml15 mb10" nhname="about_talk" style="display:none;">
|
||||
<div class="talk_new ml15 mb10" nhname="about_talk" data-at-id="<%= project.id %>" data-at-type="Project" style="display:none;">
|
||||
<ul>
|
||||
<%= render :partial => 'project_new_topic' %>
|
||||
</ul>
|
||||
|
@ -111,7 +111,7 @@
|
|||
<a href="javascript:void(0)" nhname="showbtn_reply" class="c_dblue fr f14" style="margin-right:10px;"><%= l(:button_reply) %></a>
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
<div class="talk_new ml15 mb10" nhname='about_talk' id="about_newtalk<%=topic.id%>" style="display: none;border-top: 1px dashed #d9d9d9;padding-top:5px;margin-left:0px;padding-left:15px;">
|
||||
<div class="talk_new ml15 mb10" nhname='about_talk' id="about_newtalk<%=topic.id%>" data-at-id="<%= topic.id %>" data-at-type="<%= topic.class.name %>" style="display: none;border-top: 1px dashed #d9d9d9;padding-top:5px;margin-left:0px;padding-left:15px;">
|
||||
<ul>
|
||||
<%= render :partial => 'edit',locals: {:topic => topic} %>
|
||||
</ul>
|
||||
|
@ -120,7 +120,7 @@
|
|||
<div class="talkWrapBox">
|
||||
<% reply = Message.new(:subject => "RE: #{topic.subject}")%>
|
||||
<% if !topic.locked? && authorize_for('messages', 'reply') %>
|
||||
<div class="talkWrapMsg" nhname="about_talk_reply" style="display: none;">
|
||||
<div class="talkWrapMsg" nhname="about_talk_reply" data-at-id="<%= topic.id %>" data-at-type="<%= topic.class.name %>" style="display: none;">
|
||||
<em class="talkWrapArrow"></em>
|
||||
<div class="cl"></div>
|
||||
<div class="talkConIpt ml15 mb10" style="margin-left:30px;" id="reply<%= topic.id %>">
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
window.attachEvent("onload", buildsubmenus)
|
||||
</script>
|
||||
<%= content_for(:header_tags) do %>
|
||||
<%= import_ke(enable_at: false, prettify: false) %>
|
||||
<%= import_ke(enable_at: true, prettify: false) %>
|
||||
<% end %>
|
||||
|
||||
|
||||
|
@ -102,6 +102,10 @@ function nh_init_board(params){
|
|||
if(/trident/.test(userAgent)){
|
||||
$("div.talk_new .ke-container").css({'margin-left':'0px'});
|
||||
}
|
||||
|
||||
if(typeof enableAt === 'function'){
|
||||
enableAt(this,params.about_talk.attr('data-at-id'), params.about_talk.attr('data-at-type'));
|
||||
}
|
||||
// var toolbar = $("div[class='ke-toolbar']",params.about_talk);
|
||||
// $(".ke-outline>.ke-toolbar-icon",toolbar).append('表情');
|
||||
// params.toolbar_container.append(toolbar);
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
<% if AtMessage === ma %>
|
||||
<% if AtMessage === ma && ma.at_valid? %>
|
||||
<ul class="homepageNewsList fl">
|
||||
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.at_message.author), :width => "30", :height => "30"),user_path(ma.at_message.author) %></a></li>
|
||||
<li class="homepageNewsPortrait fl"><a href="javascript:void(0);"><%=link_to image_tag(url_to_avatar(ma.author), :width => "30", :height => "30"),user_path(ma.author) %></a></li>
|
||||
<li class="homepageNewsPubType fl">
|
||||
<span class="newsBlue homepageNewsPublisher"><%= ma.at_message.author.login %></span><span class="homepageNewsType fl">提到了你:</span>
|
||||
<span class="newsBlue homepageNewsPublisher"><%= ma.author.login %></span><span class="homepageNewsType fl">提到了你:</span>
|
||||
</li>
|
||||
<li class="homepageNewsContent fl">
|
||||
<%= link_to ma.at_message.subject, {:controller => :issues, :action => 'show', :id => ma.at_message.id },
|
||||
:class =>"#{ma.viewed == 0 ? "newsBlack" : "newsGrey"}",
|
||||
<%= link_to ma.subject.html_safe, ma.url,
|
||||
:class =>"#{ma.viewed? ? "newsGrey" : "newsBlack"}",
|
||||
:onmouseover =>"message_titile_show($(this),event)",
|
||||
:onmouseout => "message_titile_hide($(this))" %></li>
|
||||
<div style="display: none" class="message_title_red system_message_style">
|
||||
<p><strong>标题:</strong><%= ma.at_message.subject %></p>
|
||||
<% unless ma.at_message.description.nil? %>
|
||||
<p><strong>标题:</strong><%= ma.subject %></p>
|
||||
<% unless ma.description.nil? %>
|
||||
<div class="fl"><strong>内容:</strong></div>
|
||||
<div class="ml36"><%= ma.at_message.description.html_safe %></div>
|
||||
<div class="ml36"><%= ma.description.html_safe %></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class CreateAtMessages < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :at_messages do |t|
|
||||
t.references :user
|
||||
t.integer :at_message_id
|
||||
t.string :at_message_type
|
||||
t.boolean :viewed, :default => false
|
||||
t.string :container_type
|
||||
t.integer :container_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :at_messages, :user_id
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddSenderToAtMessage < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :at_messages, :sender_id, :integer
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
# Read about factories at https://github.com/thoughtbot/factory_girl
|
||||
|
||||
FactoryGirl.define do
|
||||
factory :at_message do
|
||||
user nil
|
||||
at_message_id 1
|
||||
at_message_type "MyString"
|
||||
viewed false
|
||||
container_type "MyString"
|
||||
container_id 1
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AtMessage, :type => :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Reference in New Issue