mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	@@ -4,6 +4,8 @@
 | 
			
		||||
package user
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/models/db"
 | 
			
		||||
	"code.gitea.io/gitea/modules/timeutil"
 | 
			
		||||
)
 | 
			
		||||
@@ -21,18 +23,18 @@ func init() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsFollowing returns true if user is following followID.
 | 
			
		||||
func IsFollowing(userID, followID int64) bool {
 | 
			
		||||
	has, _ := db.GetEngine(db.DefaultContext).Get(&Follow{UserID: userID, FollowID: followID})
 | 
			
		||||
func IsFollowing(ctx context.Context, userID, followID int64) bool {
 | 
			
		||||
	has, _ := db.GetEngine(ctx).Get(&Follow{UserID: userID, FollowID: followID})
 | 
			
		||||
	return has
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FollowUser marks someone be another's follower.
 | 
			
		||||
func FollowUser(userID, followID int64) (err error) {
 | 
			
		||||
	if userID == followID || IsFollowing(userID, followID) {
 | 
			
		||||
func FollowUser(ctx context.Context, userID, followID int64) (err error) {
 | 
			
		||||
	if userID == followID || IsFollowing(ctx, userID, followID) {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx, committer, err := db.TxContext(db.DefaultContext)
 | 
			
		||||
	ctx, committer, err := db.TxContext(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@@ -53,12 +55,12 @@ func FollowUser(userID, followID int64) (err error) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UnfollowUser unmarks someone as another's follower.
 | 
			
		||||
func UnfollowUser(userID, followID int64) (err error) {
 | 
			
		||||
	if userID == followID || !IsFollowing(userID, followID) {
 | 
			
		||||
func UnfollowUser(ctx context.Context, userID, followID int64) (err error) {
 | 
			
		||||
	if userID == followID || !IsFollowing(ctx, userID, followID) {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx, committer, err := db.TxContext(db.DefaultContext)
 | 
			
		||||
	ctx, committer, err := db.TxContext(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user