Commit 32daf652 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Expose chat layer to underlying stream access in the script runtime. (#186)

parent 700ceea6
Loading
Loading
Loading
Loading
+485 −320

File changed.

Preview size limit exceeded, changes collapsed.

+50 −0
Original line number Diff line number Diff line
@@ -486,6 +486,23 @@ func request_Nakama_LinkSteam_0(ctx context.Context, marshaler runtime.Marshaler

}

var (
	filter_Nakama_ListChannelMessages_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)

func request_Nakama_ListChannelMessages_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq ListChannelMessagesRequest
	var metadata runtime.ServerMetadata

	if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Nakama_ListChannelMessages_0); err != nil {
		return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
	}

	msg, err := client.ListChannelMessages(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
	return msg, metadata, err

}

func request_Nakama_ListFriends_0(ctx context.Context, marshaler runtime.Marshaler, client NakamaClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
	var protoReq empty.Empty
	var metadata runtime.ServerMetadata
@@ -1667,6 +1684,35 @@ func RegisterNakamaHandlerClient(ctx context.Context, mux *runtime.ServeMux, cli

	})

	mux.Handle("GET", pattern_Nakama_ListChannelMessages_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
		if cn, ok := w.(http.CloseNotifier); ok {
			go func(done <-chan struct{}, closed <-chan bool) {
				select {
				case <-done:
				case <-closed:
					cancel()
				}
			}(ctx.Done(), cn.CloseNotify())
		}
		inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
		rctx, err := runtime.AnnotateContext(ctx, mux, req)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}
		resp, md, err := request_Nakama_ListChannelMessages_0(rctx, inboundMarshaler, client, req, pathParams)
		ctx = runtime.NewServerMetadataContext(ctx, md)
		if err != nil {
			runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
			return
		}

		forward_Nakama_ListChannelMessages_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)

	})

	mux.Handle("GET", pattern_Nakama_ListFriends_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
		ctx, cancel := context.WithCancel(req.Context())
		defer cancel()
@@ -2272,6 +2318,8 @@ var (

	pattern_Nakama_LinkSteam_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"v2", "account", "link", "steam"}, ""))

	pattern_Nakama_ListChannelMessages_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "channel"}, ""))

	pattern_Nakama_ListFriends_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v2", "friend"}, ""))

	pattern_Nakama_ListLeaderboardRecords_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 1, 0, 4, 1, 5, 2}, []string{"v2", "leaderboard", "leaderboard_id"}, ""))
