Skip to content

Commit 7730d1f

Browse files
committed
fix: resolve out of sync messages in useChatSession by accessing it from the store directly
1 parent 0c484bd commit 7730d1f

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/components/Message/Message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export const Message = React.memo(
229229
/>
230230
<Pressable
231231
onLongPress={event => {
232-
ReactNativeHapticFeedback.trigger('impactMedium', hapticOptions);
232+
ReactNativeHapticFeedback.trigger('impactLight', hapticOptions);
233233
onMessageLongPress?.(excludeDerivedMessageProps(message), event);
234234
}}
235235
onPress={event => {

src/hooks/__tests__/useChatSession.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('useChatSession', () => {
4040

4141
it('should send a message and update the chat session', async () => {
4242
const {result} = renderHook(() =>
43-
useChatSession({current: null}, [], textMessage.author, mockAssistant),
43+
useChatSession({current: null}, textMessage.author, mockAssistant),
4444
);
4545

4646
await act(async () => {
@@ -54,7 +54,7 @@ describe('useChatSession', () => {
5454
it('should handle model not loaded scenario', async () => {
5555
modelStore.context = undefined;
5656
const {result} = renderHook(() =>
57-
useChatSession({current: null}, [], textMessage.author, assistant),
57+
useChatSession({current: null}, textMessage.author, assistant),
5858
);
5959

6060
await act(async () => {
@@ -81,7 +81,7 @@ describe('useChatSession', () => {
8181
}
8282

8383
const {result} = renderHook(() =>
84-
useChatSession({current: null}, [], textMessage.author, mockAssistant),
84+
useChatSession({current: null}, textMessage.author, mockAssistant),
8585
);
8686

8787
await act(async () => {
@@ -110,7 +110,7 @@ describe('useChatSession', () => {
110110
}
111111

112112
const {result} = renderHook(() =>
113-
useChatSession({current: null}, [], textMessage.author, mockAssistant),
113+
useChatSession({current: null}, textMessage.author, mockAssistant),
114114
);
115115

116116
await act(async () => {
@@ -150,7 +150,7 @@ describe('useChatSession', () => {
150150

151151
it('should reset the conversation', () => {
152152
const {result} = renderHook(() =>
153-
useChatSession({current: null}, [], textMessage.author, mockAssistant),
153+
useChatSession({current: null}, textMessage.author, mockAssistant),
154154
);
155155

156156
result.current.handleResetConversation();
@@ -165,7 +165,7 @@ describe('useChatSession', () => {
165165

166166
it('should not stop completion when inferencing is false', () => {
167167
const {result} = renderHook(() =>
168-
useChatSession({current: null}, [], textMessage.author, mockAssistant),
168+
useChatSession({current: null}, textMessage.author, mockAssistant),
169169
);
170170

171171
result.current.handleStopPress();
@@ -186,7 +186,7 @@ describe('useChatSession', () => {
186186
}
187187

188188
const {result} = renderHook(() =>
189-
useChatSession({current: null}, [], textMessage.author, mockAssistant),
189+
useChatSession({current: null}, textMessage.author, mockAssistant),
190190
);
191191

192192
const sendPromise = act(async () => {
@@ -232,7 +232,7 @@ describe('useChatSession', () => {
232232
modelStore.setActiveModel(testModel.id);
233233

234234
const {result} = renderHook(() =>
235-
useChatSession({current: null}, [], textMessage.author, mockAssistant),
235+
useChatSession({current: null}, textMessage.author, mockAssistant),
236236
);
237237

238238
await act(async () => {

src/hooks/useChatSession.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export const useChatSession = (
1414
createdAt: number;
1515
id: string;
1616
} | null>,
17-
messages: MessageType.Any[],
1817
user: User,
1918
assistant: User,
2019
) => {
@@ -101,7 +100,9 @@ export const useChatSession = (
101100
: []),
102101
...convertToChatMessages([
103102
textMessage,
104-
...messages.filter(msg => msg.id !== textMessage.id),
103+
...chatSessionStore.currentSessionMessages.filter(
104+
msg => msg.id !== textMessage.id,
105+
),
105106
]),
106107
];
107108

src/screens/ChatScreen/ChatScreen.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ export const ChatScreen: React.FC = observer(() => {
3939
null,
4040
);
4141
const l10n = React.useContext(L10nContext);
42-
const messages = chatSessionStore.currentSessionMessages;
4342

4443
const {handleSendPress, handleStopPress} = useChatSession(
4544
currentMessageInfo,
46-
messages,
4745
user,
4846
assistant,
4947
);
@@ -60,7 +58,7 @@ export const ChatScreen: React.FC = observer(() => {
6058
: undefined
6159
}
6260
renderBubble={renderBubble}
63-
messages={messages}
61+
messages={chatSessionStore.currentSessionMessages}
6462
onSendPress={handleSendPress}
6563
onStopPress={handleStopPress}
6664
user={user}

0 commit comments

Comments
 (0)