diff options
| author | Hunternif | 2022-10-02 03:25:10 +0100 |
|---|---|---|
| committer | Hunternif | 2022-10-02 04:18:27 +0100 |
| commit | a82fa8940158784285872434659b5cb7fb9b817a (patch) | |
| tree | d0ffd2795ef2bca181801f04aa83aef9f8031527 /client/js | |
| parent | bc44d8055bf3b65365bf5329a8a4ad4ac4177cfc (diff) | |
client,server: reverse search post by signature
Diffstat (limited to 'client/js')
| -rw-r--r-- | client/js/controls/post_readonly_sidebar_control.js | 29 | ||||
| -rw-r--r-- | client/js/models/post_list.js | 19 |
2 files changed, 48 insertions, 0 deletions
diff --git a/client/js/controls/post_readonly_sidebar_control.js b/client/js/controls/post_readonly_sidebar_control.js index 35cad8f..fc26281 100644 --- a/client/js/controls/post_readonly_sidebar_control.js +++ b/client/js/controls/post_readonly_sidebar_control.js @@ -50,6 +50,7 @@ class PostReadonlySidebarControl extends events.EventTarget { ); } this._loadSimilarPosts(); + this._loadLookalikePosts(); } get _scoreContainerNode() { @@ -100,6 +101,14 @@ class PostReadonlySidebarControl extends events.EventTarget { return this._hostNode.querySelector("nav.similar ul"); } + get _lookalikesNode() { + return this._hostNode.querySelector("nav.lookalikes"); + } + + get _lookalikesListNode() { + return this._hostNode.querySelector("nav.lookalikes ul"); + } + _installFitButtons() { this._fitBothButtonNode.addEventListener( "click", @@ -257,6 +266,26 @@ class PostReadonlySidebarControl extends events.EventTarget { } }); } + + _loadLookalikePosts() { + const limit = parseInt(settings.get().similarPosts); + const fields = ["id", "thumbnailUrl"]; + const threshold = 1; + return PostList.reverseSearch(this._post.id, limit, threshold, fields) + .then((response) => { + if (response.results.length === 0) { + this._lookalikesNode.style.display = "none"; + } + const listNode = this._lookalikesListNode; + for (let post of response.results) { + let poseNode = similarItemTemplate({ + id: post.id, + thumbnailUrl: post.thumbnailUrl, + }); + listNode.appendChild(poseNode); + } + }); + } } module.exports = PostReadonlySidebarControl; diff --git a/client/js/models/post_list.js b/client/js/models/post_list.js index 1220c7a..a94ff7f 100644 --- a/client/js/models/post_list.js +++ b/client/js/models/post_list.js @@ -54,6 +54,25 @@ class PostList extends AbstractList { }); } + static reverseSearch(id, limit, threshold, fields) { + return api + .get( + uri.formatApiLink("post", id, "reverse-search", { + limit: limit, + threshold: threshold, + fields: fields.join(","), + }) + ) + .then((response) => { + const results = response.similarPosts.map((sim) => sim.post); + return Promise.resolve( + Object.assign({}, response, { + results: PostList.fromResponse(results) + }) + ); + }); + } + static decorateSearchQuery(text) { const browsingSettings = settings.get(); const disabledSafety = []; |