Skip to content

Commit

Permalink
Allow creator to bypass reply blocking on their own content
Browse files Browse the repository at this point in the history
  • Loading branch information
miko committed Jan 18, 2025
1 parent 45986a5 commit 9adc151
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
13 changes: 12 additions & 1 deletion helper/moderation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ import (

"github.com/lbryio/lbry.go/v2/extras/api"
"github.com/lbryio/lbry.go/v2/extras/errors"
"github.com/lbryio/lbry.go/v2/extras/jsonrpc"

"github.com/volatiletech/null/v8"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
)

// AllowedToRespond checks if the creator of the comment will allow a response from the respondent
func AllowedToRespond(parentCommentID, commenterClaimID string) error {
func AllowedToRespond(parentCommentID, commenterClaimID, contentClaimID string, GetSigningChannelForClaim func(string) (*jsonrpc.Claim, error)) error {
contentCreatorChannel, err := GetSigningChannelForClaim(contentClaimID)
if err != nil {
return errors.Err(err)
}
if contentCreatorChannel != nil {
isCreator := commenterClaimID == contentCreatorChannel.ClaimID
if isCreator {
return nil
}
}
parentComment, err := m.Comments(m.CommentWhere.CommentID.EQ(parentCommentID)).One(db.RO)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return errors.Err(err)
Expand Down
2 changes: 1 addition & 1 deletion server/services/v1/comments/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func checkAllowedAndValidate(request *createRequest) error {
}

if request.args.ParentID != nil {
err = helper.AllowedToRespond(util.StrFromPtr(request.args.ParentID), request.args.ChannelID)
err = helper.AllowedToRespond(util.StrFromPtr(request.args.ParentID), request.args.ChannelID, request.args.ClaimID, lbry.SDK.GetSigningChannelForClaim)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion server/services/v2/reactions/react.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/OdyseeTeam/commentron/helper"
"github.com/OdyseeTeam/commentron/model"
"github.com/OdyseeTeam/commentron/server/auth"
"github.com/OdyseeTeam/commentron/server/lbry"
"github.com/OdyseeTeam/commentron/sockety"

"github.com/OdyseeTeam/sockety/socketyapi"
Expand Down Expand Up @@ -112,7 +113,7 @@ func updateReactions(channel *model.Channel, args *commentapi.ReactArgs, comment
return errors.Err(err)
}
for _, p := range comments {
err = helper.AllowedToRespond(p.CommentID, channel.ClaimID)
err = helper.AllowedToRespond(p.CommentID, channel.ClaimID, p.LbryClaimID, lbry.SDK.GetSigningChannelForClaim)
if err != nil {
return err
}
Expand Down

0 comments on commit 9adc151

Please sign in to comment.