🐛 Fix create duplicate relationship

This commit is contained in:
2025-02-15 16:00:01 +08:00
parent a08372d4d2
commit 497c0692ca
3 changed files with 23 additions and 8 deletions

View File

@ -112,6 +112,20 @@ func NewFriend(userA models.Account, userB models.Account, skipPending ...bool)
Status: models.RelationshipPending,
}
var dupeCount int
if rel, err := GetRelationWithTwoNode(userA.ID, userB.ID, true); err == nil {
relA = rel
dupeCount++
}
if rel, err := GetRelationWithTwoNode(userB.ID, userA.ID, true); err == nil {
relB = rel
dupeCount++
}
if dupeCount > 1 {
return relA, fmt.Errorf("unable to recreate a relationship with that user")
}
if len(skipPending) > 0 && skipPending[0] {
relA.Status = models.RelationshipFriend
relB.Status = models.RelationshipFriend