Chat state is complex. Normalize carefully.
State structure:
{
conversations: {
byId: { 'conv1': { id, participantIds, lastMessageId } },
allIds: ['conv1', 'conv2']
},
messages: {
byConversationId: {
'conv1': { byId: {...}, allIds: [...] }
}
},
users: { byId: {...} },
ui: {
activeConversationId: 'conv1',
typingUsers: { 'conv1': ['user2'] }
}
}
Messages by conversation: Avoid loading all messages for all conversations into memory.