Simplify desktop notifications, only include if mention/reply/pm/link

Include post excerpt in the notification
This commit is contained in:
Sam
2015-05-04 13:49:32 +10:00
parent 803feefd54
commit 4dfc1907ac
5 changed files with 87 additions and 159 deletions

View File

@@ -80,6 +80,10 @@ class PostAlerter
user.reload
end
NOTIFIABLE_TYPES = [:mentioned, :replied, :quoted, :posted, :linked, :private_message].map{ |t|
Notification.types[t]
}
def create_notification(user, type, post, opts={})
return if user.blank?
return if user.id == Discourse::SYSTEM_USER_ID
@@ -101,9 +105,9 @@ class PostAlerter
# Don't notify the same user about the same notification on the same post
existing_notification = user.notifications
.order("notifications.id desc")
.find_by(notification_type: type, topic_id: post.topic_id, post_number: post.post_number)
.find_by(topic_id: post.topic_id, post_number: post.post_number)
if existing_notification
if existing_notification && existing_notification.notification_type == type
return unless existing_notification.notification_type == Notification.types[:edited] &&
existing_notification.data_hash["display_username"] = opts[:display_username]
end
@@ -143,6 +147,23 @@ class PostAlerter
original_post_id: original_post.id,
original_username: original_username,
display_username: opts[:display_username] || post.user.username }.to_json)
if (!existing_notification) && NOTIFIABLE_TYPES.include?(type)
# we may have an invalid post somehow, dont blow up
post_url = original_post.url rescue nil
if post_url
MessageBus.publish("/notification-alert/#{user.id}", {
notification_type: type,
post_number: original_post.post_number,
topic_title: original_post.topic.title,
excerpt: original_post.excerpt(400, text_entities: true, strip_links: true),
username: original_username,
post_url: post_url
}, user_ids: [user.id])
end
end
end
# TODO: Move to post-analyzer?