From ead1db2be8f7bc46c9ce60e7be24acb946a626e0 Mon Sep 17 00:00:00 2001 From: bytedream Date: Thu, 23 Jun 2022 16:50:48 +0200 Subject: [PATCH] Add function to check if a comment is liked by the logged-in user --- comment.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/comment.go b/comment.go index 47005cf..762b57b 100644 --- a/comment.go +++ b/comment.go @@ -143,6 +143,16 @@ func (c *Comment) Like() error { return nil } +// Liked returns if the user has liked the comment. +func (c *Comment) Liked() bool { + for _, flag := range c.Flags { + if flag == "liked" { + return true + } + } + return false +} + // RemoveLike removes the like from the comment. Works only if the user has liked it. func (c *Comment) RemoveLike() error { if err := c.unVote("like", "liked"); err != nil {