Adding Friends Server side

I have an interesting requirement - all new users need to be friends with a key user - they can block them in the future if required and they need to be listed as a normal friend for all other purposes.

If I use the client side API calls then this ‘default friend’ will need to accept all the invitations. Is it possible to add a friend on account creation? I have a hook registered for this but I can’t find supporting methods in the runtime to do this.

I’m hoping there is a better way than inserting records in via SQL but can do if need be.

If I do need to delve into the SQL and write to user_edge what needs writing into the “position” column and does the reciprocal record also need to be entered (with source_id and destination_id swapped) or is the state suitable in a single row?

Hello @DigNZ, the right way to do this would be to expose the FriendsAdd function to the runtimes, this way you could use your account creation hook to call this new function to create the friend request from the new user and then accept it on behalf of the key user. Could you please open an issue with a feature request?

In the meantime, you’d achieve automatically accepting this key user pending friend invitation using the following query:

UPDATE user_edge SET state = 0, update_time = now()
WHERE (source_id = $1 AND destination_id = $2 AND state = 1)
OR (source_id = $2 AND destination_id = $1 AND state = 2)`

Where $1 is the userID of the user who requested the friendship and $2 is the userID of the key user.

Hope this helps

That is great thanks