stream-chat-react icon indicating copy to clipboard operation
stream-chat-react copied to clipboard

feat: Move Channel state describing the MessageList state to the MessageList

Open MartinCupela opened this issue 2 years ago • 0 comments

Motivation

The following values describe the Channel. Among them, there are many that actually do not belong to the Channel, but rather to MessageList (

value pertains to
suppressAutoscroll: boolean; Main MessageList
error?: Error | null; Channel
hasMore?: boolean; Main MessageList
hasMoreNewer?: boolean; Main MessageList
highlightedMessageId?: string; Main MessageList
loading?: boolean; Main MessageList
loadingMore?: boolean; Main MessageList
loadingMoreNewer?: boolean; Main MessageList
members?: StreamChannelState<StreamChatGenerics>['members']; Channel
messages?: StreamMessage<StreamChatGenerics>[]; Main MessageList
pinnedMessages?: StreamMessage<StreamChatGenerics>[]; Channel
quotedMessage?: StreamMessage<StreamChatGenerics>; Channel
read?: StreamChannelState<StreamChatGenerics>['read']; Channel
thread?: StreamMessage<StreamChatGenerics> | null; Channel
threadHasMore?: boolean; Thread MessageList
threadLoadingMore?: boolean; Thread MessageList
threadMessages?: StreamMessage<StreamChatGenerics>[]; Thread MessageList
threadSuppressAutoscroll?: boolean; Thread MessageList
typing?: StreamChannelState<StreamChatGenerics>['typing']; Channel
watcherCount?: number; Channel
watchers?: StreamChannelState<StreamChatGenerics>['watchers']; Channel

Problems

  1. As can be seen there is no parity between the Main MessageList and Thread MessageList. That leads to Thread MessageList not supporting some functionality, that is supported in the Main MessageList. Or it may lead to unexpected behavior, when the state is shared by two message lists due to it being overwritten.
  2. Having state unnecessarily high in the tree may lead to unwanted rerenders or more complex dependencies for component memoization and decrease the performance.

Proposed solution

Move message list related state into MessageList component. That way there is no need to keep the thread vs main message list dichotomy and thus reduce code bloat.

Acceptance Criteria

  1. Parity of supported functionality btw. the Main MessageList and Thread MessageList.

MartinCupela avatar Jun 16 '22 21:06 MartinCupela