feat: add chat message history and infinite scroll

Backend changes:
- Socket.IO: Send last 20 messages on join_event_room
- REST API: Add GET /api/events/:eventId/messages endpoint with pagination
- Support for 'before' cursor-based pagination for loading older messages

Frontend changes:
- Load initial 20 messages when joining event chat
- Implement infinite scroll to load older messages on scroll to top
- Add loading indicator for older messages
- Preserve scroll position when loading older messages
- Add eventsAPI.getMessages() function for pagination

User experience:
- New users see last 20 messages immediately
- Scrolling up automatically loads older messages in batches of 20
- Smooth scrolling experience with position restoration

Note: Messages are encrypted in transit via HTTPS/WSS but stored
as plain text in database (no E2E encryption).
This commit is contained in:
Radosław Gierwiało
2025-11-13 20:16:58 +01:00
parent 833818f17d
commit 9d8fc9f6d6
4 changed files with 178 additions and 3 deletions

View File

@@ -163,6 +163,15 @@ export const eventsAPI = {
const data = await fetchAPI(`/events/${id}`);
return data.data;
},
async getMessages(eventId, before = null, limit = 20) {
const params = new URLSearchParams({ limit: limit.toString() });
if (before) {
params.append('before', before.toString());
}
const data = await fetchAPI(`/events/${eventId}/messages?${params}`);
return data;
},
};
export { ApiError };