From 239d06b2185f04703ba09e24e3f54eb0138cca87 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 12 Dec 2016 14:20:25 -0500 Subject: [PATCH] add Likes Recieved to possible stats in summary email --- app/mailers/user_notifications.rb | 5 +++++ app/models/user.rb | 31 +++++++++++++++---------------- config/locales/server.en.yml | 1 + 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index be7956973b6..184b4e088cc 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -112,6 +112,11 @@ class UserNotifications < ActionMailer::Base value = user.unread_private_messages @counts << {label_key: 'user_notifications.digest.unread_messages', value: value, href: "#{Discourse.base_url}/my/messages"} if value > 0 + if @counts.size < 3 + value = user.unread_notifications_of_type(Notification.types[:liked]) + @counts << {label_key: 'user_notifications.digest.liked_received', value: value, href: "#{Discourse.base_url}/my/notifications"} if value > 0 + end + if @counts.size < 3 @counts << { label_key: 'user_notifications.digest.new_posts', diff --git a/app/models/user.rb b/app/models/user.rb index cd90c63c6c5..e363f5dd55a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -293,23 +293,22 @@ class User < ActiveRecord::Base super end - def unread_private_messages - @unread_pms ||= - begin - # perf critical, much more efficient than AR - sql = " - SELECT COUNT(*) FROM notifications n - LEFT JOIN topics t ON n.topic_id = t.id - WHERE - t.deleted_at IS NULL AND - n.notification_type = :type AND - n.user_id = :user_id AND - NOT read" + def unread_notifications_of_type(notification_type) + # perf critical, much more efficient than AR + sql = " + SELECT COUNT(*) FROM notifications n + LEFT JOIN topics t ON n.topic_id = t.id + WHERE + t.deleted_at IS NULL AND + n.notification_type = :type AND + n.user_id = :user_id AND + NOT read" - User.exec_sql(sql, user_id: id, - type: Notification.types[:private_message]) - .getvalue(0,0).to_i - end + User.exec_sql(sql, user_id: id, type: notification_type).getvalue(0,0).to_i + end + + def unread_private_messages + @unread_pms ||= unread_notifications_of_type(Notification.types[:private_message]) end def unread_notifications diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 766a77124dd..81580737a2f 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2448,6 +2448,7 @@ en: new_topics: "New Topics" unread_messages: "Unread Messages" unread_notifications: "Unread Notifications" + liked_received: "Likes Received" new_posts: "New Posts" new_users: "New Users" popular_topics: "Popular Topics"