FEATURE: Topic slow mode. (#10904)

Adds a new slow mode for topics that are heating up. Users will have to wait for a period of time before being able to post again.

We store this interval inside the topics table and track the last time a user posted using the last_posted_at datetime in the TopicUser relation.
This commit is contained in:
Roman Rizzi
2020-10-16 16:24:38 -03:00
committed by GitHub
parent 4669e60ce5
commit 21c53ed249
27 changed files with 460 additions and 6 deletions

View File

@ -40,7 +40,8 @@ class TopicViewSerializer < ApplicationSerializer
:pinned_globally,
:pinned_at,
:pinned_until,
:image_url
:image_url,
:slow_mode_seconds
)
attributes(
@ -72,7 +73,8 @@ class TopicViewSerializer < ApplicationSerializer
:queued_posts_count,
:show_read_indicator,
:requested_group_name,
:thumbnails
:thumbnails,
:user_last_posted_at
)
has_one :details, serializer: TopicViewDetailsSerializer, root: false, embed: :objects
@ -280,4 +282,12 @@ class TopicViewSerializer < ApplicationSerializer
extra_sizes = ThemeModifierHelper.new(request: scope.request).topic_thumbnail_sizes
object.topic.thumbnail_info(enqueue_if_missing: true, extra_sizes: extra_sizes)
end
def user_last_posted_at
object.topic_user.last_posted_at
end
def include_user_last_posted_at?
object.topic.slow_mode_seconds.to_i > 0
end
end