Skip to content

Conversation

@harishoke
Copy link
Owner

This commit introduces several improvements to the WhatsApp Poll Master:

  1. Poll Data Persistence (Backend):

    • Active polls (questions, options, results, voters) are now persisted in active_polls_storage.json.
    • Poll data is loaded on server startup, ensuring poll status and results are retained across server restarts.
    • Data is saved upon new poll creation, poll updates (votes), and cleared on logout.
  2. Enhanced Poll Results Display (Frontend):

    • The poll results view now includes a "Voter Breakdown" section.
    • This section lists the JIDs of users who participated in a poll and the specific option(s) they selected.
  3. Improved Poll Template Editing (Frontend):

    • Added an "Edit Selected Template" feature.
    • You can now load an existing template, modify its question and/or options, and then:
      • Overwrite the original template (with confirmation).
      • Save the changes as a new template.
    • The workflow for saving templates has been updated to accommodate this, with clear prompts and confirmations.
  4. Poll Option Reordering (Frontend):

    • "Move Up" and "Move Down" buttons have been added to the poll option creation interface.
    • You can now reorder poll options before sending a poll or saving it as a template. The specified order will be reflected in the sent poll and saved templates.

These changes enhance data retention, provide deeper insights into poll results, and improve the usability and flexibility of poll creation and template management.

This commit introduces several improvements to the WhatsApp Poll Master:

1.  **Poll Data Persistence (Backend):**
    - Active polls (questions, options, results, voters) are now persisted in `active_polls_storage.json`.
    - Poll data is loaded on server startup, ensuring poll status and results are retained across server restarts.
    - Data is saved upon new poll creation, poll updates (votes), and cleared on logout.

2.  **Enhanced Poll Results Display (Frontend):**
    - The poll results view now includes a "Voter Breakdown" section.
    - This section lists the JIDs of users who participated in a poll and the specific option(s) they selected.

3.  **Improved Poll Template Editing (Frontend):**
    - Added an "Edit Selected Template" feature.
    - You can now load an existing template, modify its question and/or options, and then:
        - Overwrite the original template (with confirmation).
        - Save the changes as a new template.
    - The workflow for saving templates has been updated to accommodate this, with clear prompts and confirmations.

4.  **Poll Option Reordering (Frontend):**
    - "Move Up" and "Move Down" buttons have been added to the poll option creation interface.
    - You can now reorder poll options before sending a poll or saving it as a template. The specified order will be reflected in the sent poll and saved templates.

These changes enhance data retention, provide deeper insights into poll results, and improve the usability and flexibility of poll creation and template management.
Comment on lines +263 to +305
res.status(500).json({ success: false, message: 'Failed to send poll.', error: error.message });
}
});

app.get('/get-chats', async (req, res) => {
if (!clientReady || !sock) {
return res.status(400).json({ success: false, message: 'Baileys WhatsApp client is not ready.' });
}
try {
const simplifiedChats = [];
const groups = await sock.groupFetchAllParticipating();
for (const [jid, group] of Object.entries(groups)) {
if (group.subject) {
simplifiedChats.push({ id: jid, name: group.subject, isGroup: true });
}
}
// sock.contacts might not be populated immediately or in all Baileys versions by default
// It's better to rely on specific functions if needed, or ensure it's populated
// For now, this might return an empty list or be unreliable.
// Consider using sock.getContacts() or similar if you need a full contact list.

simplifiedChats.sort((a, b) => (a.name || "").localeCompare(b.name || ""));
res.json({ success: true, chats: simplifiedChats });
} catch (error) {
console.error('Error fetching chats:', error);
res.status(500).json({ success: false, message: 'Failed to fetch chats.', error: error.message });
}
});

app.post('/logout', async (req, res) => {
console.log('Received logout request.');
if (sock) {
try {
await sock.logout(); // This logs out from WhatsApp Web
console.log('Baileys client logged out successfully from WhatsApp.');
} catch (error) {
console.error('Error during Baileys logout from WhatsApp:', error);
} finally {
// Clean up local session state
if (sock && typeof sock.end === 'function') {
sock.end(new Error('Logged out by user request')); // Properly close the socket connection
}
const sessionPath = path.join(__dirname, 'baileys_auth_info');

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a file system access
, but is not rate-limited.
This route handler performs
a file system access
, but is not rate-limited.

Copilot Autofix

AI 7 months ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants