]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Fix emoji autosuggestions
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 29 Jul 2019 13:04:49 +0000 (15:04 +0200)
committerThibG <thib@sitedethib.com>
Mon, 2 Sep 2019 08:57:44 +0000 (10:57 +0200)
Port 784c88e16d8e0f75c0d27e34f926569607e02044 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
app/javascript/flavours/glitch/actions/compose.js
app/javascript/flavours/glitch/components/autosuggest_input.js
app/javascript/flavours/glitch/components/autosuggest_textarea.js
app/javascript/flavours/glitch/reducers/compose.js

index 134b6985561b0a8a355899e62802c1f9e9e372fe..16b0e7ad2a6bc1014954959fec98010994b2f282 100644 (file)
@@ -444,13 +444,13 @@ export const readyComposeSuggestionsTags = (token, tags) => ({
 export function selectComposeSuggestion(position, token, suggestion, path) {
   return (dispatch, getState) => {
     let completion;
-    if (typeof suggestion === 'object' && suggestion.id) {
+    if (suggestion.type === 'emoji') {
       dispatch(useEmoji(suggestion));
       completion = suggestion.native || suggestion.colons;
-    } else if (typeof suggestion === 'object' && suggestion.name) {
+    } else if (suggestion.type === 'hashtag') {
       completion = `#${suggestion.name}`;
-    } else {
-      completion = '@' + getState().getIn(['accounts', suggestion, 'acct']);
+    } else if (suggestion.type === 'account') {
+      completion = '@' + getState().getIn(['accounts', suggestion.id, 'acct']);
     }
 
     dispatch({
index f931069a9bf607a2052b8ef9325a1aa10ee91480..1ef7ee2168b8913eca0085c9d282ccaa6ebd632e 100644 (file)
@@ -168,15 +168,15 @@ export default class AutosuggestInput extends ImmutablePureComponent {
     const { selectedSuggestion } = this.state;
     let inner, key;
 
-    if (typeof suggestion === 'object' && suggestion.shortcode) {
+    if (suggestion.type === 'emoji') {
       inner = <AutosuggestEmoji emoji={suggestion} />;
       key   = suggestion.id;
-    } else if (typeof suggestion === 'object' && suggestion.name) {
+    } else if (suggestion.type ==='hashtag') {
       inner = <AutosuggestHashtag tag={suggestion} />;
       key   = suggestion.name;
-    } else {
-      inner = <AutosuggestAccountContainer id={suggestion} />;
-      key   = suggestion;
+    } else if (suggestion.type === 'account') {
+      inner = <AutosuggestAccountContainer id={suggestion.id} />;
+      key   = suggestion.id;
     }
 
     return (
index c057f4a5b50ec52a1c4f5f3d6754dc973bea7823..ec2fbbe4bef8e907e829876e4699dba2d28553de 100644 (file)
@@ -174,15 +174,15 @@ export default class AutosuggestTextarea extends ImmutablePureComponent {
     const { selectedSuggestion } = this.state;
     let inner, key;
 
-    if (typeof suggestion === 'object' && suggestion.shortcode) {
+    if (suggestion.type === 'emoji') {
       inner = <AutosuggestEmoji emoji={suggestion} />;
       key   = suggestion.id;
-    } else if (typeof suggestion === 'object' && suggestion.name) {
+    } else if (suggestion.type === 'hashtag') {
       inner = <AutosuggestHashtag tag={suggestion} />;
       key   = suggestion.name;
-    } else {
-      inner = <AutosuggestAccountContainer id={suggestion} />;
-      key   = suggestion;
+    } else if (suggestion.type === 'account') {
+      inner = <AutosuggestAccountContainer id={suggestion.id} />;
+      key   = suggestion.id;
     }
 
     return (
index 3c769abe3b1cac46bd25dc169b4cda1819bee1a6..ee2905c9b1da95079e4a5db92a002276d9785ba2 100644 (file)
@@ -288,11 +288,11 @@ const expiresInFromExpiresAt = expires_at => {
 
 const normalizeSuggestions = (state, { accounts, emojis, tags }) => {
   if (accounts) {
-    return accounts.map(item => item.id);
+    return accounts.map(item => ({ id: item.id, type: 'account' }));
   } else if (emojis) {
-    return emojis;
+    return emojis.map(item => ({ ...item, type: 'emoji' }));
   } else {
-    return sortHashtagsByUse(state, tags);
+    return sortHashtagsByUse(state, tags.map(item => ({ ...item, type: 'hashtag' })));
   }
 };