Forum Discussion

Han's avatar
Han
Ace
7 years ago

Add Message body to KudosMessagePage

I am trying to display the kudoed message body on the KudosMessagePage.

I am assuming that there must be a way to access the message ID from the page, as it is in the url and has a link to the message.  I have tried to access the message ID with the context objects, but it is returning null.

Does anyone know how to get the id of the kudoed message?

  • Han

    Use this updated code to fetch the board-id and message-id of the kudoed message

    <#assign urlList = http.request.url?split("/") />
    <#assign message_id = "" /> 
    <#assign board_id = "" /> 
    <#list urlList as url_split>
        <#if url_split_index gt 0 && urlList[url_split_index - 1] == "board-id">        
            <#assign board_id = url_split />
        </#if>
        <#if url_split_index gt 0 && urlList[url_split_index - 1] == "message-id">        
            <#assign message_id = url_split />
        </#if>
    </#list>
    ${board_id}-${message_id}

    After this use V1 to add these values to below API like this:

    https://saneforums.org/restapi/vc/boards/id/${board_id}/messages/id/${message_id}

    API will look like in your results:

    https://saneforums.org/restapi/vc/boards/id/le-forum-0001/messages/id/65820

    and here is the response to your community API where you can get the body of the kudoed message.

    <response status="success">
    	<message type="message" href="/messages/id/546612">
    		<root type="message" href="/messages/id/546612"/>
    		<canonical_url type="string" null="true"/>
    		<post_time type="date_time">2018-07-21T08:24:26+00:00</post_time>
    		<last_edit_time type="date_time">2018-07-21T08:24:26+00:00</last_edit_time>
    		<board_id type="int">65820</board_id>
    		<views>
    			<count type="int">124</count>
    		</views>
    		<parent type="message" null="true"/>
    		<body type="string">
    			<P>today i had someone say to me " one day everything will be normal for you again"&nbsp;</P>
    			<P>While at that time it sounded good to hear , i then walked away thinking about it..&nbsp;</P>
    			<P>What is normal for me?&nbsp;</P>
    			<P>If i go by these last 6 yrs normal has been having 2 different minds control me more than it ever had before and me thinking that hearing another u in your head was something everyone had but no one talked about,&nbsp; normal was thinking i was sick and dying from something that turns out i didnt even have. Normal was having 100's of friends and family that i could call or text and see whenever possible... But since finding out that my "normal" was no where near what people would call "normal" has come out i've lost that me... Dont get me wrong, part of me is glad that i am free from hiding that part of me, but since it has all come to surface its like theres another me.&nbsp;</P>
    			<P>This new me is always watching her back, she doesnt sleep alot, she struggles to get out of bed everyday, she has no job, and very little friends and maybe only a hand full of family that talk to her.she isnt that confident well spoken person that im used to and its really hard to understand this new me...&nbsp;</P>
    			<P>I miss so many people that were in my life, but i dont blame them for turning away from me, most dont even understand whats really going on with me to be able to even try know why what has happened did happen.. I wish i could change so many things, but i cant, all i can do is try to help me be better. i wish those i cant talk to or see could see this and know that im sorry for that has happened, but it was something i could not control. i wish they knew the pain i feel every single day and night and how much i wish i could change it all, but sadly i cant....&nbsp;</P>
    			<P>there is no such as normal for me, i just hope that one day i find what it is really like..&nbsp;</P>
    		</body>
    		<thread type="thread" href="/threads/id/546612"/>
    		<teaser type="string"/>
    		<board type="board" href="/boards/id/le-forum-0001"/>
    		<subject type="string">What is normal??</subject>
    		<id type="int">546612</id>
    		<read_only type="boolean">false</read_only>
    		<message_rating type="float">0.0</message_rating>
    		<last_edit_author type="user" href="/users/id/11734">
    			<login type="string">melq83</login>
    		</last_edit_author>
    		<kudos>
    			<count type="int">3</count>
    		</kudos>
    		<labels/>
    		<seo_title type="string" null="true"/>
    		<seo_description type="string" null="true"/>
    		<deleted type="boolean">false</deleted>
    		<author type="user" href="/users/id/11734">
    			<login type="string">melq83</login>
    		</author>
    	</message>
    </response>
  • Han,

    Use below code to get Message ID of the kudoed message.

    <#assign urlList = http.request.url?split("/") />
    <#assign message_id = "" /> 
    <#list urlList as url_split>
        <#if url_split_index gt 0 && urlList[url_split_index - 1] == "message-id">        
            <#assign message_id = url_split />
        </#if>
    </#list>
    ${message_id}
    • Han's avatar
      Han
      Ace

      Parshant Thanks for your answer. This pulls the id from the url. Which is not actually the correct id. 

      The 'message-summary' component that is already on the page has the correct id, and links to the correct message. But I am not sure of a way to retrieve it from the anchor, or how to find out what variables I have available on the page as it may be in one of them already since it's being used.