-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Enhance poll, auth, and template features #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
| 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
a file system access
This route handler performs
a file system access
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.
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.