import { MessageRecord } from '../../../../../../server-services/query-records/room-records';
import { ResponseMergerHandler } from '../../../cache-logic-interface';

export let customDialogueMessagesByIdQueryMerger: ResponseMergerHandler = function (
  cache,
  request,
  response: MessageRecord[]
) {
  if (response.length == 0) return;

  if (!cache.getCacheData('messages')[request.variables.peerId]) {
    cache.getCacheData('messages')[request.variables.peerId] = {};
  }

  response.forEach((msg) => {
    cache.getCacheData('messages')[request.variables.peerId][msg.id] = msg;
  });
};
