加入了issue的at消息提醒

This commit is contained in:
guange 2015-12-16 16:37:00 +08:00
parent 4ce9eb428e
commit c0de5d55de
4 changed files with 43 additions and 4 deletions

View File

@ -52,6 +52,7 @@ class Issue < ActiveRecord::Base
# ForgeMessage虚拟关联(多态) # ForgeMessage虚拟关联(多态)
has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy has_many :forge_messages, :class_name => 'ForgeMessage',:as =>:forge_message ,:dependent => :destroy
has_many :at_messages, class_name: 'AtMessage', as: :at_message ,:dependent => :destroy
acts_as_nested_set :scope => 'root_id', :dependent => :destroy acts_as_nested_set :scope => 'root_id', :dependent => :destroy
acts_as_attachable :before_add => :attachment_added, :after_remove => :attachment_removed acts_as_attachable :before_add => :attachment_added, :after_remove => :attachment_removed
@ -82,7 +83,7 @@ class Issue < ActiveRecord::Base
attr_reader :current_journal attr_reader :current_journal
# fq # fq
after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message after_create :act_as_activity,:be_user_score_new_issue,:act_as_forge_activity, :act_as_forge_message, :act_as_at_message
after_update :be_user_score after_update :be_user_score
after_destroy :down_user_score after_destroy :down_user_score
# after_create :be_user_score # after_create :be_user_score
@ -159,8 +160,9 @@ class Issue < ActiveRecord::Base
# at 功能添加消息提醒 # at 功能添加消息提醒
def act_as_at_message def act_as_at_message
users = self.description.scan /<span class="at" data-user-id="(\d+?)">/m users = self.description.scan /<span class="at" data-user-id="(\d+?)">/m
### xxx 在 xxx 中at了你 users && users.flatten.uniq.each do |uid|
self.at_messages << AtMessage.new(user_id: uid, sender_id: self.author_id)
end
end end
# 更新缺陷 # 更新缺陷

View File

@ -0,0 +1,21 @@
<% if AtMessage === ma %>
<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="homepageNewsPubType fl">
<span class="newsBlue homepageNewsPublisher"><%= ma.at_message.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"}",
: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? %>
<div class="fl"><strong>内容:</strong></div>
<div class="ml36"><%= ma.at_message.description.html_safe %></div>
<% end %>
</div>
<li class="homepageNewsTime fl"><%= time_tag(ma.created_at).html_safe %> </li>
</ul>
<% end %>

View File

@ -17,6 +17,8 @@
<%# 系统消息 %> <%# 系统消息 %>
<%= render :partial => 'users/user_message_system', :locals => {:ma => ma} %> <%= render :partial => 'users/user_message_system', :locals => {:ma => ma} %>
<%= render :partial => 'users/user_at_message', :locals => {:ma => ma} %>
<%# 课程消息 %> <%# 课程消息 %>
<%= render :partial => 'users/user_message_course', :locals => {:ma => ma} %> <%= render :partial => 'users/user_message_course', :locals => {:ma => ma} %>

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20151209085942) do ActiveRecord::Schema.define(:version => 20151216030610) do
create_table "activities", :force => true do |t| create_table "activities", :force => true do |t|
t.integer "act_id", :null => false t.integer "act_id", :null => false
@ -66,6 +66,20 @@ ActiveRecord::Schema.define(:version => 20151209085942) do
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
end end
create_table "at_messages", :force => true do |t|
t.integer "user_id"
t.integer "at_message_id"
t.string "at_message_type"
t.boolean "viewed"
t.string "container_type"
t.integer "container_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "sender_id"
end
add_index "at_messages", ["user_id"], :name => "index_at_messages_on_user_id"
create_table "attachments", :force => true do |t| create_table "attachments", :force => true do |t|
t.integer "container_id" t.integer "container_id"
t.string "container_type", :limit => 30 t.string "container_type", :limit => 30