Follow marks the user to follow the other user.
(ctx context.Context, userID, followID int64)
| 627 | |
| 628 | // Follow marks the user to follow the other user. |
| 629 | func (s *UsersStore) Follow(ctx context.Context, userID, followID int64) error { |
| 630 | if userID == followID { |
| 631 | return nil |
| 632 | } |
| 633 | |
| 634 | return s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { |
| 635 | f := &Follow{ |
| 636 | UserID: userID, |
| 637 | FollowID: followID, |
| 638 | } |
| 639 | result := tx.FirstOrCreate(f, f) |
| 640 | if result.Error != nil { |
| 641 | return errors.Wrap(result.Error, "upsert") |
| 642 | } else if result.RowsAffected <= 0 { |
| 643 | return nil // Relation already exists |
| 644 | } |
| 645 | |
| 646 | return s.recountFollows(tx, userID, followID) |
| 647 | }) |
| 648 | } |
| 649 | |
| 650 | // Unfollow removes the mark the user to follow the other user. |
| 651 | func (s *UsersStore) Unfollow(ctx context.Context, userID, followID int64) error { |