@ -18,6 +18,7 @@ import {
COMPOSE _SUGGESTIONS _CLEAR ,
COMPOSE _SUGGESTIONS _READY ,
COMPOSE _SUGGESTION _SELECT ,
COMPOSE _SUGGESTION _TAGS _UPDATE ,
COMPOSE _TAG _HISTORY _UPDATE ,
COMPOSE _ADVANCED _OPTIONS _CHANGE ,
COMPOSE _SENSITIVITY _CHANGE ,
@ -286,16 +287,36 @@ const expiresInFromExpiresAt = expires_at => {
return [ 300 , 1800 , 3600 , 21600 , 86400 , 259200 , 604800 ] . find ( expires _in => expires _in >= delta ) || 24 * 3600 ;
} ;
const normalizeSuggestions = ( state , { accounts , emojis , tags } ) => {
const mergeLocalHashtagResults = ( suggestions , prefix , tagHistory ) => {
prefix = prefix . toLowerCase ( ) ;
if ( suggestions . length < 4 ) {
const localTags = tagHistory . filter ( tag => tag . toLowerCase ( ) . startsWith ( prefix ) && ! suggestions . some ( suggestion => suggestion . type === 'hashtag' && suggestion . name . toLowerCase ( ) === tag . toLowerCase ( ) ) ) ;
return suggestions . concat ( localTags . slice ( 0 , 4 - suggestions . length ) . toJS ( ) . map ( tag => ( { type : 'hashtag' , name : tag } ) ) ) ;
} else {
return suggestions ;
}
} ;
const normalizeSuggestions = ( state , { accounts , emojis , tags , token } ) => {
if ( accounts ) {
return accounts . map ( item => ( { id : item . id , type : 'account' } ) ) ;
} else if ( emojis ) {
return emojis . map ( item => ( { ... item , type : 'emoji' } ) ) ;
} else {
return sortHashtagsByUse ( state , tags . map ( item => ( { ... item , type : 'hashtag' } ) ) ) ;
return mergeLocalHashtagResults ( sortHashtagsByUse ( state , tags . map ( item => ( { ... item , type : 'hashtag' } ) ) ) , token . slice ( 1 ) , state . get ( 'tagHistory' ) ) ;
}
} ;
const updateSuggestionTags = ( state , token ) => {
const prefix = token . slice ( 1 ) ;
const suggestions = state . get ( 'suggestions' ) . toJS ( ) ;
return state . merge ( {
suggestions : ImmutableList ( mergeLocalHashtagResults ( suggestions , prefix , state . get ( 'tagHistory' ) ) ) ,
suggestion _token : token ,
} ) ;
} ;
export default function compose ( state = initialState , action ) {
switch ( action . type ) {
case STORE _HYDRATE :
@ -429,6 +450,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 _TAGS _UPDATE :
return updateSuggestionTags ( state , action . token ) ;
case COMPOSE _TAG _HISTORY _UPDATE :
return state . set ( 'tagHistory' , fromJS ( action . tags ) ) ;
case TIMELINE _DELETE :