diff --git a/app/controllers/concerns/deferred_posts.rb b/app/controllers/concerns/deferred_posts.rb index 1a8d81208..9450d72ad 100644 --- a/app/controllers/concerns/deferred_posts.rb +++ b/app/controllers/concerns/deferred_posts.rb @@ -9,7 +9,7 @@ module DeferredPosts def deferred_posts Post.includes(:uploader).where(id: deferred_post_ids.to_a).find_each.reduce({}) do |post_hash, p| - post_hash[p.id] = p.minimal_attributes + post_hash[p.id] = p.thumbnail_attributes post_hash end end diff --git a/app/decorators/posts_decorator.rb b/app/decorators/posts_decorator.rb index 44f48c4e1..9cfc0e2c0 100644 --- a/app/decorators/posts_decorator.rb +++ b/app/decorators/posts_decorator.rb @@ -23,28 +23,7 @@ class PostsDecorator < ApplicationDecorator end def data_attributes - post = object - attributes = { - "data-id" => post.id, - "data-has-sound" => post.has_tag?("video_with_sound", "flash_with_sound"), - "data-tags" => post.tag_string, - "data-rating" => post.rating, - "data-flags" => post.status_flags, - "data-uploader-id" => post.uploader_id, - "data-uploader" => post.uploader_name, - "data-file-ext" => post.file_ext, - "data-score" => post.score, - "data-fav-count" => post.fav_count, - "data-is-favorited" => post.favorited_by?(CurrentUser.user.id) - } - - if post.visible? - attributes["data-file-url"] = post.file_url - attributes["data-large-file-url"] = post.large_file_url - attributes["data-preview-file-url"] = post.preview_file_url - end - - attributes + { data: object.thumbnail_attributes } end def cropped_url(options) diff --git a/app/javascript/src/javascripts/blacklists.js b/app/javascript/src/javascripts/blacklists.js index 3805fff34..9ee875f1f 100644 --- a/app/javascript/src/javascripts/blacklists.js +++ b/app/javascript/src/javascripts/blacklists.js @@ -238,7 +238,7 @@ Blacklist.postMatch = function (post, entry) { uploader_id: $post.data("uploader-id"), user: $post.data("uploader").toString().toLowerCase(), flags: $post.data("flags"), - is_fav: $post.data("is-favorited"), + is_favorited: $post.data("is-favorited"), }; return Blacklist.postMatchObject(post_data, entry); }; @@ -272,7 +272,7 @@ Blacklist.postMatchObject = function (post, entry) { tags.push(`user:${post.user}`); tags.push(`height:${post.height}`); tags.push(`width:${post.width}`); - if (post.is_fav) + if (post.is_favorited) tags.push("fav:me"); $.each(post.flags.match(/\S+/g) || [], function (i, v) { tags.push(`status:${v}`); diff --git a/app/javascript/src/javascripts/thumbnails.js b/app/javascript/src/javascripts/thumbnails.js index e27a647bf..f9db1927e 100644 --- a/app/javascript/src/javascripts/thumbnails.js +++ b/app/javascript/src/javascripts/thumbnails.js @@ -4,61 +4,74 @@ import LS from "./local_storage"; const Thumbnails = {}; Thumbnails.initialize = function () { - const clearPlaceholder = function (post) { - if (post.hasClass("thumb-placeholder-link")) { - post.removeClass("thumb-placeholder-link"); - } else { - post.empty(); - } - }; const postsData = window.___deferred_posts || {}; const posts = $(".post-thumb.placeholder, .thumb-placeholder-link"); const DAB = LS.get("dab") === "1"; - $.each(posts, function (i, post) { - const p = $(post); - const postID = p.data("id"); + + for (const post of posts) { + const $post = $(post); + + // Placeholder is valid + const postID = $post.data("id"); if (!postID) { - clearPlaceholder(p); + clearPlaceholder($post); return; } + + // Data exists for this post const postData = postsData[postID]; if (!postData) { - clearPlaceholder(p); + clearPlaceholder($post); return; } - let blacklist_hit_count = 0; - $.each(Blacklist.entries, function (j, entry) { - if (Blacklist.postMatchObject(postData, entry)) { + + // Building the element + const thumbnail = $("