2024-04-23 20:01:49 -05:00
|
|
|
const { proposals } = require('./contracts');
|
|
|
|
const read = require('./read');
|
2024-04-24 13:55:10 -05:00
|
|
|
const { sendNewProposalEvent } = require('./matrix');
|
2024-04-23 20:01:49 -05:00
|
|
|
|
|
|
|
// Subscribe to proposal events
|
|
|
|
const start = () => {
|
|
|
|
proposals.on('NewProposal', async (proposalIndex) => {
|
|
|
|
console.log('New Proposal, index', proposalIndex);
|
|
|
|
|
|
|
|
const proposal = await proposals.proposals(proposalIndex);
|
|
|
|
console.log('postId:', proposal.postId);
|
|
|
|
|
|
|
|
// Read post from database
|
|
|
|
const post = await read(proposal.postId);
|
|
|
|
console.log('post.content:', post.content);
|
|
|
|
|
|
|
|
// Send matrix room event
|
|
|
|
let message = `Proposal ${proposalIndex}\n\n${post.content}`;
|
|
|
|
if (post.embeddedData && Object.entries(post.embeddedData).length) {
|
|
|
|
message += `\n\n${JSON.stringify(post.embeddedData, null, 2)}`;
|
|
|
|
}
|
2024-04-24 13:55:10 -05:00
|
|
|
sendNewProposalEvent(proposalIndex, message);
|
2024-04-23 20:01:49 -05:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
start,
|
|
|
|
};
|