storing analytics data

This commit is contained in:
2026-02-27 09:46:51 +01:00
parent 15b7b77d20
commit f0cca76eb3
57 changed files with 3478 additions and 466 deletions

View File

@@ -39,6 +39,7 @@ function MessagesPage({ userId, username, activeConversationId: initialId }) {
const [conversations, setConversations] = useState([])
const [loadingConvs, setLoadingConvs] = useState(true)
const [activeId, setActiveId] = useState(initialId ?? null)
const [realtimeEnabled, setRealtimeEnabled] = useState(false)
const [showNewModal, setShowNewModal] = useState(false)
const [searchQuery, setSearchQuery] = useState('')
const [searchResults, setSearchResults] = useState([])
@@ -60,11 +61,32 @@ function MessagesPage({ userId, username, activeConversationId: initialId }) {
useEffect(() => {
loadConversations()
// Phase 1 polling: refresh conversation list every 15 seconds
pollRef.current = setInterval(loadConversations, 15_000)
return () => clearInterval(pollRef.current)
apiFetch('/api/messages/settings')
.then(data => setRealtimeEnabled(!!data?.realtime_enabled))
.catch(() => setRealtimeEnabled(false))
return () => {
if (pollRef.current) clearInterval(pollRef.current)
}
}, [loadConversations])
useEffect(() => {
if (pollRef.current) {
clearInterval(pollRef.current)
pollRef.current = null
}
if (realtimeEnabled) {
return
}
pollRef.current = setInterval(loadConversations, 15_000)
return () => {
if (pollRef.current) clearInterval(pollRef.current)
}
}, [loadConversations, realtimeEnabled])
const handleSelectConversation = useCallback((id) => {
setActiveId(id)
history.replaceState(null, '', `/messages/${id}`)
@@ -190,6 +212,7 @@ function MessagesPage({ userId, username, activeConversationId: initialId }) {
key={activeId}
conversationId={activeId}
conversation={activeConversation}
realtimeEnabled={realtimeEnabled}
currentUserId={userId}
currentUsername={username}
apiFetch={apiFetch}