@@ -158,7 +158,7 @@ function generateDarkColorFromUsername(username) {
158158 * @param submindID - user id of submind
159159 * @param submindUserData - user data of submind
160160 * @param submindResponse - Responding data of submind to incoming prompt
161- * @param submindOpinions - Discussion data of submind to incoming prompt
161+ * @param submindOpinions - Discussion data of submind to incoming prompt, Dict or List[Dict]
162162 * @param submindVote - Vote data of submind in prompt
163163 * @param discussionRounds - number of discussion rounds (used for rendering)
164164 * @return {Promise<string|void> } - Submind Data HTML populated with provided data
@@ -183,8 +183,15 @@ async function buildSubmindHTML(promptID, submindID, submindUserData, submindRes
183183 let promptParticipantTemplate ;
184184 // Fallback to the single-discussion rounds
185185 if ( ! discussionRounds || discussionRounds === 1 ) {
186- phaseDataObjectMapping [ 'opinion' ] = submindOpinions ;
187- promptParticipantTemplate = 'prompt_participant'
186+ // Check if submindOpinions is an array and take the first element if it is.
187+ if ( Array . isArray ( submindOpinions ) ) {
188+ // Handles cases where multi-round discussion specifies 1 round
189+ phaseDataObjectMapping [ 'opinion' ] = submindOpinions [ 0 ] ;
190+ } else {
191+ // Handles backwards-compat. where only one discussion round was saved
192+ phaseDataObjectMapping [ 'opinion' ] = submindOpinions ;
193+ }
194+ promptParticipantTemplate = 'prompt_participant' ;
188195 } else {
189196 templateData [ 'submind_discussions' ] = buildSubmindDiscussionHTML ( promptID , userNickname , submindOpinions , discussionRounds ) ;
190197 promptParticipantTemplate = 'prompt_participant_multi_discussions'
@@ -340,15 +347,20 @@ async function buildPromptHTML(prompt) {
340347 try {
341348 const messageIds = promptData [ key ] ?. [ submindID ] ;
342349 if ( Array . isArray ( messageIds ) ) {
350+ // Handle `submind_discussion_history` which maps User UID to an array of message IDs
343351 data [ key ] = messageIds . map ( id => {
344352 const raw = prompt [ 'message_mapping' ] ?. [ id ] ?. [ 0 ] ;
353+ if ( ! raw ) {
354+ console . warn ( `Message ID ${ id } not found in message_mapping for key ${ key } ` ) ;
355+ }
345356 return raw ? { ...raw , message_id : id } : { message_text : emptyAnswer } ;
346357 } ) ;
347358 } else {
348359 const id = messageIds ;
349360 const raw = prompt [ 'message_mapping' ] ?. [ id ] ?. [ 0 ] ;
350361 data [ key ] = raw ? { ...raw , message_id : id } : { message_text : emptyAnswer } ;
351362 }
363+ console . debug ( `Fetched data for key ${ key } and submindID ${ submindID } :` , data [ key ] ) ;
352364 } catch ( e ) {
353365 data [ key ] = Array . isArray ( promptData [ key ] ?. [ submindID ] )
354366 ? promptData [ key ] [ submindID ] . map ( ( ) => ( { message_text : emptyAnswer } ) )
0 commit comments