From 40941b0f6dd0ba7b95939dcf0dab317790e45208 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 26 Oct 2019 19:13:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A7=81=E4=BF=A1=E7=9A=84?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=92=8C=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javascripts/private_messages.js.coffee | 3 + .../stylesheets/private_messages.css.scss | 3 + .../private_messages_controller.rb | 56 +++++++ app/controllers/users_controller.rb | 55 +------ app/helpers/private_messages_helper.rb | 2 + app/models/private_message.rb | 12 ++ app/models/user.rb | 58 +++++-- app/views/layouts/_logined_header.html.erb | 2 +- .../private_messages/_new_message.html.erb | 65 ++++++++ .../private_messages/_private_box.html.erb | 80 ++++++++++ .../_search_user_content.html.erb | 0 .../_user_new_feedbacks.html.erb | 24 +-- app/views/private_messages/index.html.erb | 3 + app/views/private_messages/index.js.erb | 1 + app/views/private_messages/new.js.erb | 2 + .../private_messages/search_users.js.erb | 1 + .../show.js.erb} | 2 +- app/views/users/_messages_count.html.erb | 3 + app/views/users/_user_message_left.html.erb | 6 +- app/views/users/user_messages.js.erb | 5 +- app/views/users/user_newfeedback.html.erb | 3 - config/routes.rb | 1 + .../20191026085118_create_private_messages.rb | 15 ++ db/schema.rb | 16 +- public/stylesheets/css/structure.css | 145 ++++++++++++++++++ 25 files changed, 478 insertions(+), 85 deletions(-) create mode 100644 app/assets/javascripts/private_messages.js.coffee create mode 100644 app/assets/stylesheets/private_messages.css.scss create mode 100644 app/controllers/private_messages_controller.rb create mode 100644 app/helpers/private_messages_helper.rb create mode 100644 app/models/private_message.rb create mode 100644 app/views/private_messages/_new_message.html.erb create mode 100644 app/views/private_messages/_private_box.html.erb create mode 100644 app/views/private_messages/_search_user_content.html.erb rename app/views/{users => private_messages}/_user_new_feedbacks.html.erb (55%) create mode 100644 app/views/private_messages/index.html.erb create mode 100644 app/views/private_messages/index.js.erb create mode 100644 app/views/private_messages/new.js.erb create mode 100644 app/views/private_messages/search_users.js.erb rename app/views/{users/user_newfeedback.js.erb => private_messages/show.js.erb} (55%) create mode 100644 app/views/users/_messages_count.html.erb delete mode 100644 app/views/users/user_newfeedback.html.erb create mode 100644 db/migrate/20191026085118_create_private_messages.rb diff --git a/app/assets/javascripts/private_messages.js.coffee b/app/assets/javascripts/private_messages.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/private_messages.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/private_messages.css.scss b/app/assets/stylesheets/private_messages.css.scss new file mode 100644 index 000000000..0d8ece9ec --- /dev/null +++ b/app/assets/stylesheets/private_messages.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the private_messages controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/private_messages_controller.rb b/app/controllers/private_messages_controller.rb new file mode 100644 index 000000000..b9477ab1a --- /dev/null +++ b/app/controllers/private_messages_controller.rb @@ -0,0 +1,56 @@ +class PrivateMessagesController < ApplicationController + before_filter :require_login + before_filter :set_user + before_filter :set_message, except: [:index] + + def index + #用户更新私信为全部已读 + jours = current_user.private_messages + @limit = 20 + @jours_count = jours.count + @jours_all_pages = Paginator.new @jours_count, @limit, params['page'] || 1 + @offset ||= @jours_all_pages.offset + @jours_alls = paginateHelper jours, @limit + render :layout=>'base_user_message' + end + + def new + + end + + def create + + end + + def show + @jour_messages = @user.journals_for_messages.where(m_parent_id: @jour.id) + + render :layout=>'base_user_message' + end + + def destroy + + end + + def get_recent_users + + end + + def search_users + all_search_users = User.where("LOWER(concat(lastname, ifnull(firstname, ''), login)) LIKE ?", "#{params[:user_name].strip.to_s.downcase}") + + end + + + private + + def set_user + @user = User.find_by_login(params[:user_id]) + end + + def set_message + @jour = JournalsForMessage.find_by_id(params[:id]) + end + + +end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 64adb7ed2..0d08a8e74 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -477,8 +477,8 @@ class UsersController < ApplicationController messages.each do |message_all| # 未读的消息存放在数组 mess = message_all.message - if (message_all.message_type != "SystemMessage" && !mess.nil? && (mess.viewed == 0 || !mess.viewed)) || (message_all.message_type == "SystemMessage"&& !mess.nil? && mess.created_at > onclick_time) - unless (message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1) + if mess.created_at > onclick_time + unless message_all.message_type == 'CourseMessage' && mess && mess.course && mess.course.is_delete == 1 @message_alls << mess end break if @message_alls.length == 10 @@ -516,7 +516,7 @@ class UsersController < ApplicationController else @message_alls = user_all_messages.where(message_type: %w(SystemMessage ContestMessage OrgMessage)) end - @unred_all_messages = @user.count_new_message + @unred_all_messages = @user.count_new_message(@msg_type) @message_alls = @message_alls.order("created_at desc") #点击进入tab后,全部更新为已读,全部页面除外 @@ -1639,55 +1639,6 @@ class UsersController < ApplicationController render :layout=>'base_users_new' end -# modified by fq - def user_newfeedback - unless User.current.logged? - redirect_to signin_url - return - end - - #用户更新私信为全部已读 - UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true) - - jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC') - - @state = false - @limit = 20 - @jours_count = jours.count - @jours_all_pages = Paginator.new @jours_count, @limit, params['page'] || 1 - @offset ||= @jours_all_pages.offset - @jours_alls = paginateHelper jours, @limit - render :layout=>'base_user_message' - - # 自己访问自己的页面才更新消息状态 - # UserFeedbackMessage.where("user_id =? and viewed =? and journals_for_message_type =? ", User.current.id, 0, "JournalsForMessage").update_all(:viewed => true) - # end - # @page = params[:page] ? params[:page].to_i + 1 : 0 - # if params[:type].present? - # case params[:type] - # when "public" - # jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 0').order('updated_on DESC') - # when "private" - # jours = @user.journals_for_messages.where('m_parent_id IS NULL and private = 1').order('updated_on DESC') - # else - # jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC') - # end - # else - # jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('updated_on DESC') - # end - # @unred_all_messages = @user.count_new_message - # @jour_count = jours.count - # @jour = jours.limit(10).offset(@page * 10) - # @type = params[:type] - # if User.current == @user - # @jour.update_all(:is_readed => true, :status => false) - # @jour.each do |journal| - # # fetch_user_leaveWord_reply(journal).update_all(:is_readed => true, :status => false) - # journal.delay.set_children_readed_delay - # end - # end - - end #给某人留言 def feedBackTo diff --git a/app/helpers/private_messages_helper.rb b/app/helpers/private_messages_helper.rb new file mode 100644 index 000000000..1c849b6ab --- /dev/null +++ b/app/helpers/private_messages_helper.rb @@ -0,0 +1,2 @@ +module PrivateMessagesHelper +end diff --git a/app/models/private_message.rb b/app/models/private_message.rb new file mode 100644 index 000000000..9b94fd27f --- /dev/null +++ b/app/models/private_message.rb @@ -0,0 +1,12 @@ +class PrivateMessage < ActiveRecord::Base + # 私信 + belongs_to :user + belongs_to :target, class_name: "User" + belongs_to :sender, class_name: "User" + belongs_to :receiver, class_name: "User" + + #status 0表示未读,1表示已读,2表示已删除 + scope :without_deleted, -> { where.not(status: 2) } + scope :only_unread, -> { where(status: 0) } + +end diff --git a/app/models/user.rb b/app/models/user.rb index 49669395a..566d85316 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -143,6 +143,8 @@ class User < Principal ##ended by xianbo #####fq + # 新版私信 + has_many :private_messages, dependent: :destroy has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy # has_many :bids, :foreign_key => 'author_id', :dependent => :destroy @@ -446,7 +448,7 @@ class User < Principal end # 新消息统计, - def count_new_message + def count_new_message(type) message_new_time = OnclickTime.where("user_id =?", User.current).first if message_new_time.nil? message_new_time = OnclickTime.new @@ -458,17 +460,49 @@ class User < Principal user = User.current onclick_time = user.onclick_time.onclick_time delete_courses = Course.where(:is_delete => 1).blank? ? "(-1)" : "(" + Course.where(:is_delete => 1).map(&:id).join(",") + ")" - course_count = CourseMessage.where("user_id =? and viewed =? and created_at >? and course_id not in #{delete_courses}", user.id, 0, onclick_time).count - contest_count = ContestMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count - forge_count = ForgeMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count - user_feedback_count = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count - user_memo_count = MemoMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count - system_messages_count = SystemMessage.where("created_at >?", onclick_time).count - at_count = AtMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time).count - org_count = OrgMessage.where("user_id=? and viewed =? and created_at >?", user.id,0, onclick_time).count - applied_count = AppliedMessage.where("user_id=? and viewed =? and created_at >?", user.id, 0, onclick_time).count - blog_message_count = BlogMessage.where("user_id=? and viewed=? and created_at >?", user.id, 0, onclick_time).count - message_new_time.update_attribute(:onclick_time, Time.now) + course_messages = CourseMessage.where("user_id =? and viewed =? and created_at >? and course_id not in #{delete_courses}", user.id, 0, onclick_time) + course_count = course_messages.size + + contest_messages = ContestMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time) + contest_count = contest_messages.count + + forge_messages = ForgeMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time) + forge_count = forge_messages.count + + user_feedbacks = UserFeedbackMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time) + user_feedback_count = user_feedbacks.count + + user_memos = MemoMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time) + user_memo_count = user_memos.count + + system_messages = SystemMessage.where("created_at >?", onclick_time) + system_messages_count = system_messages.count + + at_messages = AtMessage.where("user_id =? and viewed =? and created_at >?", user.id, 0, onclick_time) + at_count = at_messages.count + + org_messages = OrgMessage.where("user_id=? and viewed =? and created_at >?", user.id,0, onclick_time) + org_count = org_messages.count + + applied_messages = AppliedMessage.where("user_id=? and viewed =? and created_at >?", user.id, 0, onclick_time) + applied_count = applied_messages.count + + blog_messages = BlogMessage.where("user_id=? and viewed=? and created_at >?", user.id, 0, onclick_time) + blog_message_count = blog_messages.count + + if type != "all" + Rails.logger.info("######________type__________##########{type}") + message_new_time.update_attribute(:onclick_time, Time.now) + course_messages.update_all(:viewed => true) unless course_messages.nil? + forge_messages.update_all(:viewed => true) unless forge_messages.nil? + user_feedbacks.update_all(:viewed => true) unless user_feedbacks.nil? + user_memos.update_all(:viewed => true) unless user_memos.nil? + org_messages.update_all(:viewed => true) unless org_messages.nil? + at_messages.update_all(:viewed => true) unless at_messages.nil? + contest_messages.update_all(:viewed => true) unless contest_messages.nil? + blog_messages.update_all(:viewed => true) unless blog_messages.nil? + applied_messages.update_all(:viewed => true) unless applied_messages.nil? + end messages_count = course_count + contest_count + forge_count + user_feedback_count + user_memo_count + system_messages_count + at_count + org_count + applied_count + blog_message_count end diff --git a/app/views/layouts/_logined_header.html.erb b/app/views/layouts/_logined_header.html.erb index 2324e465a..414690d20 100644 --- a/app/views/layouts/_logined_header.html.erb +++ b/app/views/layouts/_logined_header.html.erb @@ -87,7 +87,7 @@