@@ -2362,6 +2410,8 @@ var (

	forward_Nakama_LinkSteam_0 = runtime.ForwardResponseMessage

	forward_Nakama_ListChannelMessages_0 = runtime.ForwardResponseMessage

	forward_Nakama_ListFriends_0 = runtime.ForwardResponseMessage

	forward_Nakama_ListLeaderboardRecords_0 = runtime.ForwardResponseMessage
+48 −17
Original line number Diff line number Diff line
@@ -263,6 +263,11 @@ service Nakama {
    };
  }

  // List a channel's message history.
  rpc ListChannelMessages (ListChannelMessagesRequest) returns (ChannelMessageList) {
    option (google.api.http).get = "/v2/channel";
  }

  // List all friends for the current user.
  rpc ListFriends (google.protobuf.Empty) returns (Friends) {
    option (google.api.http).get = "/v2/friend";
@@ -553,24 +558,38 @@ message BlockFriendsRequest {
  repeated string usernames = 2;
}

// An identifier for a realtime chat channel.
message ChannelId {
  // The type of chat channel.
  enum Type {
    // Default case. Assumed as ROOM type.
    TYPE_UNSPECIFIED = 0;
    // A room which anyone can join to chat.
    ROOM = 1;
    // A private channel for 1-on-1 chat.
    DIRECT_MESSAGE = 2;
    // A channel for group chat.
    GROUP = 3;
// A message sent on a channel.
message ChannelMessage {
  // The channel this message belongs to.
  string channel_id = 1;
  // The unique ID of this message.
  string message_id = 2;
  // The code representing a message type or category.
  int32 code = 3;
  // Message sender, usually a user ID.
  string sender_id = 4;
  // The username of the message sender, if any.
  string username = 5;
  // The content payload.
  string content = 6;
  // Another message ID reference, if any.
  string reference_id = 7;
  // The UNIX time when the message was created.
  google.protobuf.Timestamp create_time = 8;
  // The UNIX time when the message was last updated.
  google.protobuf.Timestamp update_time = 9;
  // True if the message was persisted to the channel's history, false otherwise.
  bool persistent = 10;
}

  // The identifier for the realtime channel.
  string id = 1;
  // The type of the chat channel.
  int32 type = 2; // one of "ChannelId.Type".
// A list of channel messages, usually a result of a list operation.
message ChannelMessageList {
  // A list of messages.
  repeated ChannelMessage messages = 1;
  // The cursor to send when retireving the next page, if any.
  string next_cursor = 2;
  // The cursor to send when retrieving the previous page, if any.
  string prev_cursor = 3;
}

// Create one or more groups with the current user as owner.
@@ -755,6 +774,18 @@ message LinkFacebookRequest {
  google.protobuf.BoolValue import = 4;
}

// List a channel's message history.
message ListChannelMessagesRequest {
  // The channel ID to list from.
  string channel_id = 1;
  // Max number of records to return. Between 1 and 100.
  google.protobuf.Int32Value limit = 2;
  // True if listing should be older messages to newer, false if reverse.
  google.protobuf.BoolValue forward = 3;
  // A pagination cursor, if any.
  string cursor = 4;
}

// List leaderboard records from a given leaderboard.
message ListLeaderboardRecordsRequest {
  // The ID of the leaderboard to list for.
+120 −0
Original line number Diff line number Diff line
@@ -645,6 +645,55 @@
        ]
      }
    },
    "/v2/channel": {
      "get": {
        "summary": "List a channel's message history.",
        "operationId": "ListChannelMessages",
        "responses": {
          "200": {
            "description": "",
            "schema": {
              "$ref": "#/definitions/apiChannelMessageList"
            }
          }
        },
        "parameters": [
          {
            "name": "channel_id",
            "description": "The channel ID to list from.",
            "in": "query",
            "required": false,
            "type": "string"
          },
          {
            "name": "limit",
            "description": "Max number of records to return. Between 1 and 100.",
            "in": "query",
            "required": false,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "forward",
            "description": "True if listing should be older messages to newer, false if reverse.",
            "in": "query",
            "required": false,
            "type": "boolean",
            "format": "boolean"
          },
          {
            "name": "cursor",
            "description": "A pagination cursor, if any.",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ],
        "tags": [
          "Nakama"
        ]
      }
    },
    "/v2/friend": {
      "get": {
        "summary": "List all friends for the current user.",
@@ -1447,6 +1496,77 @@
      },
      "description": "Send a Steam token to the server. Used with authenticate/link/unlink."
    },
    "apiChannelMessage": {
      "type": "object",
      "properties": {
        "channel_id": {
          "type": "string",
          "description": "The channel this message belongs to."
        },
        "message_id": {
          "type": "string",
          "description": "The unique ID of this message."
        },
        "code": {
          "type": "integer",
          "format": "int32",
          "description": "The code representing a message type or category."
        },
        "sender_id": {
          "type": "string",
          "description": "Message sender, usually a user ID."
        },
        "username": {
          "type": "string",
          "description": "The username of the message sender, if any."
        },
        "content": {
          "type": "string",
          "description": "The content payload."
        },
        "reference_id": {
          "type": "string",
          "description": "Another message ID reference, if any."
        },
        "create_time": {
          "type": "string",
          "format": "date-time",
          "description": "The UNIX time when the message was created."
        },
        "update_time": {
          "type": "string",
          "format": "date-time",
          "description": "The UNIX time when the message was last updated."
        },
        "persistent": {
          "type": "boolean",
          "format": "boolean",
          "description": "True if the message was persisted to the channel's history, false otherwise."
        }
      },
      "description": "A message sent on a channel."
    },
    "apiChannelMessageList": {
      "type": "object",
      "properties": {
        "messages": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/apiChannelMessage"
          },
          "description": "A list of messages."
        },
        "next_cursor": {
          "type": "string",
          "description": "The cursor to send when retireving the next page, if any."
        },
        "prev_cursor": {
          "type": "string",
          "description": "The cursor to send when retrieving the previous page, if any."
        }
      },
      "description": "A list of channel messages, usually a result of a list operation."
    },
    "apiCreateGroupsRequest": {
      "type": "object",
      "properties": {
+797 −213

File changed.

Preview size limit exceeded, changes collapsed.

Loading