From 8c77e047a07db75182e71f8af821f0d93962d8ca Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Tue, 8 Oct 2024 18:58:46 -0400 Subject: [PATCH] fix: check expiry on replies Replies would get blocked even though the block expired --- helper/moderation.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/helper/moderation.go b/helper/moderation.go index 3f51f66..c003b54 100644 --- a/helper/moderation.go +++ b/helper/moderation.go @@ -2,12 +2,15 @@ package helper import ( "database/sql" + "fmt" "net/http" + "time" "github.com/OdyseeTeam/commentron/db" "github.com/OdyseeTeam/commentron/model" m "github.com/OdyseeTeam/commentron/model" + "github.com/lbryio/commentron/helper" "github.com/lbryio/lbry.go/v2/extras/api" "github.com/lbryio/lbry.go/v2/extras/errors" @@ -27,7 +30,6 @@ func AllowedToRespond(parentCommentID, commenterClaimID string) error { return errors.Err(err) } if parentChannel != nil { - blockedEntry, err := m.BlockedEntries( m.BlockedEntryWhere.CreatorChannelID.EQ(null.StringFrom(parentChannel.ClaimID)), m.BlockedEntryWhere.BlockedChannelID.EQ(null.StringFrom(commenterClaimID))).One(db.RO) @@ -35,7 +37,14 @@ func AllowedToRespond(parentCommentID, commenterClaimID string) error { return errors.Err(err) } if blockedEntry != nil { - return api.StatusError{Err: errors.Err("'%s' has blocked you from replying to their comments", parentChannel.Name), Status: http.StatusBadRequest} + if !blockedEntry.Expiry.Valid { + return api.StatusError{Err: errors.Err("'%s' has blocked you from replying to their comments", parentChannel.Name), Status: http.StatusBadRequest} + } else if time.Now().Before(blockedEntry.Expiry.Time) { + timeLeft := helper.FormatDur(blockedEntry.Expiry.Time.Sub(time.Now())) + message := fmt.Sprintf("'%s' has temporarily blocked you from replying to their comments for %s", parentChannel.Name, timeLeft) + return api.StatusError{Err: errors.Err(message), Status: http.StatusBadRequest} + } + // If we reach here, the block has expired, so we continue as normal } } }