initializer.RegisterRpc("UpdateMetadata", func(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
userId, ok := ctx.Value(runtime.RUNTIME_CTX_USER_ID).(string)
if !ok {
return "", errors.New("could not get user ID from context")
}
if err := nk.AccountUpdateId(ctx, userId, "", map[string]interface{}{
"title": "Definitely Not The Imposter",
"hat": "space_helmet"
"skin": "alien"},
}, "", "", "", "", ""); err != nil {
return "", errors.New("could not update account")
}
// MY MODIFICATION
// and here I want to call something like
// rtClient->updateStatus("I have new metadata");
return "{}", nil
})
I’m still not sure what the intention of your proposed solution is but if you need to update the status of a user, it can be done on the client. It would add one RPC call but would also keep it simple in terms of server code since this feature (updateStatus) is already implemented on Nakama server and client libraries (no need for custom code).
I need to update my Metadata via RPC function “UpdateMetadata” like in my case above.
And when I update my data, I need every my friend (which follows me) gets the information like “your friend j4c0b updated his metadata”.
I think the best way is via Presence via updateStatus, which can be called from client. You are right.
But I want to do this in one step. I would like to call from client only RPC function “UpdateMetadata” which should call updateStatus(). But how I can get RealTimeClient in my RPC function in GO?
For me, it is much better than call 2 functions from client in callbacks like
Yes, you can invoke custom RPCs from the socket connection.
To use the Notifications API you need to know the users you want to send the data to. If this is all of your friends then you can use the runtime friend listing API and send the notifications with the persist flag to false, so only the ones that are connected to the socket will receive it and it won’t be stored for offline retrieval.
To send the status update from the server you’d need to use streams.