diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ea8109dd0..4b7f04547 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -222,10 +222,9 @@ class UsersController < ApplicationController # modified by fq def user_newfeedback - @jours = @user.journals_for_messages.reverse - @jours.each do |jour| - jour.update_attribute(:status, false) - end + @jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') + @jours.update_all(:is_readed => true, :status => false) + @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 113adecc5..7c05c5af5 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 #####leave message fq class WordsController < ApplicationController @@ -25,7 +26,7 @@ class WordsController < ApplicationController # @message_count = a_message.count end end - @jours = @user.journals_for_messages.reverse + @jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse @limit = 10 @feedback_count = @jours.count @feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @@ -39,6 +40,38 @@ class WordsController < ApplicationController end end + def create_reply + # deny api. api useless + user_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1] + @user = User.find(user_id) + parent_id = params[:reference_id] + author_id = User.current.id + reply_user_id = params[:reference_user_id] + reply_id = params[:reference_message_id] # 暂时不实现 + content = params[:user_notes] + options = {:user_id => author_id, + :m_parent_id => parent_id, + :m_reply_id => reply_id, + :reply_id => reply_user_id, + :notes => content, + :is_readed => false} + @jfm = @user.add_jour(nil, nil, nil, options) + + respond_to do |format| + # format.html { + # if @jfm.errors.empty? + # flash.now.notice = l(:label_feedback_success) + # else + # flash.now.errors = l(:label_feedback_fail) + # end + # render 'test/index' + # } + format.js{ + @save_succ = true if @jfm.errors.empty? + } + end + end + def destroy if User.current.admin? || User.current.id == @user.id JournalsForMessage.delete_message(params[:object_id]) diff --git a/app/helpers/words_helper.rb b/app/helpers/words_helper.rb index 167c78e2c..a183f5a26 100644 --- a/app/helpers/words_helper.rb +++ b/app/helpers/words_helper.rb @@ -1,47 +1,56 @@ -########fq -module WordsHelper - def message_list(object, state, user) - unless state - if object.size > 5 - object = object[-5, 5] - end - end - object = object.reverse - remove_allowed = (User.current.id == object.first.user_id) - content = ''.html_safe - lis = object.each do |t_object| - s = ''.html_safe - s << link_to(t_object.indice, {}, :class => "journal-link") - s << avatar(t_object.user, :size => "16").to_s - s << link_to_user(t_object.user, :class => 'user') - time = time_tag(t_object.created_at) - s << l(:field_add, :time => time).html_safe - if !t_object.notes.blank? - s << link_to(image_tag('comment.png'), - {:controller => 'words', :action => 'new', :id => user, :journal_id => t_object}, - :remote => true, - :method => 'post', - :title => l(:button_quote)) - if remove_allowed || t_object.jour_id == User.current.id - url = {:controller => 'words', - :action => 'destroy', - :object_id => t_object, - :user_id => user} - s << ' ' - s << link_to(image_tag('delete.png'), url, - :remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) - end - end - #time = '更新于' + time_tag(t_object.created_at) + '之前' - - - # s << content_tag('div', time) - - content << content_tag('li', s, :class => "user-#{t_object.jour_id}") - content << textilizable(t_object.notes) - end - # content.present? ? content_tag('ul', content, :class => 'watchers') : content - content - end -end - \ No newline at end of file +########fq +module WordsHelper + def message_list(object, state, user) + unless state + if object.size > 5 + object = object[-5, 5] + end + end + object = object.reverse + remove_allowed = (User.current.id == object.first.user_id) + content = ''.html_safe + lis = object.each do |t_object| + s = ''.html_safe + s << link_to(t_object.indice, {}, :class => "journal-link") + s << avatar(t_object.user, :size => "16").to_s + s << link_to_user(t_object.user, :class => 'user') + time = time_tag(t_object.created_at) + s << l(:field_add, :time => time).html_safe + if !t_object.notes.blank? + s << link_to(image_tag('comment.png'), + {:controller => 'words', :action => 'new', :id => user, :journal_id => t_object}, + :remote => true, + :method => 'post', + :title => l(:button_quote)) + if remove_allowed || t_object.jour_id == User.current.id + url = {:controller => 'words', + :action => 'destroy', + :object_id => t_object, + :user_id => user} + s << ' ' + s << link_to(image_tag('delete.png'), url, + :remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete)) + end + end + #time = '更新于' + time_tag(t_object.created_at) + '之前' + + + # s << content_tag('div', time) + + content << content_tag('li', s, :class => "user-#{t_object.jour_id}") + content << textilizable(t_object.notes) + end + # content.present? ? content_tag('ul', content, :class => 'watchers') : content + content + end + + def fetch_user_leaveWord_reply leaveWordObj + if leaveWordObj.kind_of? JournalsForMessage + leaveWordObj.children + elsif leaveWordObj.kind_of? Fixnum + JournalsForMessage.find(leaveWordObj).children + else + [] + end + end +end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index bb03ad121..e00564f18 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -1,12 +1,33 @@ # fq +# 数据库字段中带有m前缀和is_readed是二次开发添加,之前的字段基本复用 +# 注意reply_id 是提到人的id,不是留言id, Base中叫做 at_user class JournalsForMessage < ActiveRecord::Base - attr_accessible :jour_id, :jour_type, :notes, :reply_id, :status, :user_id - attr_accessor :indice - validates :notes, presence: true + include Redmine::SafeAttributes + safe_attributes "jour_type", # 留言所属类型 + "jour_id", # 留言所属类型的id + "notes", # 留言内容 + "reply_id", # 留言被回复留言者的用户id(用户a回复了用户b,这是b的id,用以查询谁给b留言了) + "status", # 留言是否被查看(弃用) + "user_id", # 留言者的id + "m_parent_id", # 留言信息的父留言id + "is_readed", # 留言是否已读 + "m_reply_count", # 留言的回复数量 + "m_reply_id" # 回复某留言的留言id(a留言回复了b留言,这是b留言的id) + acts_as_tree :foreign_key => 'm_parent_id', :counter_cache => :m_reply_count, :order => "#{JournalsForMessage.table_name}.created_on ASC" + belongs_to :jour, :polymorphic => true belongs_to :user + belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id' + has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy + has_many :reply_for_journals, :dependent => :destroy + + validates :notes, presence: true after_create :act_as_activity #huang + after_create :reset_counters! + after_destroy :reset_counters! + + # default_scope { where('m_parent_id IS NULL') } def self.delete_message(message_id) self.delete_all "id = #{message_id}" @@ -24,9 +45,18 @@ class JournalsForMessage < ActiveRecord::Base def act_as_activity if self.jour_type == 'Principal' - unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id !=0 + unless self.user_id == self.jour.id && self.user_id != self.reply_id && self.reply_id != 0 self.acts << Activity.new(:user_id => self.user_id) end end end + + def reset_counters! + self.class.reset_counters!(self) + end + def self.reset_counters! journals_for_messages + # jfm_id = journals_for_messages.id.to_i + count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} ) + update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id]) + end end diff --git a/app/models/memo.rb b/app/models/memo.rb index 284d2ba1b..6841cc0fd 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -6,7 +6,7 @@ class Memo < ActiveRecord::Base validates_presence_of :author_id, :forum_id, :subject validates :content, presence: true validates_length_of :subject, maximum: 50 - validates_length_of :content, maximum: 3072 + #validates_length_of :content, maximum: 3072 validate :cannot_reply_to_locked_topic, :on => :create acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC" diff --git a/app/models/reply_for_journal.rb b/app/models/reply_for_journal.rb new file mode 100644 index 000000000..0ea6a04c7 --- /dev/null +++ b/app/models/reply_for_journal.rb @@ -0,0 +1,4 @@ +class ReplyForJournal < ActiveRecord::Base + # attr_accessible :title, :body + belongs_to :journals_for_messages +end diff --git a/app/models/user.rb b/app/models/user.rb index 6b1ee3d1b..3ee601b6a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -164,8 +164,14 @@ class User < Principal ###添加留言 fq - def add_jour(user, notes, reference_user_id = 0) - self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true) + def add_jour(user, notes, reference_user_id = 0, options = {}) + if options.count == 0 + self.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => reference_user_id, :status => true) + else + jfm = self.journals_for_messages.build(options) + jfm.save + jfm + end end # 判断用户是否加入了竞赛中 fq @@ -204,7 +210,12 @@ class User < Principal def count_new_jour count = self.new_jours.count end - + + #added by nie + def count_new_journal_reply + count = self.journal_reply.count + end + def set_mail_notification ##add byxianbo thread=Thread.new do diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 8db091278..ad4876de5 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -67,14 +67,10 @@ -
<%= link_to l(:label_user_watcher)+"("+User.watched_by(@user.id).count.to_s+")" ,:controller=>"users", :action=>"user_watchlist"%>   - <%= link_to l(:label_x_user_fans, :count => User.current.watcher_users(User.current.id).count)+"("+@user.watcher_users(@user.id).count.to_s+")", :controller=>"users", :action=>"user_fanslist" %>  - <%= link_to l(:label_requirement_focus)+"("+Bid.watched_by(@user).where('reward_type = ?', 1).count.to_s+")" ,:controller=>"users", :action=>"watch_bids"%>   - <% if @user.id == User.current.id %>

@@ -89,9 +85,7 @@