One more quick comment.
I noticed that, in our communities, I was getting an "permission denied" error when replying to a reply -not the original question-, probably because the custom field was set up for just for first message in a thread. I'm not 100% sure.
Anyways, we want to keep a single list for the whole thread, regardless of whether the user replied to the original question or a reply, so I tweaked the code a little.
I replaced these two lines
<#assign msg_non_unique_id = http.request.url?substring(http.request.url?last_index_of("/") + 1, http.request.url?length)/>
<#assign msg_id = rest("/boards/id/${coreNode.id}/messages/id/${msg_non_unique_id}/id").value/>
With this:
<#assign msg_id = env.context.message.discussion.topicMessage.uniqueId />
(this gets the unique id for the first message on the thread, so no need to use another rest call)
Just an FYI in case you're having the same issue on your communities.
Regards!