feat: enforce friend add and curfew policies
This commit is contained in:
@@ -3192,7 +3192,7 @@ func (a *adapter) ensureUserProfile(ctx context.Context, uid t.Uid) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := a.db.ExecContext(ctx, `INSERT IGNORE INTO im_user_profiles(id,user_id,public_account) VALUES(?,?,?)`, profileID, decodeUID(uid), uid.UserId()); err != nil {
|
||||
if _, err := a.db.ExecContext(ctx, `INSERT IGNORE INTO im_user_profiles(id,user_id,public_account,friend_add_enabled,friend_add_policy_version) VALUES(?,?,?,?,?)`, profileID, decodeUID(uid), uid.UserId(), true, 1); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -3885,35 +3885,41 @@ func (a *adapter) feedbackByIdempotency(ctx context.Context, uid t.Uid, idempote
|
||||
|
||||
func (a *adapter) userProfileByUID(ctx context.Context, uid t.Uid) (*t.UserProfile, error) {
|
||||
row := struct {
|
||||
UserID int64 `db:"user_id"`
|
||||
AvatarFileID string `db:"avatar_file_id"`
|
||||
Nickname string
|
||||
BirthDate sql.NullTime `db:"birth_date"`
|
||||
Signature string
|
||||
Gender string
|
||||
Region string
|
||||
Email string
|
||||
PublicAccount string `db:"public_account"`
|
||||
Version int
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
UserID int64 `db:"user_id"`
|
||||
AvatarFileID string `db:"avatar_file_id"`
|
||||
Nickname string
|
||||
BirthDate sql.NullTime `db:"birth_date"`
|
||||
Signature string
|
||||
Gender string
|
||||
Region string
|
||||
Email string
|
||||
PublicAccount string `db:"public_account"`
|
||||
FriendAddEnabled bool `db:"friend_add_enabled"`
|
||||
FriendAddDisabledReason string `db:"friend_add_disabled_reason"`
|
||||
FriendAddPolicyVersion int `db:"friend_add_policy_version"`
|
||||
Version int
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}{}
|
||||
if err := sqlx.GetContext(ctx, a.db, &row, `SELECT user_id,avatar_file_id,nickname,birth_date,signature,gender,region,email,
|
||||
public_account,version,created_at,updated_at FROM im_user_profiles WHERE user_id=?`, decodeUID(uid)); err != nil {
|
||||
public_account,friend_add_enabled,friend_add_disabled_reason,friend_add_policy_version,version,created_at,updated_at FROM im_user_profiles WHERE user_id=?`, decodeUID(uid)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
profile := &t.UserProfile{
|
||||
UserID: store.EncodeUid(row.UserID),
|
||||
AvatarFileID: row.AvatarFileID,
|
||||
Nickname: row.Nickname,
|
||||
Signature: row.Signature,
|
||||
Gender: row.Gender,
|
||||
Region: row.Region,
|
||||
Email: row.Email,
|
||||
PublicAccount: row.PublicAccount,
|
||||
Version: row.Version,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
UserID: store.EncodeUid(row.UserID),
|
||||
AvatarFileID: row.AvatarFileID,
|
||||
Nickname: row.Nickname,
|
||||
Signature: row.Signature,
|
||||
Gender: row.Gender,
|
||||
Region: row.Region,
|
||||
Email: row.Email,
|
||||
PublicAccount: row.PublicAccount,
|
||||
FriendAddEnabled: row.FriendAddEnabled,
|
||||
FriendAddDisabledReason: row.FriendAddDisabledReason,
|
||||
FriendAddPolicyVersion: row.FriendAddPolicyVersion,
|
||||
Version: row.Version,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
}
|
||||
if row.BirthDate.Valid {
|
||||
profile.BirthDate = row.BirthDate.Time.Format("2006-01-02")
|
||||
|
||||
Reference in New Issue
Block a user