diff --git a/CHANGELOG.md b/CHANGELOG.md index 9eb29342b7b9db1b7fdf05aa6f50699a0a7db150..3e7194f5945bc7e0fddb5e9de70e0a6c4017afcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr - Improve Stackdriver log format timestamp and message field formats. - Use crypto random to seed global random instance if possible. - Allow migrate subcommand to use database names that contain dashes. +- Add senderID param to channelIdBuild function. ### Fixed - Fix the registered function name for 'nk.channelIdBuild' in the JavaScript runtime. diff --git a/docker-compose-postgres.yml b/docker-compose-postgres.yml index eab5b1bdc9d609901e036a31eeb085e26f2d3b45..ed8c7dcb3398c33c4042cd5e6a6ff995ec154278 100644 --- a/docker-compose-postgres.yml +++ b/docker-compose-postgres.yml @@ -2,7 +2,7 @@ version: '3' services: postgres: container_name: postgres - image: postgres:9.6-alpine + image: postgres:12.2-alpine environment: - POSTGRES_DB=nakama - POSTGRES_PASSWORD=localdb diff --git a/go.mod b/go.mod index 1888d510e5ac2e9439680871a25a6b240523d1de..15f18d5cab643bbc6b9ae6d50c7f8afe38b64317 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.4.2 github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 - github.com/heroiclabs/nakama-common v1.21.1-0.20220117102903-bc0471af4fe1 + github.com/heroiclabs/nakama-common v1.21.1-0.20220225112712-3adfceaba805 github.com/jackc/pgconn v1.10.0 github.com/jackc/pgerrcode v0.0.0-20201024163028-a0d42d470451 github.com/jackc/pgtype v1.8.1 @@ -76,5 +76,3 @@ require ( gopkg.in/gorp.v1 v1.7.2 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) - -replace github.com/heroiclabe/nakama-common => ../nakama-common diff --git a/go.sum b/go.sum index ee18fc72e46b3f18b3492715c5f7388f8b47112b..43bcb0586a254d037368124faa3d8adfb02566cf 100644 --- a/go.sum +++ b/go.sum @@ -257,6 +257,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/heroiclabs/nakama-common v1.21.1-0.20220117102903-bc0471af4fe1 h1:x/dBIoeLjzb8PnCbrOsVEda8AJy+kmWj/zRTVkO9mc8= github.com/heroiclabs/nakama-common v1.21.1-0.20220117102903-bc0471af4fe1/go.mod h1:WF4YG46afwY3ibzsXnkt3zvhQ3tBY03IYeU7xSLr8HE= +github.com/heroiclabs/nakama-common v1.21.1-0.20220225112712-3adfceaba805 h1:GxmEr5fxdNEamOJmCPeUYdJvMQsJJJNZnBnkBmJxG9M= +github.com/heroiclabs/nakama-common v1.21.1-0.20220225112712-3adfceaba805/go.mod h1:WF4YG46afwY3ibzsXnkt3zvhQ3tBY03IYeU7xSLr8HE= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= diff --git a/server/runtime_go_nakama.go b/server/runtime_go_nakama.go index e971fc224b41fa7aad486d952e194d450e1cd1c0..eb5c43eb5c9b8e7bb88072cf353808d181293bf9 100644 --- a/server/runtime_go_nakama.go +++ b/server/runtime_go_nakama.go @@ -3456,12 +3456,22 @@ func (n *RuntimeGoNakamaModule) ChannelMessageUpdate(ctx context.Context, channe // @group chat // @summary Create a channel identifier to be used in other runtime calls. Does not create a channel. // @param ctx(type=context.Context) The context object represents information about the server and requester. +// @param senderId(type=string) UserID of the message sender (when applicable). An empty string defaults to the system user. // @param target(type=string) Can be the room name, group identifier, or another username. // @param chanType(type=runtime.ChannelType) The type of channel, for example group or direct. // @return channelId(string) The generated ID representing a channel. // @return error(error) An optional error value if an error occurred. -func (n *RuntimeGoNakamaModule) ChannelIdBuild(ctx context.Context, target string, chanType runtime.ChannelType) (string, error) { - channelId, _, err := BuildChannelId(ctx, n.logger, n.db, uuid.Nil, target, rtapi.ChannelJoin_Type(chanType)) +func (n *RuntimeGoNakamaModule) ChannelIdBuild(ctx context.Context, senderId, target string, chanType runtime.ChannelType) (string, error) { + senderUUID := uuid.Nil + if senderId != "" { + var err error + senderUUID, err = uuid.FromString(senderId) + if err != nil { + return "", err + } + } + + channelId, _, err := BuildChannelId(ctx, n.logger, n.db, senderUUID, target, rtapi.ChannelJoin_Type(chanType)) if err != nil { return "", err } diff --git a/server/runtime_javascript_nakama.go b/server/runtime_javascript_nakama.go index 9ccd65a25380e88741a0dafa159426edfc09e86e..5b4652cce6a01df3883f01546b18f4cadb679f02 100644 --- a/server/runtime_javascript_nakama.go +++ b/server/runtime_javascript_nakama.go @@ -7149,20 +7149,32 @@ func (n *runtimeJavascriptNakamaModule) channelMessageUpdate(r *goja.Runtime) fu // @group chat // @summary Create a channel identifier to be used in other runtime calls. Does not create a channel. +// @param senderId(type=string) UserID of the message sender (when applicable). Defaults to the system user if void. // @param target(type=string) Can be the room name, group identifier, or another username. // @param chanType(type=nkruntime.ChannelType) The type of channel, for example group or direct. // @return channelId(string) The generated ID representing a channel. // @return error(error) An optional error value if an error occurred. func (n *runtimeJavascriptNakamaModule) channelIdBuild(r *goja.Runtime) func(goja.FunctionCall) goja.Value { return func(f goja.FunctionCall) goja.Value { - target := getJsString(r, f.Argument(0)) + senderID := uuid.Nil + senderIDIn := f.Argument(0) + if senderIDIn != goja.Undefined() && senderIDIn != goja.Null() { + senderIDStr := getJsString(r, senderIDIn) + senderUUID, err := uuid.FromString(senderIDStr) + if err != nil { + panic(r.NewTypeError("expects sender id to be valid identifier")) + } + senderID = senderUUID + } + + target := getJsString(r, f.Argument(1)) - chanType := getJsInt(r, f.Argument(1)) + chanType := getJsInt(r, f.Argument(2)) if chanType < 1 || chanType > 3 { panic(r.NewTypeError("invalid channel type: expects value 1-3")) } - channelId, _, err := BuildChannelId(context.Background(), n.logger, n.db, uuid.Nil, target, rtapi.ChannelJoin_Type(chanType)) + channelId, _, err := BuildChannelId(context.Background(), n.logger, n.db, senderID, target, rtapi.ChannelJoin_Type(chanType)) if err != nil { if errors.Is(err, runtime.ErrInvalidChannelTarget) || errors.Is(err, runtime.ErrInvalidChannelType) { panic(r.NewTypeError(err.Error())) diff --git a/server/runtime_lua_nakama.go b/server/runtime_lua_nakama.go index fa918551d42887cdb3164bc1a06a5f9a1e2fd3cd..3c7c2733f5aeac8519bc139891dc708585398ae1 100644 --- a/server/runtime_lua_nakama.go +++ b/server/runtime_lua_nakama.go @@ -8706,21 +8706,33 @@ func (n *RuntimeLuaNakamaModule) channelMessageUpdate(l *lua.LState) int { // @group chat // @summary Create a channel identifier to be used in other runtime calls. Does not create a channel. +// @param senderId(type=string) UserID of the message sender (when applicable). An empty string defaults to the system user. // @param target(type=string) Can be the room name, group identifier, or another username. // @param chanType(type=int) The type of channel, for example group or direct. // @return channelId(string) The generated ID representing a channel. // @return error(error) An optional error value if an error occurred. func (n *RuntimeLuaNakamaModule) channelIdBuild(l *lua.LState) int { - target := l.CheckString(1) + senderStr := l.CheckString(1) + suid := uuid.Nil + if senderStr != "" { + var err error + suid, err = uuid.FromString(senderStr) + if err != nil { + l.ArgError(1, "expects sender id to either be not set, empty string or a valid UUID") + return 0 + } + } + + target := l.CheckString(2) - chanType := l.CheckInt(2) + chanType := l.CheckInt(3) if chanType < 1 || chanType > 3 { l.RaiseError("invalid channel type: expects value 1-3") return 0 } - channelId, _, err := BuildChannelId(l.Context(), n.logger, n.db, uuid.Nil, target, rtapi.ChannelJoin_Type(chanType)) + channelId, _, err := BuildChannelId(l.Context(), n.logger, n.db, suid, target, rtapi.ChannelJoin_Type(chanType)) if err != nil { if errors.Is(err, runtime.ErrInvalidChannelTarget) { l.ArgError(1, err.Error()) diff --git a/vendor/github.com/heroiclabs/nakama-common/runtime/runtime.go b/vendor/github.com/heroiclabs/nakama-common/runtime/runtime.go index 2a7d742426037979792a5577ca04b61a171d263b..687d928878b786f22ff320b7018c4b1187cd3028 100644 --- a/vendor/github.com/heroiclabs/nakama-common/runtime/runtime.go +++ b/vendor/github.com/heroiclabs/nakama-common/runtime/runtime.go @@ -991,7 +991,7 @@ type NakamaModule interface { NotificationSend(ctx context.Context, userID, subject string, content map[string]interface{}, code int, sender string, persistent bool) error NotificationsSend(ctx context.Context, notifications []*NotificationSend) error - WalletUpdate(ctx context.Context, userID string, changeset map[string]int64, metadata map[string]interface{}, updateLedger bool) (map[string]int64, map[string]int64, error) + WalletUpdate(ctx context.Context, userID string, changeset map[string]int64, metadata map[string]interface{}, updateLedger bool) (updated map[string]int64, previous map[string]int64, err error) WalletsUpdate(ctx context.Context, updates []*WalletUpdate, updateLedger bool) ([]*WalletUpdateResult, error) WalletLedgerUpdate(ctx context.Context, itemID string, metadata map[string]interface{}) (WalletLedgerItem, error) WalletLedgerList(ctx context.Context, userID string, limit int, cursor string) ([]WalletLedgerItem, string, error) @@ -1010,6 +1010,7 @@ type NakamaModule interface { LeaderboardRecordWrite(ctx context.Context, id, ownerID, username string, score, subscore int64, metadata map[string]interface{}, overrideOperator *int) (*api.LeaderboardRecord, error) LeaderboardRecordDelete(ctx context.Context, id, ownerID string) error LeaderboardsGetId(ctx context.Context, ids []string) ([]*api.Leaderboard, error) + LeaderboardRecordsHaystack(ctx context.Context, id, ownerID string, limit int, expiry int64) ([]*api.LeaderboardRecord, error) PurchaseValidateApple(ctx context.Context, userID, receipt string, passwordOverride ...string) (*api.ValidatePurchaseResponse, error) PurchaseValidateGoogle(ctx context.Context, userID, receipt string) (*api.ValidatePurchaseResponse, error) @@ -1050,7 +1051,7 @@ type NakamaModule interface { MetricsGaugeSet(name string, tags map[string]string, value float64) MetricsTimerRecord(name string, tags map[string]string, value time.Duration) - ChannelIdBuild(ctx context.Context, target string, chanType ChannelType) (string, error) + ChannelIdBuild(ctx context.Context, sender string, target string, chanType ChannelType) (string, error) ChannelMessageSend(ctx context.Context, channelID string, content map[string]interface{}, senderId, senderUsername string, persist bool) (*rtapi.ChannelMessageAck, error) ChannelMessageUpdate(ctx context.Context, channelID, messageID string, content map[string]interface{}, senderId, senderUsername string, persist bool) (*rtapi.ChannelMessageAck, error) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 1be27a443c9aebace636252864f9b257e5dbe59d..ff44d56dcaff9e515e60b6563f40daa99b060046 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -139,7 +139,7 @@ github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopena github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options github.com/grpc-ecosystem/grpc-gateway/v2/runtime github.com/grpc-ecosystem/grpc-gateway/v2/utilities -# github.com/heroiclabs/nakama-common v1.21.1-0.20220117102903-bc0471af4fe1 +# github.com/heroiclabs/nakama-common v1.21.1-0.20220225112712-3adfceaba805 ## explicit; go 1.14 github.com/heroiclabs/nakama-common/api github.com/heroiclabs/nakama-common/rtapi @@ -383,4 +383,3 @@ gopkg.in/yaml.v2 # gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ## explicit gopkg.in/yaml.v3 -# github.com/heroiclabe/nakama-common => ../nakama-common