about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/reducers/compose.js
diff options
context:
space:
mode:
authorDavid Sterry <davesterry@gmail.com>2021-12-15 14:47:19 -0800
committerClaire <claire.github-309c@sitedethib.com>2021-12-16 16:48:42 +0100
commit50d62fe2e749a5ab2b2bed81d5a9449b5e733964 (patch)
treead8ebb28e0466649785afa167e8711debb271e68 /app/javascript/flavours/glitch/reducers/compose.js
parent59a5193280237777e7dcfc39664b534c92eac30a (diff)
[Glitch] ignore hashtag suggestions if they vary only in case
Port 2aafa5b4e7a83ce8195cd739f1233a52ab060db7 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours/glitch/reducers/compose.js')
-rw-r--r--app/javascript/flavours/glitch/reducers/compose.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js
index 1735cfb4d..d2ea0a924 100644
--- a/app/javascript/flavours/glitch/reducers/compose.js
+++ b/app/javascript/flavours/glitch/reducers/compose.js
@@ -22,6 +22,7 @@ import {
   COMPOSE_SUGGESTIONS_CLEAR,
   COMPOSE_SUGGESTIONS_READY,
   COMPOSE_SUGGESTION_SELECT,
+  COMPOSE_SUGGESTION_IGNORE,
   COMPOSE_SUGGESTION_TAGS_UPDATE,
   COMPOSE_TAG_HISTORY_UPDATE,
   COMPOSE_ADVANCED_OPTIONS_CHANGE,
@@ -252,6 +253,17 @@ const insertSuggestion = (state, position, token, completion, path) => {
   });
 };
 
+const ignoreSuggestion = (state, position, token, completion, path) => {
+  return state.withMutations(map => {
+    map.updateIn(path, oldText => `${oldText.slice(0, position + token.length)} ${oldText.slice(position + token.length)}`);
+    map.set('suggestion_token', null);
+    map.set('suggestions', ImmutableList());
+    map.set('focusDate', new Date());
+    map.set('caretPosition', position + token.length + 1);
+    map.set('idempotencyKey', uuid());
+  });
+};
+
 const sortHashtagsByUse = (state, tags) => {
   const personalHistory = state.get('tagHistory');
 
@@ -499,6 +511,8 @@ export default function compose(state = initialState, action) {
     return state.set('suggestions', ImmutableList(normalizeSuggestions(state, action))).set('suggestion_token', action.token);
   case COMPOSE_SUGGESTION_SELECT:
     return insertSuggestion(state, action.position, action.token, action.completion, action.path);
+  case COMPOSE_SUGGESTION_IGNORE:
+    return ignoreSuggestion(state, action.position, action.token, action.completion, action.path);
   case COMPOSE_SUGGESTION_TAGS_UPDATE:
     return updateSuggestionTags(state, action.token);
   case COMPOSE_TAG_HISTORY_UPDATE: