import { MessageParticipants , User } from '../types' ; export let defaultUser = { id : - 404 , username : 'User' , avatar : '' , } ; export function getParticipants ( ids , users , myUsername , lastPosterUsername ) { let participants = users . filter ( ( { id } ) => ids . includes ( id ) ) ; let participantsToShow ; while ( ids . length > participants . length || participants . length <= 0 ) { participants . push ( defaultUser ) ; } if ( participants . length > 1 ) { participantsToShow = participants . slice ( 0 , 2 ) ; if ( lastPosterUsername !== myUsername ) { let lastPosterIdx = participants . findIndex ( ( { username } ) => username === lastPosterUsername ) ; if ( lastPosterIdx !== - 1 ) { participantsToShow = [ participants [ lastPosterIdx ] ] ; participantsToShow . push ( participants [ lastPosterIdx === 0 ? 1 : 0 ] ) ; } } } else { participantsToShow = participants ; } return { participants , participantsToShow } ; }