aabde17532
Phase 4 implementation: - 4.1 IONOS SMTP email configuration (production + docker profiles) - 4.2 Portal navigation update (info board, events, forum links) - 4.3 Tier enforcement: PlanTierService (forum=Pro+, info board limits) - 4.4 WebSocket real-time updates (WebSocketEventPublisher) - 4.5 EmailService: notification, event reminder, info board templates + rate limiting - 4.6 Enterprise custom FROM: CustomMailDomain entity, DNS verification, controller New files: - PlanTierService: tier checks for forum/info board/enterprise features - NotificationDispatchService: EMAIL channel dispatch via preferences - WebSocketEventPublisher: STOMP topic push for forum/info board/events - CustomMailDomainService: DNS TXT record verification for custom FROM - MailSettingsController: Enterprise custom domain API endpoints - CustomMailDomain entity + repository - V16 migration: email dispatch index - V17 migration: custom_mail_domains table - Frontend: use-forum-subscription + use-info-board-subscription hooks - Portal navbar: added info board, events, forum navigation items - i18n: added portal nav translations (de + en) Also fixed pre-existing Phase 2.5/3 compilation issues: - Member entity: added userId field - AuditService: added convenience overloads (logEvent, 4-param log) - AuditEventType: added INFO_BOARD_POST_UPDATED, INFO_BOARD_POST_DELETED - QuotaViolationCode: added TIER_UPGRADE_REQUIRED - StaffPermissionChecker: added requirePermission(UserDetails, ...) - TenantContext: added getCurrentTenantId() alias - MemberRepository: added findByUserId, findByClubId, findAllByClubId - EmailServiceTest: updated for new constructor signature
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
"use client"
|
|
|
|
import { useEffect, useCallback, useRef } from "react"
|
|
|
|
/**
|
|
* Hook to subscribe to forum WebSocket events for a specific club.
|
|
* Listens for new topics and replies in real-time.
|
|
*/
|
|
export function useForumSubscription(
|
|
clubId: string | undefined,
|
|
topicId?: string,
|
|
onNewTopic?: (data: ForumTopicEvent) => void,
|
|
onNewReply?: (data: ForumReplyEvent) => void
|
|
) {
|
|
const stompClientRef = useRef<any>(null)
|
|
|
|
useEffect(() => {
|
|
if (!clubId) return
|
|
|
|
// Dynamic import of SockJS client
|
|
const connectWebSocket = async () => {
|
|
try {
|
|
const SockJS = (await import("sockjs-client")).default
|
|
const { Client } = await import("@stomp/stompjs")
|
|
|
|
const client = new Client({
|
|
webSocketFactory: () => new SockJS("/ws"),
|
|
reconnectDelay: 5000,
|
|
heartbeatIncoming: 10000,
|
|
heartbeatOutgoing: 10000,
|
|
})
|
|
|
|
client.onConnect = () => {
|
|
// Subscribe to general forum channel
|
|
client.subscribe(`/topic/club.${clubId}.forum`, (message) => {
|
|
const data = JSON.parse(message.body)
|
|
if (data.type === "NEW_TOPIC" && onNewTopic) {
|
|
onNewTopic(data as ForumTopicEvent)
|
|
}
|
|
})
|
|
|
|
// Subscribe to specific topic if provided
|
|
if (topicId) {
|
|
client.subscribe(`/topic/club.${clubId}.forum.${topicId}`, (message) => {
|
|
const data = JSON.parse(message.body)
|
|
if (data.type === "NEW_REPLY" && onNewReply) {
|
|
onNewReply(data as ForumReplyEvent)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
client.activate()
|
|
stompClientRef.current = client
|
|
} catch (error) {
|
|
console.warn("WebSocket connection failed:", error)
|
|
}
|
|
}
|
|
|
|
connectWebSocket()
|
|
|
|
return () => {
|
|
if (stompClientRef.current) {
|
|
stompClientRef.current.deactivate()
|
|
}
|
|
}
|
|
}, [clubId, topicId, onNewTopic, onNewReply])
|
|
}
|
|
|
|
export interface ForumTopicEvent {
|
|
type: "NEW_TOPIC"
|
|
topicId: string
|
|
title: string
|
|
authorName: string
|
|
timestamp: string
|
|
}
|
|
|
|
export interface ForumReplyEvent {
|
|
type: "NEW_REPLY"
|
|
topicId: string
|
|
replyId: string
|
|
authorName: string
|
|
timestamp: string
|
|
}
|