diff --git a/app/actions/remote/command.ts b/app/actions/remote/command.ts index 2610e2f36..14675bdf8 100644 --- a/app/actions/remote/command.ts +++ b/app/actions/remote/command.ts @@ -205,6 +205,10 @@ export const fetchCommands = async (serverUrl: string, teamId: string) => { let client: Client; try { client = NetworkManager.getClient(serverUrl); + } catch (error) { + return {error: error as ClientErrorProps}; + } + try { return {commands: await client.getCommandsList(teamId)}; } catch (error) { return {error: error as ClientErrorProps}; @@ -215,6 +219,11 @@ export const fetchSuggestions = async (serverUrl: string, term: string, teamId: let client: Client; try { client = NetworkManager.getClient(serverUrl); + } catch (error) { + return {error: error as ClientErrorProps}; + } + + try { return {suggestions: await client.getCommandAutocompleteSuggestionsList(term, teamId, channelId, rootId)}; } catch (error) { return {error: error as ClientErrorProps}; diff --git a/app/components/autocomplete/slash_suggestion/app_command_parser/mentions.ts b/app/components/autocomplete/slash_suggestion/app_command_parser/mentions.ts index a1577c5ab..436779d41 100644 --- a/app/components/autocomplete/slash_suggestion/app_command_parser/mentions.ts +++ b/app/components/autocomplete/slash_suggestion/app_command_parser/mentions.ts @@ -73,10 +73,7 @@ export async function getChannelSuggestions(channels?: Channel[]): Promise(new AppCommandParser(serverUrl, intl, channelId, currentTeamId, rootId, theme)); const mounted = useRef(false); + const [noResultsTerm, setNoResultsTerm] = useState(null); const [dataSource, setDataSource] = useState(emptySuggestionList); const [commands, setCommands] = useState(); @@ -113,6 +114,7 @@ const SlashSuggestion = ({ updateSuggestions(emptySuggestionList); } else if (res.suggestions.length === 0) { updateSuggestions(emptySuggestionList); + setNoResultsTerm(term); } else { updateSuggestions(res.suggestions); } @@ -182,6 +184,7 @@ const SlashSuggestion = ({ useEffect(() => { if (value[0] !== '/') { runFetch.cancel(); + setNoResultsTerm(null); updateSuggestions(emptySuggestionList); return; } @@ -200,6 +203,11 @@ const SlashSuggestion = ({ if (value.indexOf(' ') === -1) { runFetch.cancel(); showBaseCommands(value); + setNoResultsTerm(null); + return; + } + + if (noResultsTerm && value.startsWith(noResultsTerm)) { return; } diff --git a/app/components/autocomplete/slash_suggestion/slash_suggestion_item.tsx b/app/components/autocomplete/slash_suggestion/slash_suggestion_item.tsx index bf0c35132..05b508cb5 100644 --- a/app/components/autocomplete/slash_suggestion/slash_suggestion_item.tsx +++ b/app/components/autocomplete/slash_suggestion/slash_suggestion_item.tsx @@ -122,7 +122,12 @@ const SlashSuggestionItem = ({ } else if (icon.startsWith('data:')) { if (icon.startsWith('data:image/svg+xml')) { // TODO: What base64 library should we use? Security implications on doing things like this? - const xml = ''; // base64.decode(icon.substring('data:image/svg+xml;base64,'.length)); + let xml = ''; + try { + xml = Buffer.from(icon.substring('data:image/svg+xml;base64,'.length), 'base64').toString(); + } catch { + // Do nothing + } image = (