import { dateToNumber } from '../../../utils/date';
export function extractLinkData(cid, links) {
    const isFrom = links[0].from === cid;
    return {
        direction: (isFrom ? 'from' : 'to'),
        lastLinkCid: isFrom ? links[0].to : links[0].from,
        count: links.length,
        lastTimestamp: dateToNumber(links[0].timestamp),
        firstTimestamp: dateToNumber(links[links.length - 1].timestamp),
    };
}
export function changeSyncStatus(statusEntity, links) {
    const { direction, lastLinkCid, count, lastTimestamp, firstTimestamp } = extractLinkData(statusEntity.id, links);
    const unreadCount = (statusEntity.unreadCount || 0) + count;
    const timestampRead = count ? statusEntity.timestampRead : firstTimestamp;
    return Object.assign(Object.assign({}, statusEntity), { lastId: lastLinkCid, unreadCount, meta: { direction }, timestampUpdate: lastTimestamp, timestampRead });
}
//# sourceMappingURL=utils.js.map