import { P2P_PROP } from '../../../enum/p2p'; import envConfig from '../../../env/env-config'; import { getNodeProfile } from '../../../env/nodeProfile'; import P2PMessage from '../../../pages/p2p/p2pMessage.page'; import { covertFileNameStringToFilePaths } from '../../../util/filePathUtil'; import * as stepVariableMap from '../../../util/stepVariableMap'; const p2pMessagePage = new P2PMessage(); export async function fillInReplyGeneralMessage(senderCompany, rowsHash) { const p2pGeneralMessage = getGeneralMessageFromRowsHash(senderCompany, rowsHash); await p2pMessagePage.getFormMessageTextArea().setInputField(p2pGeneralMessage.message); p2pGeneralMessage.fullPathAttachments.forEach(async (fullFiePath) => { await p2pMessagePage.getAttachFileUpload().uploadFile(fullFiePath); }); return p2pGeneralMessage; } export async function fillInCreateGeneralMessage(senderCompany, rowsHash) { const p2pGeneralMessage = getGeneralMessageFromRowsHash(senderCompany, rowsHash); await p2pMessagePage.getSubjectTextArea().setInputField(p2pGeneralMessage.subject); p2pGeneralMessage.recipients.displayNames.forEach(async (displayName) => { if (displayName !== p2pGeneralMessage.sender.displayName) { await p2pMessagePage.getRecipientsDropdown().clickElement(); await p2pMessagePage.getRecipientsOption(displayName).clickElement(); } }); await p2pMessagePage.getFormMessageTextArea().setInputField(p2pGeneralMessage.message); p2pGeneralMessage.fullPathAttachments.forEach(async (fullFilePath) => { await p2pMessagePage.getAttachFileUpload().uploadFile(fullFilePath); }); return p2pGeneralMessage; } export function getGeneralMessageFromRowsHash(senderCompany, rowHashes) { let subject = ''; let partyDisplayNames = []; let partyX500Names = []; const message = stepVariableMap.replaceWithSpecialKeyValue(rowHashes[P2P_PROP.MESSAGE]); if (rowHashes[P2P_PROP.SUBJECT]) { subject = stepVariableMap.replaceWithSpecialKeyValue(rowHashes[P2P_PROP.SUBJECT]); } if (rowHashes[P2P_PROP.TO]) { partyDisplayNames = rowHashes[P2P_PROP.TO].split(',').map(function (party) { const companyName = envConfig.defaultParty[party]; return getNodeProfile(companyName).displayName; }); partyX500Names = rowHashes[P2P_PROP.TO].split(',').map(function (party) { const companyName = envConfig.defaultParty[party]; return getNodeProfile(companyName).name; }); } const senderDisplayName = getNodeProfile(senderCompany).displayName; const senderX500Name = getNodeProfile(senderCompany).name; let fullPathAttachments = []; const fileNameAttachments = []; if (rowHashes[P2P_PROP.ATTACHMENT]) { fullPathAttachments = covertFileNameStringToFilePaths(rowHashes[P2P_PROP.ATTACHMENT]); } return { subject: subject, message: message, sender: { displayName: senderDisplayName, x500Name: senderX500Name }, recipients: { displayNames: partyDisplayNames, x500Names: partyX500Names }, fileNameAttachments: fileNameAttachments, fullPathAttachments: fullPathAttachments }; }