DEV: Publish DiscourseEvent in TopicUser.track_visit for first visit (#27975)

This commit is contained in:
Mark VanLandingham
2024-07-19 10:53:12 -05:00
committed by GitHub
parent d13dab5b68
commit 6e77107ccc
2 changed files with 18 additions and 6 deletions

View File

@ -299,8 +299,10 @@ class TopicUser < ActiveRecord::Base
def track_visit!(topic_id, user_id)
now = DateTime.now
rows = TopicUser.where(topic_id: topic_id, user_id: user_id).update_all(last_visited_at: now)
change(user_id, topic_id, last_visited_at: now, first_visited_at: now) if rows == 0
if rows == 0
change(user_id, topic_id, last_visited_at: now, first_visited_at: now)
DiscourseEvent.trigger(:user_first_visit_to_topic, user_id: user_id, topic_id: topic_id)
end
end
# Update the last read and the last seen post count, but only if it doesn't exist.