Add alert creation on note sharing - triggers alerts for shared_with users

This commit is contained in:
2026-01-16 01:29:48 +00:00
parent 9ced9fd4ed
commit 7c4459fd47
3 changed files with 81 additions and 4 deletions
+20 -4
View File
@@ -38,21 +38,36 @@ async function getEmailByFirstName(pb, firstName) {
}
try {
// First, get ALL records to inspect structure
const allRecords = await pb.collection('Associations').getList(1, 50);
console.log(`[Email Lookup] All Associations records:`, allRecords.items);
if (allRecords.items.length > 0) {
console.log(`[Email Lookup] Sample record fields:`, Object.keys(allRecords.items[0]));
console.log(`[Email Lookup] Sample record:`, allRecords.items[0]);
}
// Now try the filtered query
const records = await pb.collection('Associations').getList(1, 50, {
filter: `first_name = "${firstName}"`,
});
console.log(`[Email Lookup] Query: first_name="${firstName}" | Filtered results:`, records.items);
if (records.items.length === 0) {
console.log(`[Email Lookup] No records found for: ${firstName}`);
emailLookupCache[firstName] = 'Email not found';
return 'Email not found';
}
// Use first match's email
const email = records.items[0].email || 'Email not found';
// Use first match's emailtext field
const firstRecord = records.items[0];
console.log(`[Email Lookup] First record:`, firstRecord);
const email = firstRecord.emailtext || 'Email not found';
emailLookupCache[firstName] = email;
return email;
} catch (error) {
console.error(`Failed to lookup email for "${firstName}":`, error);
console.error(`Error response:`, error.response?.data);
return 'Error loading email';
}
}
@@ -74,8 +89,6 @@ window.setupUserEmailLookup = function(pb, containerSelector) {
}
console.log(`✓ User Email Lookup initialized for: ${containerSelector}`);
// Observer: Watch for new capsule additions
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
@@ -115,11 +128,14 @@ function attachEmailLookupTooltip(pb, capsuleEl) {
const firstName = nameSpan.textContent.trim();
if (!firstName) return;
console.log(`[Email Lookup] Attached to user: ${firstName}`);
// Mark as processed
nameSpan.setAttribute('data-email-loaded', 'true');
// Attach hover listener
capsuleEl.addEventListener('mouseenter', async () => {
console.log(`[Email Lookup] Hover on: ${firstName}`);
// If email already in title, don't query again
if (capsuleEl.title && !capsuleEl.title.startsWith('Loading')) {
return;