[Glitch] Preserve hashtag casing in web UI hashtag history

Port f9b23a5d62 to glitch-soc
master
Thibaut Girka 6 years ago committed by ThibG
parent 24b6811a6e
commit 3b09597556
  1. 9
      app/javascript/flavours/glitch/actions/compose.js
  2. 2
      app/javascript/flavours/glitch/reducers/compose.js

@ -4,6 +4,7 @@ import { throttle } from 'lodash';
import { search as emojiSearch } from 'flavours/glitch/util/emoji/emoji_mart_search_light'; import { search as emojiSearch } from 'flavours/glitch/util/emoji/emoji_mart_search_light';
import { useEmoji } from './emojis'; import { useEmoji } from './emojis';
import { tagHistory } from 'flavours/glitch/util/settings'; import { tagHistory } from 'flavours/glitch/util/settings';
import { recoverHashtags } from 'flavours/glitch/util/hashtag';
import resizeImage from 'flavours/glitch/util/resize_image'; import resizeImage from 'flavours/glitch/util/resize_image';
import { updateTimeline } from './timelines'; import { updateTimeline } from './timelines';
@ -140,7 +141,7 @@ export function submitCompose() {
'Idempotency-Key': getState().getIn(['compose', 'idempotencyKey']), 'Idempotency-Key': getState().getIn(['compose', 'idempotencyKey']),
}, },
}).then(function (response) { }).then(function (response) {
dispatch(insertIntoTagHistory(response.data.tags)); dispatch(insertIntoTagHistory(response.data.tags, status));
dispatch(submitComposeSuccess({ ...response.data })); dispatch(submitComposeSuccess({ ...response.data }));
// If the response has no data then we can't do anything else. // If the response has no data then we can't do anything else.
@ -402,13 +403,13 @@ export function hydrateCompose() {
}; };
} }
function insertIntoTagHistory(tags) { function insertIntoTagHistory(recognizedTags, text) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const oldHistory = state.getIn(['compose', 'tagHistory']); const oldHistory = state.getIn(['compose', 'tagHistory']);
const me = state.getIn(['meta', 'me']); const me = state.getIn(['meta', 'me']);
const names = tags.map(({ name }) => name); const names = recoverHashtags(recognizedTags, text);
const intersectedOldHistory = oldHistory.filter(name => !names.includes(name)); const intersectedOldHistory = oldHistory.filter(name => names.findIndex(newName => newName.toLowerCase() === name.toLowerCase()) === -1);
names.push(...intersectedOldHistory.toJS()); names.push(...intersectedOldHistory.toJS());

@ -214,7 +214,7 @@ const updateSuggestionTags = (state, token) => {
return state.merge({ return state.merge({
suggestions: state.get('tagHistory') suggestions: state.get('tagHistory')
.filter(tag => tag.startsWith(prefix)) .filter(tag => tag.toLowerCase().startsWith(prefix.toLowerCase()))
.slice(0, 4) .slice(0, 4)
.map(tag => '#' + tag), .map(tag => '#' + tag),
suggestion_token: token, suggestion_token: token,

Loading…
Cancel
Save