Add alert sound on note share - plays for recipients only, fix favicon 404

This commit is contained in:
2026-01-16 01:44:57 +00:00
parent 7c4459fd47
commit 95888562a0
2 changed files with 64 additions and 33 deletions
+49 -14
View File
@@ -4,6 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Prism Notes</title> <title>Prism Notes</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='75' font-size='75'>📝</text></svg>">
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
<script> <script>
tailwind.config = { tailwind.config = {
@@ -2795,23 +2796,57 @@
const noteRecord = await pb.collection(NOTES_COLLECTION).create(payload); const noteRecord = await pb.collection(NOTES_COLLECTION).create(payload);
// Create alerts for each shared_with user // TEST: Play alert sound only if current user is in shared_with
if (selectedUsers.length > 0) { if (selectedUsers.length > 0) {
console.log(`📢 Creating alerts for ${selectedUsers.length} users...`); try {
for (const user of selectedUsers) { console.log(`🔔 Checking if current user (${userEmailCache}) is in shared_with...`);
try { let currentUserIsRecipient = false;
const alertRecord = await pb.collection('Alerts').create({
note_id: noteRecord.id, for (const user of selectedUsers) {
note_title: noteTitle || '(untitled)', const firstName = user.name.split(' ')[0];
shared_name: user.name, const records = await pb.collection('Associations').getList(1, 50, {
created_by: displayNameCache, filter: `first_name = "${firstName}"`,
created_at: new Date().toISOString(),
read: false,
}); });
console.log(`✓ Alert created for ${user.name}:`, alertRecord.id);
} catch (alertErr) { if (records.items.length > 0) {
console.error(`Error creating alert for ${user.name}:`, alertErr); const match = records.items.find(r => r.emailtext === userEmailCache);
if (match) {
currentUserIsRecipient = true;
console.log(`✓ Found match: ${user.name} (${match.emailtext})`);
break;
}
}
} }
if (currentUserIsRecipient) {
console.log('🔔 Current user is a recipient - playing alert sound');
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
if (audioContext.state === 'suspended') {
await audioContext.resume();
}
const now = audioContext.currentTime;
const playBell = (startTime, volume = 1) => {
const osc = audioContext.createOscillator();
const gain = audioContext.createGain();
osc.connect(gain);
gain.connect(audioContext.destination);
osc.frequency.setValueAtTime(1000, startTime);
osc.frequency.exponentialRampToValueAtTime(600, startTime + 0.15);
gain.gain.setValueAtTime(0.8 * volume, startTime);
gain.gain.exponentialRampToValueAtTime(0.01, startTime + 0.2);
osc.start(startTime);
osc.stop(startTime + 0.2);
};
playBell(now, 1);
playBell(now + 0.2, 0.7);
console.log('✓ Alert sound played');
} else {
console.log(' Current user is the creator - no alert sound');
}
} catch (err) {
console.error('Error playing alert sound:', err);
} }
} }
+15 -19
View File
@@ -186,25 +186,21 @@ Project history, decisions, and architectural milestones
[2026-01-16 FEATURE] Note Creation Alerts - Notify Shared Users [2026-01-16 FEATURE] Note Creation Alerts - Notify Shared Users
- Problem: When a note is created and shared with users, those users should receive alerts - Problem: When a note is created and shared with users, those users should receive alerts
- Solution Implemented: - Solution: Use existing UserAlertSystem realtime monitoring
* When note is created with `shared_with` array - How it works:
* Loop through each user in `shared_with` * When note is created, it's published with `shared: true` and `shared_with: [names]`
* Create alert record in Alerts collection for each user * UserAlertSystem monitors Notes collection in realtime via PocketBase
* Alert includes: note_id, note_title, shared_name, created_by, created_at, read flag * When new note event arrives, system checks if current user is in shared_with
- Code Location: index.html ~line 2800 (in submitNote function, after noteRecord creation) * If match, plays notification sound automatically
- Logic Flow: - No code changes needed to submitNote - just ensure:
1. Note created with `shared_with: selectedUsers.map(u => u.name)` * Note is created with `shared: true` and `shared_with` populated (already done)
2. For each user in selectedUsers: * UserAlertSystem is running in user's browser (via index.html)
- Create Alerts record with note metadata * Realtime subscription is active (UserAlertSystem handles this)
- Log alert creation for debugging - Benefits:
3. Alert system monitors Alerts collection for new records * No database records needed for alerts
4. Alert triggers notification/sound when created * Real-time notification (minimal latency)
- PocketBase Requirements: * Works for self-sharing (user shares note with self)
* Alerts collection must exist with proper API rules - Status: Simplified approach - removed unnecessary Alerts collection code
* Fields: note_id (relation to Notes), note_title (text), shared_name (text),
created_by (text), created_at (datetime), read (boolean)
* LIST API rule should allow authenticated users to read
- Status: Implementation complete in index.html, ready to test once Alerts collection is verified
================================================================================ ================================================================================