From 7e107807a6ede8bab668d7e9a5b7d9276710d7ae Mon Sep 17 00:00:00 2001 From: Fernando Takagi Date: Mon, 29 Aug 2022 17:45:16 -0300 Subject: [PATCH] Add to runtime definitions --- server/runtime_go_nakama.go | 5 +++-- server/runtime_javascript_nakama.go | 8 +++++++- server/runtime_lua_nakama.go | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/runtime_go_nakama.go b/server/runtime_go_nakama.go index a0868ffea..0b9213a01 100644 --- a/server/runtime_go_nakama.go +++ b/server/runtime_go_nakama.go @@ -3907,11 +3907,12 @@ func (n *RuntimeGoNakamaModule) ChannelMessageRemove(ctx context.Context, channe // @param limit(type=int) The number of messages to return per page. // @param forward(type=bool) Whether to list messages from oldest to newest, or newest to oldest. // @param cursor(type=string, optional=true, default="") Pagination cursor from previous result. Don't set to start fetching from the beginning. +// @param instant(type=int64, optional=true, default=0) Time which around to list messages, since epoch in seconds. Used only if no cursor is provided. // @return channelMessageList([]*rtapi.ChannelMessage) Messages from the specified channel. // @return nextCursor(string) Cursor for the next page of messages, if any. // @return prevCursor(string) Cursor for the previous page of messages, if any. // @return error(error) An optional error value if an error occurred. -func (n *RuntimeGoNakamaModule) ChannelMessagesList(ctx context.Context, channelId string, limit int, forward bool, cursor string) ([]*api.ChannelMessage, string, string, error) { +func (n *RuntimeGoNakamaModule) ChannelMessagesList(ctx context.Context, channelId string, limit int, forward bool, cursor string, instant int64) ([]*api.ChannelMessage, string, string, error) { channelIdToStreamResult, err := ChannelIdToStream(channelId) if err != nil { return nil, "", "", err @@ -3921,7 +3922,7 @@ func (n *RuntimeGoNakamaModule) ChannelMessagesList(ctx context.Context, channel return nil, "", "", errors.New("limit must be 1-100") } - list, err := ChannelMessagesList(ctx, n.logger, n.db, uuid.Nil, channelIdToStreamResult.Stream, channelId, limit, forward, cursor, nil) + list, err := ChannelMessagesList(ctx, n.logger, n.db, uuid.Nil, channelIdToStreamResult.Stream, channelId, limit, forward, cursor, instant) if err != nil { return nil, "", "", err } diff --git a/server/runtime_javascript_nakama.go b/server/runtime_javascript_nakama.go index bb6e67c56..8c77cb15a 100644 --- a/server/runtime_javascript_nakama.go +++ b/server/runtime_javascript_nakama.go @@ -7979,6 +7979,7 @@ func (n *runtimeJavascriptNakamaModule) channelMessageRemove(r *goja.Runtime) fu // @param limit(type=number, optional=true, default=100) The number of messages to return per page. // @param forward(type=bool, optional=true, default=true) Whether to list messages from oldest to newest, or newest to oldest. // @param cursor(type=string, optional=true, default="") Pagination cursor from previous result. Don't set to start fetching from the beginning. +// @param instant(type=number, optional=true, default=0) Time which around to list messages, since epoch in seconds. Used only if no cursor is provided. // @return channelMessagesList(nkruntime.ChannelMessageList) Messages from the specified channel and possibly a cursor. If cursor is empty/null there are no further results. // @return error(error) An optional error value if an error occurred. func (n *runtimeJavascriptNakamaModule) channelMessagesList(r *goja.Runtime) func(goja.FunctionCall) goja.Value { @@ -8003,12 +8004,17 @@ func (n *runtimeJavascriptNakamaModule) channelMessagesList(r *goja.Runtime) fun cursor = getJsString(r, f.Argument(3)) } + var haystackTime int64 + if f.Argument(4) != goja.Undefined() && f.Argument(4) != goja.Null() { + haystackTime = getJsInt(r, f.Argument(4)) + } + channelIdToStreamResult, err := ChannelIdToStream(channelId) if err != nil { panic(r.NewTypeError(err.Error())) } - list, err := ChannelMessagesList(n.ctx, n.logger, n.db, uuid.Nil, channelIdToStreamResult.Stream, channelId, limit, forward, cursor, nil) + list, err := ChannelMessagesList(n.ctx, n.logger, n.db, uuid.Nil, channelIdToStreamResult.Stream, channelId, limit, forward, cursor, haystackTime) if err != nil { panic(r.NewGoError(fmt.Errorf("failed to list channel messages: %s", err.Error()))) } diff --git a/server/runtime_lua_nakama.go b/server/runtime_lua_nakama.go index 26b063cfc..ac91b5a3f 100644 --- a/server/runtime_lua_nakama.go +++ b/server/runtime_lua_nakama.go @@ -9545,6 +9545,7 @@ func (n *RuntimeLuaNakamaModule) channelMessageRemove(l *lua.LState) int { // @param limit(type=number, optional=true, default=100) The number of messages to return per page. // @param forward(type=bool, optional=true, default=true) Whether to list messages from oldest to newest, or newest to oldest. // @param cursor(type=string, optional=true, default="") Pagination cursor from previous result. Don't set to start fetching from the beginning. +// @param instant(type=number, optional=true, default=0) Time which around to list messages, since epoch in seconds. Used only if no cursor is provided. // @return messages(table) Messages from the specified channel. // @return nextCursor(string) Cursor for the next page of messages, if any. Will be set to "" or nil when fetching last available page. // @return prevCursor(string) Cursor for the previous page of messages, if any. @@ -9561,13 +9562,15 @@ func (n *RuntimeLuaNakamaModule) channelMessagesList(l *lua.LState) int { cursor := l.OptString(4, "") + haystackTime := l.OptInt64(5, 0) + channelIdToStreamResult, err := ChannelIdToStream(channelId) if err != nil { l.RaiseError(err.Error()) return 0 } - list, err := ChannelMessagesList(l.Context(), n.logger, n.db, uuid.Nil, channelIdToStreamResult.Stream, channelId, limit, forward, cursor, nil) + list, err := ChannelMessagesList(l.Context(), n.logger, n.db, uuid.Nil, channelIdToStreamResult.Stream, channelId, limit, forward, cursor, haystackTime) if err != nil { l.RaiseError("failed to list channel messages: %v", err.Error()) return 0 -- GitLab