Skip to content

Commit 6608e7b

Browse files
committed
fix: reconcile own_votes properly
1 parent c997068 commit 6608e7b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

package/src/store/apis/updateMessage.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ export const updateMessage = ({
3030
return queries;
3131
}
3232

33-
const { poll, poll_id } = messages[0];
34-
3533
const storableMessage = mapMessageToStorable({
36-
...(poll ? { poll: JSON.parse(poll) } : {}),
37-
...(poll_id ? { poll_id } : {}),
3834
...message,
3935
});
4036

package/src/store/apis/updatePollMessage.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PollResponse } from 'stream-chat';
22

33
import { mapPollToStorable } from '../mappers/mapPollToStorable';
4+
import { mapStorableToPoll } from '../mappers/mapStorableToPoll';
45
import { QuickSqliteClient } from '../QuickSqliteClient';
56
import { createSelectQuery } from '../sqlite-utils/createSelectQuery';
67
import { createUpdateQuery } from '../sqlite-utils/createUpdateQuery';
@@ -23,14 +24,17 @@ export const updatePollMessage = ({
2324
);
2425

2526
for (const pollFromDB of pollsFromDB) {
26-
const { latest_votes, own_votes } = pollFromDB;
27+
const serializedPoll = mapStorableToPoll(pollFromDB);
28+
const { latest_votes, own_votes } = serializedPoll;
2729
console.log(own_votes);
2830
const storablePoll = mapPollToStorable({
29-
...pollFromDB,
30-
latest_votes: latest_votes ? JSON.parse(latest_votes) : [],
31-
own_votes: own_votes ? JSON.parse(own_votes) : [],
31+
...poll,
32+
// latest_votes: latest_votes ?? [],
33+
// own_votes: own_votes ?? [],
3234
});
3335

36+
console.log('STORABLE POLL: ', storablePoll);
37+
3438
queries.push(
3539
createUpdateQuery('poll', storablePoll, {
3640
id: poll.id,

0 commit comments

Comments
 (0)