MCPcopy Create free account
hub / github.com/gogs/gogs / Follow

Method Follow

internal/database/users.go:629–648  ·  view source on GitHub ↗

Follow marks the user to follow the other user.

(ctx context.Context, userID, followID int64)

Source from the content-addressed store, hash-verified

627
628// Follow marks the user to follow the other user.
629func (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.
651func (s *UsersStore) Unfollow(ctx context.Context, userID, followID int64) error {

Callers 8

usersDeleteByIDFunction · 0.80
usersListFollowersFunction · 0.80
usersListFollowingsFunction · 0.80
usersFollowFunction · 0.80
usersIsFollowingFunction · 0.80
usersUnfollowFunction · 0.80
ActionFunction · 0.80
FollowFunction · 0.80

Calls 1

recountFollowsMethod · 0.95

Tested by 6

usersDeleteByIDFunction · 0.64
usersListFollowersFunction · 0.64
usersListFollowingsFunction · 0.64
usersFollowFunction · 0.64
usersIsFollowingFunction · 0.64
usersUnfollowFunction · 0.64