Skip to content

Commit

Permalink
fix: check expiry on replies
Browse files Browse the repository at this point in the history
Replies would get blocked even though the block expired
  • Loading branch information
tzarebczan committed Oct 8, 2024
1 parent 8aa1adc commit 8c77e04
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions helper/moderation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -27,15 +30,21 @@ 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)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
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
}
}
}
Expand Down

0 comments on commit 8c77e04

Please sign in to comment.