Merge pull request #3265 from evazion/fix-3262
Fix #3262: Add time remaining for upload limits on user profiles
This commit is contained in:
@@ -549,6 +549,28 @@ class User < ApplicationRecord
|
|||||||
is_moderator? || flagger_id == id
|
is_moderator? || flagger_id == id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def upload_limit
|
||||||
|
@upload_limit ||= [max_upload_limit - used_upload_slots, 0].max
|
||||||
|
end
|
||||||
|
|
||||||
|
def used_upload_slots
|
||||||
|
uploaded_count = Post.for_user(id).where("created_at >= ?", 24.hours.ago).count
|
||||||
|
uploaded_comic_count = Post.for_user(id).tag_match("comic").where("created_at >= ?", 24.hours.ago).count / 3
|
||||||
|
uploaded_count - uploaded_comic_count
|
||||||
|
end
|
||||||
|
|
||||||
|
def max_upload_limit
|
||||||
|
[(base_upload_limit * upload_limit_multiplier).ceil, 10].max
|
||||||
|
end
|
||||||
|
|
||||||
|
def upload_limit_multiplier
|
||||||
|
(1 - (adjusted_deletion_confidence / 15.0))
|
||||||
|
end
|
||||||
|
|
||||||
|
def adjusted_deletion_confidence
|
||||||
|
[deletion_confidence(60), 15].min
|
||||||
|
end
|
||||||
|
|
||||||
def base_upload_limit
|
def base_upload_limit
|
||||||
if created_at >= 1.month.ago
|
if created_at >= 1.month.ago
|
||||||
10
|
10
|
||||||
@@ -563,23 +585,8 @@ class User < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def max_upload_limit
|
def next_free_upload_slot
|
||||||
dcon = [deletion_confidence(60), 15].min
|
(posts.where("created_at >= ?", 24.hours.ago).first.try(:created_at) || 24.hours.ago) + 24.hours
|
||||||
[(base_upload_limit * (1 - (dcon / 15.0))).ceil, 10].max
|
|
||||||
end
|
|
||||||
|
|
||||||
def upload_limit
|
|
||||||
@upload_limit ||= begin
|
|
||||||
uploaded_count = Post.for_user(id).where("created_at >= ?", 24.hours.ago).count
|
|
||||||
uploaded_comic_count = Post.for_user(id).tag_match("comic").where("created_at >= ?", 24.hours.ago).count / 3
|
|
||||||
limit = max_upload_limit - (uploaded_count - uploaded_comic_count)
|
|
||||||
|
|
||||||
if limit < 0
|
|
||||||
limit = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
limit
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def tag_query_limit
|
def tag_query_limit
|
||||||
@@ -935,4 +942,8 @@ class User < ApplicationRecord
|
|||||||
self.enable_sequential_post_navigation = true
|
self.enable_sequential_post_navigation = true
|
||||||
self.enable_auto_complete = true
|
self.enable_auto_complete = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def presenter
|
||||||
|
@presenter ||= UserPresenter.new(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -63,18 +63,20 @@ class UserPresenter
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload_limit
|
def upload_limit(template)
|
||||||
if user.can_upload_free?
|
if user.can_upload_free?
|
||||||
return "none"
|
return "none"
|
||||||
end
|
end
|
||||||
|
|
||||||
dcon = [user.deletion_confidence(60), 15].min
|
slots_tooltip = "Next free slot: #{template.time_ago_in_words(user.next_free_upload_slot)}"
|
||||||
multiplier = (1 - (dcon / 15.0))
|
limit_tooltip = <<-EOS.strip_heredoc
|
||||||
max_count = [(user.base_upload_limit * multiplier).ceil, 5].max
|
Base: #{user.base_upload_limit}
|
||||||
uploaded_count = Post.for_user(user.id).where("created_at >= ?", 24.hours.ago).count
|
Del. Rate: #{"%.2f" % user.adjusted_deletion_confidence}
|
||||||
uploaded_comic_count = Post.for_user(user.id).tag_match("comic").where("created_at >= ?", 24.hours.ago).count / 3
|
Multiplier: (1 - (#{"%.2f" % user.adjusted_deletion_confidence} / 15)) = #{user.upload_limit_multiplier}
|
||||||
|
Upload Limit: #{user.base_upload_limit} * #{"%.2f" % user.upload_limit_multiplier} = #{user.max_upload_limit}
|
||||||
|
EOS
|
||||||
|
|
||||||
"(#{user.base_upload_limit} * #{'%0.2f' % multiplier}) - #{uploaded_count - uploaded_comic_count} = #{user.upload_limit}"
|
%{<abbr title="#{slots_tooltip}">#{user.used_upload_slots}</abbr> / <abbr title="#{limit_tooltip}">#{user.max_upload_limit}</abbr>}.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def uploads
|
def uploads
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% unless CurrentUser.can_upload_free? %>
|
<% unless CurrentUser.can_upload_free? %>
|
||||||
<p>You can upload <strong><%= pluralize CurrentUser.upload_limit, "more post" %></strong> today.</p>
|
<p>Upload limit: <strong><%= CurrentUser.user.presenter.upload_limit(self) %></strong>.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= render "image" %>
|
<%= render "image" %>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>Upload Limit</th>
|
<th>Upload Limit</th>
|
||||||
<td><%= presenter.upload_limit %></td>
|
<td><%= presenter.upload_limit(self) %> (<%= link_to "help", wiki_pages_path(title: "about:upload_limits") %>)</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user