Forum Discussion

jaread83's avatar
jaread83
Champion
8 years ago

Total Kudos Givers

Hi,

We recently implemented a rank that grants the user 2 points per kudos.

I have a component that is supposed to do a count of the amount of users and this worked fine until we granted the thanks weight.

I see it was answered in this post but the user had the exact same problem as me and noone came back to answer the OP:

https://community.lithium.com/t5/Developer-Discussion/Count-of-kudo-givers-to-a-particular-post/m-p/204236#M9166

So my question is basically the answer that was not given on the last reply in that thread. Is there a way to count the amount of kudos givers rather than the total points.

Thanks

  • jaread83 - Found two errors in your query . 

     

    <#assign kudosCount = rest(apiVersion,"/search?q=" + "SELECT * FROM kudos where message.id = messageId limit kudosCountFirst"?url).data.items![] />

     

    messageId and kudosCountFirst are treated as string as you must need to wrap freemaker variable with ${}. Second you need to wrap messageId in quotes.  

     

    Updated Query : 

    <#assign kudosCount = rest(apiVersion,"/search?q=" + "SELECT * FROM kudos where message.id = '${messageId}' limit ${kudosCountFirst}"?url).data.items![] />

     

    PS : I don't drink beer :smileyvery-happy:

     

    Give kudos if you find my posts helpful or mark solution if it answers your query.

    Tariq

     

  • jaread83 - LIQL doesn't support count(*) for KUDOS. It is not possible to achieve this using one query . 

     

    However you still can get the exact result . You will need to get the kudos count and pass it to the limit of next query as kudos count will always be greater than giver count. 

     

    /restapi/vc/messages/id/1894/kudos/count/
    select * from kudos where message.id = 'message.id' and limit <kudos count value>

    Let me know if this helps.

     

    Give kudos if you find my posts helpful or mark solution if it answers your query

    Tariq

     

     

    • jaread83's avatar
      jaread83
      Champion

      Hi TariqHussain, thanks for the advice. I have got it to half work but I need to convert the API v2 call to a number in order to apply some logic to it.

      Is there a way to convert it to a number so I can get the count?

      Basically, what I am trying to do is count the amount of kudos for a message, list the users who gave the kudos and cut it off at a specific number to add a 'and X amount of others'. Here is my code with your implementation:

       

      <#assign messageId = env.context.message.uniqueId />
      <#if messageId?? && messageId gt 0>
          <#assign apiVersion = "2.0"/>
          <#assign cutoff = 10 />
          <#assign counter = 0 />
          <#attempt>
              <#assign users = rest("/messages/id/${messageId}/kudos/givers?page_size=${cutoff}").users />
          <#recover>
              <#assign users = "" />
          </#attempt>
          <#attempt>
              <#assign kudosCountFirst = rest("/messages/id/${messageId}/kudos/count").value />
              <#assign kudosCount = rest(apiVersion,"/search?q=" + "SELECT * FROM kudos where message.id = messageId limit kudosCountFirst"?url).data.items![] />
          <#recover>
              <#assign kudosCountFirst = "" />
              <#assign kudosCount = "" />
          </#attempt>
          <#assign remaining = kudosCount?number - cutoff?number /> 
          <#if users??>
      <#if kudosCount?number gte 1 ><span class="kudosgivers hidden">${kudosCount} <#if kudosCount?number == 1>user<#else>users</#if> liked/thanked this post:
      <#list users.user as kudosGiver><#assign counter = counter+1 />${kudosGiver.login}<#if counter?number == cutoff?number && kudosCount?number gte cutoff?number+1>... and ${remaining} other <#if remaining == 1> user<#else>users</#if>. <#else><#if counter?number == kudosCount?number>. <#else>, </#if></#if></#list>
      <#if kudosCount?number gte cutoff?number+1 >Click the number to view who else liked/thanked this post.</#if></span></#if>
          </#if>
      </#if>

      I hope you sre able to help. This is a bit of a head scratcher for me at the moment.

      This is what the end result should look like:

      With the Kudos weight added for some users, this throws it all off though.

      • TariqHussain's avatar
        TariqHussain
        Boss

        jaread83 - Do you want to count the which that you are fetching from API V2? 

         

        You can use ?size context object to count the size of array .  

         

        <#assign remaining = kudosCount?size?number - cutoff?number /> 

        You can also achieve this with below code.

         

        <#assign kudosQuery = rest(apiVersion,"/search?q=" + "SELECT * FROM kudos where message.id = messageId limit kudosCountFirst"?url).data />
        <#assign kudoCount = kudosQuery.size />
        <#assign kudoResult = kudosQuery.items![] />

        Give kudos if you find my posts helpful or mark solution if it answers your query

        Tariq