Skip to content

Commit b3e4c9b

Browse files
abc and some cleanup
1 parent ccae3b4 commit b3e4c9b

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

src/components/Chat/hooks/useIsOnline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3+
import { useAppStateListener } from './useAppStateListener';
34
import { NetInfo } from '../../../native';
45

56
import type { NetInfoSubscription } from '@react-native-community/netinfo';
@@ -15,7 +16,6 @@ import type {
1516
DefaultUserType,
1617
UnknownType,
1718
} from '../../../types/types';
18-
import { useAppStateListener } from './useAppStateListener';
1919

2020
/**
2121
* Disconnect the websocket connection when app goes to background,

src/components/Message/Message.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,12 @@ const areEqual = <
12951295
const repliesEqual = prevMessage.reply_count === nextMessage.reply_count;
12961296
if (!repliesEqual) return false;
12971297

1298+
/**
1299+
* We need to allow re-render when lastReceivedId changes, for following cases
1300+
* 1. updating the status (seen status) on latest message in list
1301+
* 2. updating quoted messages. Because when you press the quoted message, it makes a call
1302+
* to `goToMessage` function, which is dependent on message list (length specifically).
1303+
*/
12981304
const lastReceivedIdChangedAndMatters =
12991305
prevLastReceivedId !== nextLastReceivedId &&
13001306
(prevLastReceivedId === prevMessage.id ||

src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,25 @@ const areEqual = <
437437
tDateTimeParser: nextTDateTimeParser,
438438
} = nextProps;
439439

440+
const hasReactionsEqual = prevHasReactions === nextHasReactions;
441+
if (!hasReactionsEqual) return false;
442+
443+
const lastGroupMessageEqual = prevLastGroupMessage === nextLastGroupMessage;
444+
if (!lastGroupMessageEqual) return false;
445+
446+
/**
447+
* We need to allow re-render when lastReceivedId changes, for following cases
448+
* 1. updating the status (seen status) on latest message in list
449+
* 2. updating quoted messages. Because when you press the quoted message, it makes a call
450+
* to `goToMessage` function, which is dependent on message list (length specifically).
451+
*/
440452
const lastReceivedIdChangedAndMatters =
441453
prevLastReceivedId !== nextLastReceivedId &&
442454
prevMessage.quoted_message_id &&
443455
nextMessage.quoted_message_id;
444456

445457
if (lastReceivedIdChangedAndMatters) return false;
446458

447-
const hasReactionsEqual = prevHasReactions === nextHasReactions;
448-
if (!hasReactionsEqual) return false;
449-
450-
const lastGroupMessageEqual = prevLastGroupMessage === nextLastGroupMessage;
451-
if (!lastGroupMessageEqual) return false;
452-
453459
const onlyEmojisEqual = prevOnlyEmojis === nextOnlyEmojis;
454460
if (!onlyEmojisEqual) return false;
455461

src/components/MessageList/MessageList.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ const MessageListWithContext = <
371371
const flatListRef = useRef<FlatListType<
372372
MessageType<At, Ch, Co, Ev, Me, Re, Us>
373373
> | null>(null);
374+
374375
const initialScrollSet = useRef<boolean>(false);
375376
const channelResyncScrollSet = useRef<boolean>(true);
376377

@@ -655,23 +656,23 @@ const MessageListWithContext = <
655656
);
656657
};
657658

658-
//
659-
// We are keeping full control on message pagination, and not relying on react-native for it.
660-
// The reasons being,
661-
// 1. FlatList doesn't support onStartReached prop
662-
// 2. `onEndReached` function prop available on react-native, gets executed
663-
// once per content length (and thats actually a nice optimization strategy).
664-
// But it also means, we always need to prioritize onEndReached above our
665-
// logic for `onStartReached`.
666-
// 3. `onEndReachedThreshold` prop decides - at which scroll position to call `onEndReached`.
667-
// Its a factor of content length (which is necessary for "real" infinite scroll). But on
668-
// the other hand, it also makes calls to `onEndReached` (and this `channel.query`) way
669-
// too early during scroll, which we don't really need. So we are going to instead
670-
// keep some fixed offset distance, to decide when to call `loadMore` or `loadMoreRecent`.
671-
//
672-
// We are still gonna keep the optimization, which react-native does - only call onEndReached
673-
// once per content length.
674-
//
659+
/**
660+
* We are keeping full control on message pagination, and not relying on react-native for it.
661+
* The reasons being,
662+
* 1. FlatList doesn't support onStartReached prop
663+
* 2. `onEndReached` function prop available on react-native, gets executed
664+
* once per content length (and thats actually a nice optimization strategy).
665+
* But it also means, we always need to prioritize onEndReached above our
666+
* logic for `onStartReached`.
667+
* 3. `onEndReachedThreshold` prop decides - at which scroll position to call `onEndReached`.
668+
* Its a factor of content length (which is necessary for "real" infinite scroll). But on
669+
* the other hand, it also makes calls to `onEndReached` (and this `channel.query`) way
670+
* too early during scroll, which we don't really need. So we are going to instead
671+
* keep some fixed offset distance, to decide when to call `loadMore` or `loadMoreRecent`.
672+
*
673+
* We are still gonna keep the optimization, which react-native does - only call onEndReached
674+
* once per content length.
675+
*/
675676

676677
/**
677678
* 1. Makes a call to `loadMoreRecent` function, which queries more recent messages.

src/components/MessageList/NetworkDownIndicator.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import { StyleSheet, Text, View } from 'react-native';
3+
34
import { useChannelContext } from '../../contexts/channelContext/ChannelContext';
45
import { useChatContext } from '../../contexts/chatContext/ChatContext';
56

@@ -22,15 +23,15 @@ const styles = StyleSheet.create({
2223
});
2324

2425
export const NetworkDownIndicator = () => {
26+
const { error } = useChannelContext();
27+
const { isOnline } = useChatContext();
2528
const {
2629
theme: {
2730
colors: { grey },
2831
messageList: { errorNotification, errorNotificationText },
2932
},
3033
} = useTheme();
3134
const { t } = useTranslationContext();
32-
const { isOnline } = useChatContext();
33-
const { error } = useChannelContext();
3435

3536
if (isOnline && !error) {
3637
return null;

0 commit comments

Comments
 (0)