@@ -8,7 +8,8 @@ import type { DefaultStreamChatGenerics } from '../../types/types';
88import { isBlockedMessage } from '../../utils/utils' ;
99import { mapStorableToMessage } from '../mappers/mapStorableToMessage' ;
1010import { QuickSqliteClient } from '../QuickSqliteClient' ;
11- import type { TableRowJoinedUser } from '../types' ;
11+ import { createSelectQuery } from '../sqlite-utils/createSelectQuery' ;
12+ import type { TableRow , TableRowJoinedUser } from '../types' ;
1213
1314export const getChannelMessages = <
1415 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics ,
@@ -35,6 +36,21 @@ export const getChannelMessages = <
3536 }
3637 messageIdVsReactions [ reaction . messageId ] . push ( reaction ) ;
3738 } ) ;
39+ const messageIdsVsPolls : Record < string , TableRow < 'poll' > > = { } ;
40+ const pollsById : Record < string , TableRow < 'poll' > > = { } ;
41+ const messagesWithPolls = messageRows . filter ( ( message ) => ! ! message . poll_id ) ;
42+ const polls = QuickSqliteClient . executeSql . apply (
43+ null ,
44+ createSelectQuery ( 'poll' , [ '*' ] , {
45+ id : messagesWithPolls . map ( ( message ) => message . poll_id ) ,
46+ } ) ,
47+ ) ;
48+ polls . forEach ( ( poll ) => {
49+ pollsById [ poll . id ] = poll ;
50+ } ) ;
51+ messagesWithPolls . forEach ( ( message ) => {
52+ messageIdsVsPolls [ message . poll_id ] = pollsById [ message . poll_id ] ;
53+ } ) ;
3854
3955 // Populate the messages.
4056 const cidVsMessages : Record < string , MessageResponse < StreamChatGenerics > [ ] > = { } ;
@@ -48,6 +64,7 @@ export const getChannelMessages = <
4864 mapStorableToMessage < StreamChatGenerics > ( {
4965 currentUserId,
5066 messageRow : m ,
67+ pollRow : messageIdsVsPolls [ m . poll_id ] ,
5168 reactionRows : messageIdVsReactions [ m . id ] ,
5269 } ) ,
5370 ) ;
0 commit comments