mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-25 08:39:38 -05:00
e7f251c105
FIX: history revision can now properly be hidden FIX: PostRevision serializer is now entirely dynamic to properly handle hidden revisions FIX: default history modal to "side by side" view on mobile FIX: properly hiden which revision has been hidden UX: inline category/user/wiki/post_type changes with the revision details FEATURE: new '/posts/:post_id/revisions/latest' endpoint to retrieve latest revision UX: do not show the hide/show revision button on mobile (no room for them) UX: remove CSS transitions on the buttons in the history modal FIX: PostRevisor now handles all the changes that might create new revisions FIX: PostRevision.ensure_consistency! was wrong due to off by 1 mistake... refactored topic's callbacks for better readability extracted 'PostRevisionGuardian'
66 lines
1.8 KiB
Ruby
66 lines
1.8 KiB
Ruby
class PostAlertObserver < ActiveRecord::Observer
|
|
observe :post_action, :post_revision
|
|
|
|
def alerter
|
|
@alerter ||= PostAlerter.new
|
|
end
|
|
|
|
# Dispatch to an after_save_#{class_name} method
|
|
def after_save(model)
|
|
method_name = callback_for('after_save', model)
|
|
send(method_name, model) if respond_to?(method_name)
|
|
end
|
|
|
|
# Dispatch to an after_create_#{class_name} method
|
|
def after_create(model)
|
|
method_name = callback_for('after_create', model)
|
|
send(method_name, model) if respond_to?(method_name)
|
|
end
|
|
|
|
def after_save_post_action(post_action)
|
|
# We only care about deleting post actions for now
|
|
return if post_action.deleted_at.blank?
|
|
Notification.where(post_action_id: post_action.id).each(&:destroy)
|
|
end
|
|
|
|
def after_create_post_action(post_action)
|
|
# We only notify on likes for now
|
|
return unless post_action.is_like?
|
|
|
|
post = post_action.post
|
|
return if post_action.user.blank?
|
|
|
|
alerter.create_notification(
|
|
post.user,
|
|
Notification.types[:liked],
|
|
post,
|
|
display_username: post_action.user.username,
|
|
post_action_id: post_action.id
|
|
)
|
|
end
|
|
|
|
def after_create_post_revision(post_revision)
|
|
post = post_revision.post
|
|
|
|
return unless post
|
|
return if post_revision.user.blank?
|
|
return if post_revision.user_id == post.user_id
|
|
return if post.topic.private_message?
|
|
return if SiteSetting.disable_edit_notifications && post_revision.user_id == Discourse::SYSTEM_USER_ID
|
|
|
|
alerter.create_notification(
|
|
post.user,
|
|
Notification.types[:edited],
|
|
post,
|
|
display_username: post_revision.user.username,
|
|
acting_user_id: post_revision.try(:user_id)
|
|
)
|
|
end
|
|
|
|
protected
|
|
|
|
def callback_for(action, model)
|
|
"#{action}_#{model.class.name.underscore.gsub(/.+\//, '')}"
|
|
end
|
|
|
|
end
|