@ -11,7 +11,7 @@ import { showAlertForError } from './alerts';
import { showAlert } from './alerts' ;
import { defineMessages } from 'react-intl' ;
let cancelFetchComposeSuggestionsAccounts ;
let cancelFetchComposeSuggestionsAccounts , cancelFetchComposeSuggestionsTags ;
export const COMPOSE_CHANGE = 'COMPOSE_CHANGE' ;
export const COMPOSE_SUBMIT_REQUEST = 'COMPOSE_SUBMIT_REQUEST' ;
@ -325,10 +325,12 @@ const fetchComposeSuggestionsAccounts = throttle((dispatch, getState, token) =>
if ( cancelFetchComposeSuggestionsAccounts ) {
cancelFetchComposeSuggestionsAccounts ( ) ;
}
api ( getState ) . get ( '/api/v1/accounts/search' , {
cancelToken : new CancelToken ( cancel => {
cancelFetchComposeSuggestionsAccounts = cancel ;
} ) ,
params : {
q : token . slice ( 1 ) ,
resolve : false ,
@ -349,9 +351,30 @@ const fetchComposeSuggestionsEmojis = (dispatch, getState, token) => {
dispatch ( readyComposeSuggestionsEmojis ( token , results ) ) ;
} ;
const fetchComposeSuggestionsTags = ( dispatch , getState , token ) => {
dispatch ( updateSuggestionTags ( token ) ) ;
} ;
const fetchComposeSuggestionsTags = throttle ( ( dispatch , getState , token ) => {
if ( cancelFetchComposeSuggestionsTags ) {
cancelFetchComposeSuggestionsTags ( ) ;
}
api ( getState ) . get ( '/api/v2/search' , {
cancelToken : new CancelToken ( cancel => {
cancelFetchComposeSuggestionsTags = cancel ;
} ) ,
params : {
type : 'hashtags' ,
q : token . slice ( 1 ) ,
resolve : false ,
limit : 4 ,
} ,
} ) . then ( ( { data } ) => {
dispatch ( readyComposeSuggestionsTags ( token , data . hashtags ) ) ;
} ) . catch ( error => {
if ( ! isCancel ( error ) ) {
dispatch ( showAlertForError ( error ) ) ;
}
} ) ;
} , 200 , { leading : true , trailing : true } ) ;
export function fetchComposeSuggestions ( token ) {
return ( dispatch , getState ) => {
@ -385,6 +408,12 @@ export function readyComposeSuggestionsAccounts(token, accounts) {
} ;
} ;
export const readyComposeSuggestionsTags = ( token , tags ) => ( {
type : COMPOSE_SUGGESTIONS_READY ,
token ,
tags ,
} ) ;
export function selectComposeSuggestion ( position , token , suggestion , path ) {
return ( dispatch , getState ) => {
let completion , startPosition ;
@ -394,8 +423,8 @@ export function selectComposeSuggestion(position, token, suggestion, path) {
startPosition = position - 1 ;
dispatch ( useEmoji ( suggestion ) ) ;
} else if ( suggestion [ 0 ] === '#' ) {
completion = suggestion ;
} else if ( typeof suggestion === 'object' && suggestion . name ) {
completion = ` # ${ suggestion . name } ` ;
startPosition = position - 1 ;
} else {
completion = getState ( ) . getIn ( [ 'accounts' , suggestion , 'acct' ] ) ;