From c0939e9aab1efb4d84c7e7b0f2ec7318d21aa425 Mon Sep 17 00:00:00 2001 From: Felix Hallenberg Date: Sat, 4 May 2024 10:29:50 +0300 Subject: [PATCH] Fix eslint/ts issues --- .../Main/Chat/MessageList/MemoizedRenderItem.tsx | 1 + src/Screens/Main/Chat/MessageList/index.tsx | 2 ++ src/state/reducers/markSeen.ts | 10 ++++------ src/state/reducers/messages.ts | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Screens/Main/Chat/MessageList/MemoizedRenderItem.tsx b/src/Screens/Main/Chat/MessageList/MemoizedRenderItem.tsx index fbc0f203..e305980d 100644 --- a/src/Screens/Main/Chat/MessageList/MemoizedRenderItem.tsx +++ b/src/Screens/Main/Chat/MessageList/MemoizedRenderItem.tsx @@ -34,6 +34,7 @@ const equalProps = ( ) { const prev = prevProps.item as MessageProps; const next = nextProps.item as MessageProps; + return prev.id === next.id && prev.isSeen === next.isSeen; } diff --git a/src/Screens/Main/Chat/MessageList/index.tsx b/src/Screens/Main/Chat/MessageList/index.tsx index 246a66ca..332a78d2 100644 --- a/src/Screens/Main/Chat/MessageList/index.tsx +++ b/src/Screens/Main/Chat/MessageList/index.tsx @@ -105,6 +105,7 @@ export const MessageList = ({ viewableItems: Array; changed: Array; }; + const handleViewableChanged = ({ changed }: ViewArgs) => { // TODO: Helper here, decode the changed maybe const unSeenMessagesOnScreen = changed @@ -124,6 +125,7 @@ export const MessageList = ({ itemVisiblePercentThreshold: 100, minimumViewTime: 1000, }; + const viewabilityConfigCallbackPairs = React.useRef([ { viewabilityConfig, onViewableItemsChanged: handleViewableChanged }, ]); diff --git a/src/state/reducers/markSeen.ts b/src/state/reducers/markSeen.ts index e68d40b5..bbe04529 100644 --- a/src/state/reducers/markSeen.ts +++ b/src/state/reducers/markSeen.ts @@ -16,6 +16,7 @@ export const reducer: automaton.Reducer = ( switch (action.type) { case 'messages/markSeen': { const hasMessages = action.payload.messages.length > 0; + if (!hasMessages) { return automaton.loop(state, { type: 'messages/markSeen/end', @@ -26,6 +27,7 @@ export const reducer: automaton.Reducer = ( const [first, ...messages] = action.payload.messages; console.log('markSeen action for message', first.content); + const nextState = first.messageId in state || first.isSeen || first.type === 'Sent' ? state @@ -35,14 +37,10 @@ export const reducer: automaton.Reducer = ( return automaton.loop( nextState, - // withToken(markSeenTask, () => ({ - // type: 'messages/markSeen', - // payload: { messages }, - // })), - { + withToken(markSeenTask, () => ({ type: 'messages/markSeen', payload: { messages }, - }, + })), ); } diff --git a/src/state/reducers/messages.ts b/src/state/reducers/messages.ts index d5079b83..cb3b7491 100644 --- a/src/state/reducers/messages.ts +++ b/src/state/reducers/messages.ts @@ -16,7 +16,7 @@ import * as actions from '../actions'; import * as types from '../types'; import { withToken } from './accessToken'; -import { getIsBanned, getBuddyStatus } from '../selectors'; +import { getBuddyStatus } from '../selectors'; export type State = types.AppState['messages']; export type LoopState = actions.LS; @@ -176,6 +176,7 @@ export const reducer: automaton.Reducer = ( case 'messages/markSeen': { const hasMessages = action.payload.messages.length > 0; + if (!hasMessages) { return state; }