about summary refs log tree commit diff
path: root/src/lib/api
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-05-02 20:03:01 -0500
committerGitHub <noreply@github.com>2023-05-02 20:03:01 -0500
commitd225e857b5eadca46b75947e8ec3606129312de7 (patch)
treec6db12ca73cc18c6f837c510f8e5555e46aaff6b /src/lib/api
parentddb8ebb4125e8fff784ad9c162645ed869817d3a (diff)
downloadvoidsky-d225e857b5eadca46b75947e8ec3606129312de7.tar.zst
[APP-610] Make the language filter more lenient (#562)
* Tune the language filter to accept posts when a determination cant be made

* use j instead of i since i has been declared in upper scope

* use j instead of i since i has been declared in upper scope

* Pass the j man

---------

Co-authored-by: Ansh Nanda <anshnanda10@gmail.com>
Diffstat (limited to 'src/lib/api')
-rw-r--r--src/lib/api/feed-manip.ts18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/lib/api/feed-manip.ts b/src/lib/api/feed-manip.ts
index 2429419d8..341e8727d 100644
--- a/src/lib/api/feed-manip.ts
+++ b/src/lib/api/feed-manip.ts
@@ -203,11 +203,25 @@ export class FeedTuner {
             typeof item.post.record.text === 'string'
           ) {
             const res = lande(item.post.record.text)
-            const contentLangCode3 = res[0][0]
-            if (langsCode3.includes(contentLangCode3)) {
+
+            // require at least 70% confidence; otherwise, roll with it
+            if (res[0][1] <= 0.7) {
               hasPreferredLang = true
               break
             }
+
+            // if the user's languages are in the top 5 guesses, roll with it
+            for (let j = 0; j < 5 && j < res.length; j++) {
+              hasPreferredLang =
+                hasPreferredLang || langsCode3.includes(res[i][0])
+            }
+            if (hasPreferredLang) {
+              break
+            }
+          } else {
+            // no text? roll with it
+            hasPreferredLang = true
+            break
           }
         }
         if (!hasPreferredLang) {