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

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

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

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