about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-05-27 00:53:48 +0200
committerGitHub <noreply@github.com>2017-05-27 00:53:48 +0200
commit0734e1fe33c5c7c837655ccd43161d8b08d68cf7 (patch)
tree563af005c1bf514f92c6a3d1ae00e805ca0555e2 /streaming
parent44cb08297c4fd992f3438b8cac99e1364edd4847 (diff)
Language filtering in streaming API (#3339)
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/streaming/index.js b/streaming/index.js
index 9e4674590..908e70d20 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -168,7 +168,7 @@ if (cluster.isMaster) {
         return;
       }
 
-      client.query('SELECT oauth_access_tokens.resource_owner_id, users.account_id FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id WHERE oauth_access_tokens.token = $1 LIMIT 1', [token], (err, result) => {
+      client.query('SELECT oauth_access_tokens.resource_owner_id, users.account_id, users.filtered_languages FROM oauth_access_tokens INNER JOIN users ON oauth_access_tokens.resource_owner_id = users.id WHERE oauth_access_tokens.token = $1 LIMIT 1', [token], (err, result) => {
         done();
 
         if (err) {
@@ -185,6 +185,7 @@ if (cluster.isMaster) {
         }
 
         req.accountId = result.rows[0].account_id;
+        req.filteredLanguages = result.rows[0].filtered_languages;
 
         next();
       });
@@ -248,6 +249,11 @@ if (cluster.isMaster) {
           const targetAccountIds = [unpackedPayload.account.id].concat(unpackedPayload.mentions.map(item => item.id)).concat(unpackedPayload.reblog ? [unpackedPayload.reblog.account.id] : []);
           const accountDomain    = unpackedPayload.account.acct.split('@')[1];
 
+          if (req.filteredLanguages.indexOf(unpackedPayload.language) !== -1) {
+            log.silly(req.requestId, `Message ${unpackedPayload.id} filtered by language (${unpackedPayload.language})`);
+            return;
+          }
+
           const queries = [
             client.query(`SELECT 1 FROM blocks WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 1)}) UNION SELECT 1 FROM mutes WHERE account_id = $1 AND target_account_id IN (${placeholders(targetAccountIds, 1)})`, [req.accountId].concat(targetAccountIds)),
           ];