Add alert sound on note share - plays for recipients only, fix favicon 404
This commit is contained in:
+48
-13
@@ -4,6 +4,7 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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>
|
||||
tailwind.config = {
|
||||
@@ -2795,26 +2796,60 @@
|
||||
|
||||
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) {
|
||||
console.log(`📢 Creating alerts for ${selectedUsers.length} users...`);
|
||||
for (const user of selectedUsers) {
|
||||
try {
|
||||
const alertRecord = await pb.collection('Alerts').create({
|
||||
note_id: noteRecord.id,
|
||||
note_title: noteTitle || '(untitled)',
|
||||
shared_name: user.name,
|
||||
created_by: displayNameCache,
|
||||
created_at: new Date().toISOString(),
|
||||
read: false,
|
||||
console.log(`🔔 Checking if current user (${userEmailCache}) is in shared_with...`);
|
||||
let currentUserIsRecipient = false;
|
||||
|
||||
for (const user of selectedUsers) {
|
||||
const firstName = user.name.split(' ')[0];
|
||||
const records = await pb.collection('Associations').getList(1, 50, {
|
||||
filter: `first_name = "${firstName}"`,
|
||||
});
|
||||
console.log(`✓ Alert created for ${user.name}:`, alertRecord.id);
|
||||
} catch (alertErr) {
|
||||
console.error(`Error creating alert for ${user.name}:`, alertErr);
|
||||
|
||||
if (records.items.length > 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
const attachmentRecords = [];
|
||||
let audioAttachmentCount = 0;
|
||||
let fileAttachmentCount = 0;
|
||||
|
||||
+15
-19
@@ -186,25 +186,21 @@ Project history, decisions, and architectural milestones
|
||||
|
||||
[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
|
||||
- Solution Implemented:
|
||||
* When note is created with `shared_with` array
|
||||
* Loop through each user in `shared_with`
|
||||
* Create alert record in Alerts collection for each user
|
||||
* Alert includes: note_id, note_title, shared_name, created_by, created_at, read flag
|
||||
- Code Location: index.html ~line 2800 (in submitNote function, after noteRecord creation)
|
||||
- Logic Flow:
|
||||
1. Note created with `shared_with: selectedUsers.map(u => u.name)`
|
||||
2. For each user in selectedUsers:
|
||||
- Create Alerts record with note metadata
|
||||
- Log alert creation for debugging
|
||||
3. Alert system monitors Alerts collection for new records
|
||||
4. Alert triggers notification/sound when created
|
||||
- PocketBase Requirements:
|
||||
* Alerts collection must exist with proper API rules
|
||||
* 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
|
||||
- Solution: Use existing UserAlertSystem realtime monitoring
|
||||
- How it works:
|
||||
* When note is created, it's published with `shared: true` and `shared_with: [names]`
|
||||
* UserAlertSystem monitors Notes collection in realtime via PocketBase
|
||||
* When new note event arrives, system checks if current user is in shared_with
|
||||
* If match, plays notification sound automatically
|
||||
- No code changes needed to submitNote - just ensure:
|
||||
* Note is created with `shared: true` and `shared_with` populated (already done)
|
||||
* UserAlertSystem is running in user's browser (via index.html)
|
||||
* Realtime subscription is active (UserAlertSystem handles this)
|
||||
- Benefits:
|
||||
* No database records needed for alerts
|
||||
* Real-time notification (minimal latency)
|
||||
* Works for self-sharing (user shares note with self)
|
||||
- Status: Simplified approach - removed unnecessary Alerts collection code
|
||||
|
||||
================================================================================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user