// Check to see if user has already blocked friend, if so, don't add friend or send notification.
varblockStateint
err:=tx.QueryRowContext(ctx,"SELECT state FROM user_edge WHERE source_id = $1 AND destination_id = $2 AND state = 3",userID,id).Scan(&blockState)
// ignore if the error is sql.ErrNoRows as means block was not found - continue as intended.
iferr!=nil&&err!=sql.ErrNoRows{
// genuine DB error was found.
logger.Debug("Failed to check edge state.",zap.Error(err),zap.String("user",userID.String()),zap.String("friend",id))
returnerr
}elseiferr==nil{
// the block was found, don't add friend or send notification.
logger.Info("Ignoring previously blocked friend. Delete friend first before attempting to add.",zap.String("user",userID.String()),zap.String("friend",id))
// Check to see if user has already blocked friend, if so ignore.
varblockStateint
err:=tx.QueryRowContext(ctx,"SELECT state FROM user_edge WHERE source_id = $1 AND destination_id = $2 AND state = 3",userID,friendID).Scan(&blockState)
// ignore if the error is sql.ErrNoRows as means block was not found - continue as intended.
iferr!=nil&&err!=sql.ErrNoRows{
// genuine DB error was found.
logger.Debug("Failed to check edge state.",zap.Error(err),zap.String("user",userID.String()),zap.String("friend",friendID))
returnfalse,err
}elseiferr==nil{
// the block was found, return early.
logger.Info("Ignoring previously blocked friend. Delete friend first before attempting to add.",zap.String("user",userID.String()),zap.String("friend",friendID))
returnfalse,nil
}
// Mark an invite as accepted, if one was in place.
res,err:=tx.ExecContext(ctx,`
UPDATE user_edge SET state = 0, update_time = now()