about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-04-28 12:46:43 -0500
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:22 -0500
commit933d7afa873a0440c302ec767162fe726c46f0f0 (patch)
treec28a23e0a37f9792250890c8c04797faee8e54d4
parent8dbefa3966bedadfcf842fa955868573c657bc11 (diff)
Make the UI properly handle filters using `exclude_media` and `media_only` flags.
-rw-r--r--app/javascript/flavours/glitch/selectors/index.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/app/javascript/flavours/glitch/selectors/index.js b/app/javascript/flavours/glitch/selectors/index.js
index d1a88a2fc..2f8492942 100644
--- a/app/javascript/flavours/glitch/selectors/index.js
+++ b/app/javascript/flavours/glitch/selectors/index.js
@@ -41,10 +41,16 @@ export const getFilters = (state, { contextType }) => state.get('filters', Immut
 const escapeRegExp = string =>
   string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
 
-export const regexFromFilters = filters => {
-  if (filters.size === 0) {
-    return null;
-  }
+export const regexFromFilters = (status, filters) => {
+  if (filters.size === 0) { return null; }
+
+  let has_media = status.get('media_attachments').size > 0;
+
+  filters = filters.filter(filter => {
+    return (!has_media && filter.get('exclude_media')) || (has_media && filter.get('media_only'))
+  });
+
+  if (filters.size === 0) { return null; }
 
   return new RegExp(filters.map(filter => {
     let expr = escapeRegExp(filter.get('phrase'));
@@ -78,10 +84,10 @@ export const makeGetStatus = () => {
         return null;
       }
 
-      const regex  = (accountReblog || accountBase).get('id') !== me && regexFromFilters(filters);
       let filtered = false;
 
       if (statusReblog) {
+        const regex  = (accountReblog || accountBase).get('id') !== me && regexFromFilters(statusReblog, filters);
         filtered     = regex && regex.test(statusReblog.get('search_index'));
         statusReblog = statusReblog.set('account', accountReblog);
         statusReblog = statusReblog.set('filtered', filtered);
@@ -89,6 +95,7 @@ export const makeGetStatus = () => {
         statusReblog = null;
       }
 
+      const regex = (accountReblog || accountBase).get('id') !== me && regexFromFilters(statusBase, filters);
       filtered = filtered || regex && regex.test(statusBase.get('search_index'));
 
       return statusBase.withMutations(map => {