Open
Conversation
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
Copilot Autofix
AI 9 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces several improvements to the WhatsApp Poll Master:
Poll Data Persistence (Backend):
active_polls_storage.json.Enhanced Poll Results Display (Frontend):
Improved Poll Template Editing (Frontend):
Poll Option Reordering (Frontend):
These changes enhance data retention, provide deeper insights into poll results, and improve the usability and flexibility of poll creation and template management.