import { getConversation , queryConversations } from '@proton/shared/lib/api/conversations' ; import { getMessage , queryMessageMetadata } from '@proton/shared/lib/api/messages' ; import isDeepEqual from '@proton/shared/lib/helpers/isDeepEqual' ; import { Api } from '@proton/shared/lib/interfaces' ; import { ELEMENTS_CACHE_REQUEST_SIZE , PAGE_SIZE } from '../../../constants' ; import { Element } from '../../../models/element' ; import { QueryParams , QueryResults , RetryData } from '../elementsTypes' ; export const getQueryElementsParameters = ( { page , params : { labelID , sort , search , filter } } ) : any => ( { Page : page , PageSize : PAGE_SIZE , Limit : ELEMENTS_CACHE_REQUEST_SIZE , LabelID : labelID , Sort : sort . sort , Desc : sort . desc ? 1 : 0 , Begin : search . begin , End : search . end , Keyword : search . keyword , To : search . to , From : search . from , Attachments : search . attachments , Unread : filter . Unread , AddressID : search . address , AutoWildcard : search . wildcard , } ) ; export const queryElements = async ( api , abortController , conversationMode , payload ) : Promise < QueryResults > => { abortController ?. abort ( ) ; const newAbortController = new AbortController ( ) ; const query = conversationMode ? queryConversations : queryMessageMetadata ; const result = await api ( { ... query ( payload as any ) , signal : newAbortController . signal } ) ; return { abortController : newAbortController , Total : result . Total , Elements : conversationMode ? result . Conversations : result . Messages , } ; } ; param payload param error export const newRetry = ( retry , payload , error ) => { const count = error && isDeepEqual ( payload , retry . payload ) ? retry . count + 1 : 1 ; return { payload , count , error } ; } ; export const queryElement = async ( api , conversationMode , elementID ) : Promise < Element > => { const query = conversationMode ? getConversation : getMessage ; const result = await api ( { ... query ( elementID ) , silence : true } ) ; return conversationMode ? result . Conversation : result . Message ; } ;