36 lines
893 B
Go
36 lines
893 B
Go
// Copyright 2023 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package user
|
|
|
|
import (
|
|
"context"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
)
|
|
|
|
// BlockedUser represents a blocked user entry.
|
|
type BlockedUser struct {
|
|
ID int64 `xorm:"pk autoincr"`
|
|
// UID of the one who got blocked.
|
|
BlockID int64 `xorm:"index"`
|
|
// UID of the one who did the block action.
|
|
UserID int64 `xorm:"index"`
|
|
}
|
|
|
|
func init() {
|
|
db.RegisterModel(new(BlockedUser))
|
|
}
|
|
|
|
// IsBlocked returns if userID has blocked blockID.
|
|
func IsBlocked(ctx context.Context, userID, blockID int64) bool {
|
|
has, _ := db.GetEngine(ctx).Get(&BlockedUser{UserID: userID, BlockID: blockID})
|
|
return has
|
|
}
|
|
|
|
// UnblockUser removes the blocked user entry.
|
|
func UnblockUser(ctx context.Context, userID, blockID int64) error {
|
|
_, err := db.GetEngine(ctx).Delete(&BlockedUser{UserID: userID, BlockID: blockID})
|
|
return err
|
|
}
|