@planningcenter/chat-react-native 4.4.1-qa-staging.10 → 4.4.1-qa-staging.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/hooks/use_mark_latest_message_read.d.ts.map +1 -1
- package/build/hooks/use_mark_latest_message_read.js +3 -3
- package/build/hooks/use_mark_latest_message_read.js.map +1 -1
- package/package.json +3 -3
- package/src/hooks/__tests__/use_mark_latest_message_read.test.tsx +21 -7
- package/src/hooks/use_mark_latest_message_read.ts +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_mark_latest_message_read.d.ts","sourceRoot":"","sources":["../../src/hooks/use_mark_latest_message_read.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAIhE,UAAU,KAAK;IACb,YAAY,EAAE,oBAAoB,CAAA;IAClC,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,wBAAwB,CAAC,EAAE,YAAY,EAAE,OAAc,EAAE,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"use_mark_latest_message_read.d.ts","sourceRoot":"","sources":["../../src/hooks/use_mark_latest_message_read.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAIhE,UAAU,KAAK;IACb,YAAY,EAAE,oBAAoB,CAAA;IAClC,QAAQ,EAAE,eAAe,EAAE,CAAA;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,wBAAwB,CAAC,EAAE,YAAY,EAAE,OAAc,EAAE,EAAE,KAAK,QAsB/E"}
|
|
@@ -18,13 +18,13 @@ export function useMarkLatestMessageRead({
|
|
|
18
18
|
}), [markRead]);
|
|
19
19
|
const unreadCount = conversation.unreadCount;
|
|
20
20
|
const unreadReaction = conversation.unreadReaction;
|
|
21
|
-
const shouldMarkRead = Boolean(unreadCount >= 1 || unreadReaction
|
|
21
|
+
const shouldMarkRead = !firedOnce.current || enabled && Boolean(unreadCount >= 1 || unreadReaction);
|
|
22
22
|
const appState = useAppState();
|
|
23
23
|
const isActive = appState === 'active';
|
|
24
24
|
useEffect(() => {
|
|
25
|
-
if (!
|
|
25
|
+
if (!isActive || !shouldMarkRead) return;
|
|
26
26
|
firedOnce.current = true;
|
|
27
27
|
debouncedMarkRead(true);
|
|
28
|
-
}, [debouncedMarkRead,
|
|
28
|
+
}, [debouncedMarkRead, isActive, shouldMarkRead, unreadReaction]);
|
|
29
29
|
}
|
|
30
30
|
//# sourceMappingURL=use_mark_latest_message_read.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_mark_latest_message_read.js","names":["debounce","useEffect","useMemo","useRef","useAppState","useConversationsMarkRead","useMarkLatestMessageRead","conversation","enabled","firedOnce","markRead","debouncedMarkRead","leading","trailing","unreadCount","unreadReaction","shouldMarkRead","
|
|
1
|
+
{"version":3,"file":"use_mark_latest_message_read.js","names":["debounce","useEffect","useMemo","useRef","useAppState","useConversationsMarkRead","useMarkLatestMessageRead","conversation","enabled","firedOnce","markRead","debouncedMarkRead","leading","trailing","unreadCount","unreadReaction","shouldMarkRead","current","Boolean","appState","isActive"],"sources":["../../src/hooks/use_mark_latest_message_read.ts"],"sourcesContent":["import { debounce } from 'lodash'\nimport { useEffect, useMemo, useRef } from 'react'\nimport { ConversationResource, MessageResource } from '../types'\nimport { useAppState } from './use_app_state'\nimport { useConversationsMarkRead } from './use_conversations_actions'\n\ninterface Props {\n conversation: ConversationResource\n messages: MessageResource[]\n enabled?: boolean\n}\n\nexport function useMarkLatestMessageRead({ conversation, enabled = true }: Props) {\n const firedOnce = useRef<boolean>(false)\n const { markRead } = useConversationsMarkRead({ conversation })\n const debouncedMarkRead = useMemo(\n () => debounce(markRead, 1000, { leading: true, trailing: true }),\n [markRead]\n )\n const unreadCount = conversation.unreadCount\n const unreadReaction = conversation.unreadReaction\n\n const shouldMarkRead =\n !firedOnce.current || (enabled && Boolean(unreadCount >= 1 || unreadReaction))\n const appState = useAppState()\n const isActive = appState === 'active'\n\n useEffect(() => {\n if (!isActive || !shouldMarkRead) return\n\n firedOnce.current = true\n\n debouncedMarkRead(true)\n }, [debouncedMarkRead, isActive, shouldMarkRead, unreadReaction])\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAElD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,wBAAwB,QAAQ,6BAA6B;AAQtE,OAAO,SAASC,wBAAwBA,CAAC;EAAEC,YAAY;EAAEC,OAAO,GAAG;AAAY,CAAC,EAAE;EAChF,MAAMC,SAAS,GAAGN,MAAM,CAAU,KAAK,CAAC;EACxC,MAAM;IAAEO;EAAS,CAAC,GAAGL,wBAAwB,CAAC;IAAEE;EAAa,CAAC,CAAC;EAC/D,MAAMI,iBAAiB,GAAGT,OAAO,CAC/B,MAAMF,QAAQ,CAACU,QAAQ,EAAE,IAAI,EAAE;IAAEE,OAAO,EAAE,IAAI;IAAEC,QAAQ,EAAE;EAAK,CAAC,CAAC,EACjE,CAACH,QAAQ,CACX,CAAC;EACD,MAAMI,WAAW,GAAGP,YAAY,CAACO,WAAW;EAC5C,MAAMC,cAAc,GAAGR,YAAY,CAACQ,cAAc;EAElD,MAAMC,cAAc,GAClB,CAACP,SAAS,CAACQ,OAAO,IAAKT,OAAO,IAAIU,OAAO,CAACJ,WAAW,IAAI,CAAC,IAAIC,cAAc,CAAE;EAChF,MAAMI,QAAQ,GAAGf,WAAW,CAAC,CAAC;EAC9B,MAAMgB,QAAQ,GAAGD,QAAQ,KAAK,QAAQ;EAEtClB,SAAS,CAAC,MAAM;IACd,IAAI,CAACmB,QAAQ,IAAI,CAACJ,cAAc,EAAE;IAElCP,SAAS,CAACQ,OAAO,GAAG,IAAI;IAExBN,iBAAiB,CAAC,IAAI,CAAC;EACzB,CAAC,EAAE,CAACA,iBAAiB,EAAES,QAAQ,EAAEJ,cAAc,EAAED,cAAc,CAAC,CAAC;AACnE","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "4.4.1-qa-staging.
|
|
3
|
+
"version": "4.4.1-qa-staging.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@fortawesome/fontawesome-svg-core": "^7.2.0",
|
|
35
35
|
"@fortawesome/react-native-fontawesome": "^0.3.2",
|
|
36
|
-
"@planningcenter/emoji-keyboard": "4.4.1-qa-staging.
|
|
36
|
+
"@planningcenter/emoji-keyboard": "4.4.1-qa-staging.11",
|
|
37
37
|
"lodash-inflection": "^1.5.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sf-symbols-typescript": "^2.2.0",
|
|
85
85
|
"typescript": "~6.0.3"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "f32cabf4c0fcc893fd82b53d6b780bf1371a930b"
|
|
88
88
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderHook } from '@testing-library/react-native'
|
|
1
|
+
import { act, renderHook } from '@testing-library/react-native'
|
|
2
2
|
import type { ConversationResource } from '../../types'
|
|
3
3
|
import { useMarkLatestMessageRead } from '../use_mark_latest_message_read'
|
|
4
4
|
|
|
@@ -19,15 +19,29 @@ describe('useMarkLatestMessageRead', () => {
|
|
|
19
19
|
expect(mockMarkRead).toHaveBeenCalledTimes(1)
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
it('
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
it('marks read once on mount even while disabled', () => {
|
|
23
|
+
renderHook(() => useMarkLatestMessageRead({ conversation, messages: [], enabled: false }))
|
|
24
|
+
|
|
25
|
+
expect(mockMarkRead).toHaveBeenCalledTimes(1)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('ignores unread bumps while disabled and marks read once enabled', () => {
|
|
29
|
+
jest.useFakeTimers()
|
|
30
|
+
const { rerender } = renderHook<void, { conversation: ConversationResource; enabled: boolean }>(
|
|
31
|
+
props => useMarkLatestMessageRead({ ...props, messages: [] }),
|
|
32
|
+
{ initialProps: { conversation: { ...conversation, unreadCount: 0 }, enabled: false } }
|
|
26
33
|
)
|
|
27
|
-
expect(mockMarkRead).
|
|
34
|
+
expect(mockMarkRead).toHaveBeenCalledTimes(1)
|
|
28
35
|
|
|
29
|
-
rerender({ enabled:
|
|
36
|
+
rerender({ conversation: { ...conversation, unreadCount: 2 }, enabled: false })
|
|
37
|
+
act(() => jest.advanceTimersByTime(1000))
|
|
30
38
|
|
|
31
39
|
expect(mockMarkRead).toHaveBeenCalledTimes(1)
|
|
40
|
+
|
|
41
|
+
rerender({ conversation: { ...conversation, unreadCount: 2 }, enabled: true })
|
|
42
|
+
act(() => jest.advanceTimersByTime(1000))
|
|
43
|
+
|
|
44
|
+
expect(mockMarkRead).toHaveBeenCalledTimes(2)
|
|
45
|
+
jest.useRealTimers()
|
|
32
46
|
})
|
|
33
47
|
})
|
|
@@ -20,15 +20,16 @@ export function useMarkLatestMessageRead({ conversation, enabled = true }: Props
|
|
|
20
20
|
const unreadCount = conversation.unreadCount
|
|
21
21
|
const unreadReaction = conversation.unreadReaction
|
|
22
22
|
|
|
23
|
-
const shouldMarkRead =
|
|
23
|
+
const shouldMarkRead =
|
|
24
|
+
!firedOnce.current || (enabled && Boolean(unreadCount >= 1 || unreadReaction))
|
|
24
25
|
const appState = useAppState()
|
|
25
26
|
const isActive = appState === 'active'
|
|
26
27
|
|
|
27
28
|
useEffect(() => {
|
|
28
|
-
if (!
|
|
29
|
+
if (!isActive || !shouldMarkRead) return
|
|
29
30
|
|
|
30
31
|
firedOnce.current = true
|
|
31
32
|
|
|
32
33
|
debouncedMarkRead(true)
|
|
33
|
-
}, [debouncedMarkRead,
|
|
34
|
+
}, [debouncedMarkRead, isActive, shouldMarkRead, unreadReaction])
|
|
34
35
|
}
|