fix(ui): refresh Contact Info path display in real-time

Path info in Contact Info modal was stale due to 60s server cache
and no refresh after path operations. Now:
- Invalidate contacts cache after reset_path, change_path, path_update
- Emit 'path_changed' socket event on PATH_UPDATE from device
- UI listens and re-renders Contact Info when path changes
- Reset to FLOOD button immediately refreshes the path display

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-03-27 20:29:26 +01:00
parent 292d1d91af
commit 5df9b4b4a2
3 changed files with 61 additions and 0 deletions
+41
View File
@@ -120,6 +120,18 @@ function connectChatSocket() {
chatSocket.on('device_status', (data) => {
updateStatus(data.connected ? 'connected' : 'disconnected');
});
// Real-time path change — refresh Contact Info if open for this contact
chatSocket.on('path_changed', async (data) => {
const modalEl = document.getElementById('dmContactInfoModal');
if (!modalEl || !modalEl.classList.contains('show')) return;
const currentPubkey = getCurrentContactPubkey();
if (!currentPubkey) return;
const changedKey = (data.public_key || '').toLowerCase();
if (changedKey && changedKey.startsWith(currentPubkey.toLowerCase())) {
await refreshContactInfoPath();
}
});
}
// Initialize on page load
@@ -975,6 +987,34 @@ function populateContactInfoModal() {
}
}
/**
* Refresh contact data from device and re-render Contact Info modal if open.
* Uses ?refresh=true to bypass server-side cache.
*/
async function refreshContactInfoPath() {
try {
const response = await fetch('/api/contacts/detailed?refresh=true');
const data = await response.json();
if (data.success) {
contactsList = (data.contacts || []).sort((a, b) =>
(a.name || '').localeCompare(b.name || ''));
contactsMap = {};
contactsList.forEach(c => {
if (c.public_key) contactsMap[c.public_key] = c;
});
}
} catch (e) {
console.error('[DM] refreshContactInfoPath fetch error:', e);
return;
}
// Re-populate modal if still open
const modalEl = document.getElementById('dmContactInfoModal');
if (modalEl && modalEl.classList.contains('show')) {
populateContactInfoModal();
loadPathSection();
}
}
/**
* Load messages for current conversation
*/
@@ -2114,6 +2154,7 @@ function setupPathFormHandlers(pubkey) {
const data = await response.json();
if (data.success) {
showNotification('Device path reset to FLOOD', 'info');
await refreshContactInfoPath();
} else {
showNotification(data.error || 'Reset failed', 'danger');
}