@@ -55,8 +55,11 @@ const MessageList: React.FC<MessageListProps> = ({
5555 filterMessageList,
5656 replyType,
5757 loading,
58+ isScrolled,
59+ setIsScrolled,
5860 unreadSince,
5961 } = useChannelContext ( ) ;
62+
6063 const store = useSendbirdStateContext ( ) ;
6164 const allMessagesFiltered = ( typeof filterMessageList === 'function' )
6265 ? allMessages . filter ( ( filterMessageList as ( message : EveryMessage ) => boolean ) )
@@ -160,121 +163,131 @@ const MessageList: React.FC<MessageListProps> = ({
160163 }
161164 return < PlaceHolder className = "sendbird-conversation__no-messages" type = { PlaceHolderTypes . NO_MESSAGES } /> ;
162165 }
166+
163167 return (
164- < div className = { `sendbird-conversation__messages ${ className } ` } >
165- < div className = "sendbird-conversation__scroll-container" >
166- < div className = "sendbird-conversation__padding" />
167- < div
168- className = "sendbird-conversation__messages-padding"
169- ref = { scrollRef }
170- onScroll = { ( e ) => {
171- handleOnScroll ( ) ;
172- scrollToBottomHandler ( e ) ;
173- } }
174- >
175- { allMessagesFiltered . map ( ( m , idx ) => {
176- const {
177- chainTop,
178- chainBottom,
179- hasSeparator,
180- } = getMessagePartsInfo ( {
181- allMessages : allMessagesFiltered ,
182- replyType,
183- isMessageGroupingEnabled,
184- currentIndex : idx ,
185- currentMessage : m ,
186- currentChannel : currentGroupChannel ,
187- } ) ;
188- const isByMe = ( m as UserMessage ) ?. sender ?. userId === store ?. config ?. userId ;
189- return (
190- < MessageProvider message = { m } key = { m ?. messageId } isByMe = { isByMe } >
191- < Message
192- handleScroll = { moveScroll }
193- renderMessage = { renderMessage }
194- message = { m }
195- hasSeparator = { hasSeparator }
196- chainTop = { chainTop }
197- chainBottom = { chainBottom }
198- renderCustomSeparator = { renderCustomSeparator }
199- />
200- </ MessageProvider >
201- ) ;
202- } ) }
203- { localMessages . map ( ( m , idx ) => {
204- const {
205- chainTop,
206- chainBottom,
207- } = getMessagePartsInfo ( {
208- allMessages : allMessagesFiltered ,
209- replyType,
210- isMessageGroupingEnabled,
211- currentIndex : idx ,
212- currentMessage : m ,
213- currentChannel : currentGroupChannel ,
214- } ) ;
215- const isByMe = ( m as UserMessage ) ?. sender ?. userId === store ?. config ?. userId ;
216- return (
217- < MessageProvider message = { m } key = { m ?. messageId } isByMe = { isByMe } >
218- < Message
219- handleScroll = { moveScroll }
220- renderMessage = { renderMessage }
221- message = { m }
222- chainTop = { chainTop }
223- chainBottom = { chainBottom }
224- renderCustomSeparator = { renderCustomSeparator }
225- />
226- </ MessageProvider >
227- ) ;
228- } ) }
229- { /* show frozen notifications */ }
230- { /* show new message notifications */ }
231- </ div >
232- </ div >
233- { currentGroupChannel ?. isFrozen && (
234- < FrozenNotification className = "sendbird-conversation__messages__notification" />
235- ) }
236- { unreadSince && (
237- < UnreadCount
238- className = "sendbird-conversation__messages__notification"
239- count = { currentGroupChannel ?. unreadMessageCount }
240- time = { unreadSince }
241- onClick = { ( ) => {
242- if ( scrollRef ?. current ?. scrollTop ) {
243- scrollRef . current . scrollTop = ( scrollRef ?. current ?. scrollHeight ?? 0 ) - ( scrollRef ?. current ?. offsetHeight ?? 0 ) ;
244- }
245- if ( ! disableMarkAsRead && ! ! currentGroupChannel ) {
246- markAsReadScheduler . push ( currentGroupChannel ) ;
247- messagesDispatcher ( {
248- type : messageActionTypes . MARK_AS_READ ,
249- payload : { channel : currentGroupChannel } ,
250- } ) ;
251- }
252- setInitialTimeStamp ( null ) ;
253- setAnimatedMessageId ( null ) ;
254- setHighLightedMessageId ( null ) ;
255- } }
256- />
257- ) }
168+ < >
258169 {
259- // This flag is an unmatched variable
260- scrollBottom > SCROLL_BOTTOM_PADDING && (
170+ ! isScrolled && < PlaceHolder type = { PlaceHolderTypes . LOADING } />
171+ }
172+ < div className = { `sendbird-conversation__messages ${ className } ` } >
173+ < div className = "sendbird-conversation__scroll-container" >
174+ < div className = "sendbird-conversation__padding" />
261175 < div
262- className = "sendbird-conversation__scroll-bottom-button"
263- onClick = { onClickScrollBot }
264- onKeyDown = { onClickScrollBot }
265- tabIndex = { 0 }
266- role = "button"
176+ className = "sendbird-conversation__messages-padding"
177+ ref = { scrollRef }
178+ onScroll = { ( e ) => {
179+ handleOnScroll ( ) ;
180+ scrollToBottomHandler ( e ) ;
181+ } }
267182 >
268- < Icon
269- width = "24px"
270- height = "24px"
271- type = { IconTypes . CHEVRON_DOWN }
272- fillColor = { IconColors . PRIMARY }
273- />
183+ {
184+ allMessagesFiltered . map ( ( m , idx ) => {
185+ const {
186+ chainTop,
187+ chainBottom,
188+ hasSeparator,
189+ } = getMessagePartsInfo ( {
190+ allMessages : allMessagesFiltered ,
191+ replyType,
192+ isMessageGroupingEnabled,
193+ currentIndex : idx ,
194+ currentMessage : m ,
195+ currentChannel : currentGroupChannel ,
196+ } ) ;
197+ const isByMe = ( m as UserMessage ) ?. sender ?. userId === store ?. config ?. userId ;
198+ return (
199+ < MessageProvider message = { m } key = { m ?. messageId } isByMe = { isByMe } >
200+ < Message
201+ handleScroll = { moveScroll }
202+ renderMessage = { renderMessage }
203+ message = { m }
204+ hasSeparator = { hasSeparator }
205+ chainTop = { chainTop }
206+ chainBottom = { chainBottom }
207+ renderCustomSeparator = { renderCustomSeparator }
208+ />
209+ </ MessageProvider >
210+ ) ;
211+ } )
212+ }
213+ {
214+ localMessages . map ( ( m , idx ) => {
215+ const {
216+ chainTop,
217+ chainBottom,
218+ } = getMessagePartsInfo ( {
219+ allMessages : allMessagesFiltered ,
220+ replyType,
221+ isMessageGroupingEnabled,
222+ currentIndex : idx ,
223+ currentMessage : m ,
224+ currentChannel : currentGroupChannel ,
225+ } ) ;
226+ const isByMe = ( m as UserMessage ) ?. sender ?. userId === store ?. config ?. userId ;
227+ return (
228+ < MessageProvider message = { m } key = { m ?. messageId } isByMe = { isByMe } >
229+ < Message
230+ handleScroll = { moveScroll }
231+ renderMessage = { renderMessage }
232+ message = { m }
233+ chainTop = { chainTop }
234+ chainBottom = { chainBottom }
235+ renderCustomSeparator = { renderCustomSeparator }
236+ />
237+ </ MessageProvider >
238+ ) ;
239+ } )
240+ }
241+ { /* show frozen notifications, */ }
242+ { /* show new message notifications, */ }
274243 </ div >
275- )
276- }
277- </ div >
244+ </ div >
245+ { currentGroupChannel ?. isFrozen && (
246+ < FrozenNotification className = "sendbird-conversation__messages__notification" />
247+ ) }
248+ { unreadSince && (
249+ < UnreadCount
250+ className = "sendbird-conversation__messages__notification"
251+ count = { currentGroupChannel ?. unreadMessageCount }
252+ time = { unreadSince }
253+ onClick = { ( ) => {
254+ if ( scrollRef ?. current ?. scrollTop ) {
255+ scrollRef . current . scrollTop = ( scrollRef ?. current ?. scrollHeight ?? 0 ) - ( scrollRef ?. current ?. offsetHeight ?? 0 ) ;
256+ }
257+ if ( ! disableMarkAsRead && ! ! currentGroupChannel ) {
258+ markAsReadScheduler . push ( currentGroupChannel ) ;
259+ messagesDispatcher ( {
260+ type : messageActionTypes . MARK_AS_READ ,
261+ payload : { channel : currentGroupChannel } ,
262+ } ) ;
263+ }
264+ setInitialTimeStamp ( null ) ;
265+ setAnimatedMessageId ( null ) ;
266+ setHighLightedMessageId ( null ) ;
267+ } }
268+ />
269+ ) }
270+ {
271+ // This flag is an unmatched variable
272+ scrollBottom > SCROLL_BOTTOM_PADDING && (
273+ < div
274+ className = "sendbird-conversation__scroll-bottom-button"
275+ onClick = { onClickScrollBot }
276+ onKeyDown = { onClickScrollBot }
277+ tabIndex = { 0 }
278+ role = "button"
279+ >
280+ < Icon
281+ width = "24px"
282+ height = "24px"
283+ type = { IconTypes . CHEVRON_DOWN }
284+ fillColor = { IconColors . PRIMARY }
285+ />
286+ </ div >
287+ )
288+ }
289+ </ div >
290+ </ >
278291 ) ;
279292} ;
280293
0 commit comments