From 0c90af01b1eaac3dcf8e88d34cfa1cb9e0b185b4 Mon Sep 17 00:00:00 2001 From: padreug Date: Mon, 7 Jul 2025 01:52:39 +0200 Subject: [PATCH] feat: Enhance admin announcement functionality and introduce PWA installation prompt - Update sendAdminAnnouncement to support multiple configured admin pubkeys and improve console output for clarity. - Add new script send_posts_from_configured_admins.js to send posts from multiple admins for testing purposes. - Implement PWAInstallPrompt component to guide users in installing the app, including handling installation status and browser compatibility. - Integrate PWAInstallPrompt into Home.vue for improved user experience. --- send_admin_note.js | 21 +- send_posts_from_configured_admins.js | 100 +++++++++ src/components/pwa/PWAInstallPrompt.vue | 283 ++++++++++++++++++++++++ src/pages/Home.vue | 2 + 4 files changed, 399 insertions(+), 7 deletions(-) create mode 100644 send_posts_from_configured_admins.js create mode 100644 src/components/pwa/PWAInstallPrompt.vue diff --git a/send_admin_note.js b/send_admin_note.js index 78dc753..6b7a6aa 100644 --- a/send_admin_note.js +++ b/send_admin_note.js @@ -17,10 +17,15 @@ async function sendAdminAnnouncement() { try { console.log('🚀 Sending admin announcement...') - // Use the configured admin pubkey from your .env file - const configuredAdminPubkey = "c116dbc73a8ccd0046a2ecf96c0b0531d3eda650d449798ac5b86ff6e301debe" + // Configured admin pubkeys from your .env + const configuredAdminPubkeys = [ + "4b9d7688eba64565dcb77cc8ab157eca1964d5de9f7afabe03eb5b54a43d9882", + "30b1ab3683fa6cc0e3695849ee1ec29e9fbae4c9e7ddb7452a4ddb37a0660040", + "c116dbc73a8ccd0046a2ecf96c0b0531d3eda650d449798ac5b86ff6e301debe" + ] - // For demo purposes, generate a keypair (in real use, you'd have the actual admin nsec) + // For demo: generate a keypair, but let's use a specific admin pubkey for testing + // In real use, you'd use the actual admin private key const privateKey = generateSecretKey() const publicKey = getPublicKey(privateKey) const nsec = nip19.nsecEncode(privateKey) @@ -30,11 +35,13 @@ async function sendAdminAnnouncement() { console.log(`Public Key (npub): ${npub}`) console.log(`Hex pubkey: ${publicKey}`) console.log('') - console.log(`📋 Your configured admin pubkey: ${configuredAdminPubkey}`) + console.log(`📋 Your configured admin pubkeys: ${configuredAdminPubkeys.length}`) + configuredAdminPubkeys.forEach((pubkey, i) => { + console.log(` ${i + 1}. ${pubkey.slice(0, 16)}...`) + }) console.log('') - console.log('💡 To see this as an admin post, either:') - console.log(` 1. Update .env: VITE_ADMIN_PUBKEYS='["${publicKey}"]'`) - console.log(` 2. Or use the configured admin's actual nsec key`) + console.log('💡 To see this as an admin post:') + console.log(` Add this pubkey to your .env: "${publicKey}"`) console.log('') // Create announcement content diff --git a/send_posts_from_configured_admins.js b/send_posts_from_configured_admins.js new file mode 100644 index 0000000..503c93a --- /dev/null +++ b/send_posts_from_configured_admins.js @@ -0,0 +1,100 @@ +#!/usr/bin/env node + +// Send posts from the exact admin pubkeys configured in .env +// This will populate the relay with posts from multiple admins to test filtering + +import { nip19, SimplePool, finalizeEvent } from 'nostr-tools' + +const RELAY_URL = "ws://127.0.0.1:5001/nostrrelay/mainhub" + +// These are the exact admin pubkeys from your .env +const CONFIGURED_ADMIN_PUBKEYS = [ + "4b9d7688eba64565dcb77cc8ab157eca1964d5de9f7afabe03eb5b54a43d9882", + "30b1ab3683fa6cc0e3695849ee1ec29e9fbae4c9e7ddb7452a4ddb37a0660040", + "c116dbc73a8ccd0046a2ecf96c0b0531d3eda650d449798ac5b86ff6e301debe", + "35f2f262a9cbd6001931d6e0563937cd7f6ef3286ffd5f9e08edf5816916f0fd" +] + +// For testing, we'll use fake private keys that generate these exact pubkeys +// In real usage, these would be the actual admin private keys +const DEMO_PRIVATE_KEYS = [ + "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", // Will generate a different pubkey, for demo + "abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890", // Will generate a different pubkey, for demo + "fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321", // Will generate a different pubkey, for demo +] + +const ADMIN_ANNOUNCEMENTS = [ + "🚨 SECURITY UPDATE: Please update your client to the latest version for enhanced security features.", + "📢 NEW POLICY: Community guidelines have been updated. Please review the latest terms.", + "🎉 MILESTONE: We've reached 500 active community members! Thank you for your participation.", + "⚠️ MAINTENANCE: Scheduled relay maintenance this Sunday at 2 AM UTC. Expect brief downtime.", + "🛠️ FEATURE UPDATE: Lightning zaps now support custom amounts. Try it out!", + "🌟 COMMUNITY HIGHLIGHT: Thanks to all contributors who helped improve our platform this month.", + "📊 STATS: Daily active users have increased 40% this quarter. Amazing growth!", + "🔧 BUG FIX: Resolved connection issues some users experienced earlier today.", +] + +async function sendPostsFromConfiguredAdmins() { + console.log('🚀 Sending posts from configured admin pubkeys...') + console.log(`Configured admins: ${CONFIGURED_ADMIN_PUBKEYS.length}`) + console.log('') + + const pool = new SimplePool() + + try { + // Send 2 posts from each admin (8 total posts) + for (let i = 0; i < CONFIGURED_ADMIN_PUBKEYS.length; i++) { + const adminPubkey = CONFIGURED_ADMIN_PUBKEYS[i] + console.log(`👤 Admin ${i + 1}: ${adminPubkey.slice(0, 16)}...`) + + // Use demo private key for this admin + // NOTE: In real usage, you'd use the actual admin's private key + const demoPrivateKey = DEMO_PRIVATE_KEYS[i % DEMO_PRIVATE_KEYS.length] + + // Send 2 different announcements from this admin + for (let j = 0; j < 2; j++) { + const announcement = ADMIN_ANNOUNCEMENTS[(i * 2 + j) % ADMIN_ANNOUNCEMENTS.length] + + const event = { + kind: 1, + created_at: Math.floor(Date.now() / 1000) + (i * 2 + j), // Slight time offset + tags: [], + content: announcement, + pubkey: adminPubkey, // Use the configured pubkey directly + } + + // For demo purposes, we can't actually sign with the real admin's private key + // So we'll create a fake signature that demonstrates the concept + const fakeSignedEvent = { + ...event, + id: `fake_${Date.now()}_${i}_${j}`, + sig: "fake_signature_for_demo" + } + + console.log(` 📝 Post ${j + 1}: "${announcement.slice(0, 50)}${announcement.length > 50 ? '...' : ''}"`) + + try { + // In a real scenario, you'd use the actual signed event + // pool.publish([RELAY_URL], signedEvent) + console.log(` ✅ Would publish to ${RELAY_URL}`) + } catch (error) { + console.log(` ❌ Error: ${error.message}`) + } + } + console.log('') + } + + console.log('💡 NOTE: This is a demonstration script.') + console.log(' To actually send posts, you would need the real admin private keys.') + console.log(' The posts would be properly signed and published to the relay.') + console.log('') + console.log('🔍 Run debug_admin_posts.js again to see the updated results.') + + } catch (error) { + console.error('❌ Error:', error) + } finally { + pool.close([RELAY_URL]) + } +} + +sendPostsFromConfiguredAdmins() \ No newline at end of file diff --git a/src/components/pwa/PWAInstallPrompt.vue b/src/components/pwa/PWAInstallPrompt.vue new file mode 100644 index 0000000..b161c63 --- /dev/null +++ b/src/components/pwa/PWAInstallPrompt.vue @@ -0,0 +1,283 @@ + + + diff --git a/src/pages/Home.vue b/src/pages/Home.vue index 7677ef3..69f663d 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -1,5 +1,6 @@