Author's Kudos of Current Post
I am trying to implement a kudos count of the author who wrote the current post in a board. Currently, whenever I make this call (Where max is equal to the number of posts in the board):
<#list 0..${max} as i>
kudos: ${rest("${id}/kudos/received/count").value}
</list>
It returns every post in the board and displays all of them for the author. I just want the kudos of the author of the post to be displayed. For instance, if i post in a board, I want my kudos to be displayed under my avatar and information, not everybody else's. Is there a rest call or any sort of Lithium call that I can make that will return that specific message and/or author?
Hi hobbs6487,
When your component is in the context of a message, you can use the env FreeMarker custom context object to obtain the user id of the message author:
env.context.message.author.id
Once you have the user's id, it's just a matter of sticking that in the appropriate REST API call to get the kudos count for that user, for example:
<#assign kudosCount = rest("/users/id/${env.context.message.author.id?c}/kudos/received/count").value!"0" />
Once you've assigned the value to a variable, you can manipulate it as needed, or just output it for display:
Kudos: ${kudosCount}
Some references you may find useful:
http://lithosphere.lithium.com/t5/Developer-Knowledge-Base/Context-objects-for-custom-components-env/ta-p/9321
http://lithosphere.lithium.com/t5/Lithium-Developers/Display-user-s-real-name-instead-of-user-handle/m-p/31323/highlight/true#M344I hope this helps!
-Adam