chat

package
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2022 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var File_proto_chat_proto protoreflect.FileDescriptor

Functions

func NewChatEndpoints

func NewChatEndpoints() []*api.Endpoint

func RegisterChatHandler

func RegisterChatHandler(s server.Server, hdlr ChatHandler, opts ...server.HandlerOption) error

Types

type ChatHandler

type ChatHandler interface {
	// New creates a chat for a group of users. The RPC is idempotent so if it's called multiple times
	// for the same users, the same response will be returned. It's good practice to design APIs as
	// idempotent since this enables safe retries.
	New(context.Context, *NewRequest, *NewResponse) error
	// History returns the historical messages in a chat
	History(context.Context, *HistoryRequest, *HistoryResponse) error
	// Send a single message to the chat
	Send(context.Context, *SendRequest, *SendResponse) error
	// Connect to a chat using a bidirectional stream enabling the client to send and recieve messages
	// over a single RPC. When a message is sent on the stream, it will be added to the chat history
	// and sent to the other connected users. When opening the connection, the client should provide
	// the chat_id and user_id in the context so the server knows which messages to stream.
	Connect(context.Context, Chat_ConnectStream) error
}

type ChatService

type ChatService interface {
	// New creates a chat for a group of users. The RPC is idempotent so if it's called multiple times
	// for the same users, the same response will be returned. It's good practice to design APIs as
	// idempotent since this enables safe retries.
	New(ctx context.Context, in *NewRequest, opts ...client.CallOption) (*NewResponse, error)
	// History returns the historical messages in a chat
	History(ctx context.Context, in *HistoryRequest, opts ...client.CallOption) (*HistoryResponse, error)
	// Send a single message to the chat
	Send(ctx context.Context, in *SendRequest, opts ...client.CallOption) (*SendResponse, error)
	// Connect to a chat using a bidirectional stream enabling the client to send and recieve messages
	// over a single RPC. When a message is sent on the stream, it will be added to the chat history
	// and sent to the other connected users. When opening the connection, the client should provide
	// the chat_id and user_id in the context so the server knows which messages to stream.
	Connect(ctx context.Context, opts ...client.CallOption) (Chat_ConnectService, error)
}

func NewChatService

func NewChatService(name string, c client.Client) ChatService

type Chat_ConnectService

type Chat_ConnectService interface {
	Context() context.Context
	SendMsg(interface{}) error
	RecvMsg(interface{}) error
	Close() error
	Send(*Message) error
	Recv() (*Message, error)
}

type Chat_ConnectStream

type Chat_ConnectStream interface {
	Context() context.Context
	SendMsg(interface{}) error
	RecvMsg(interface{}) error
	Close() error
	Send(*Message) error
	Recv() (*Message, error)
}

type HistoryRequest

type HistoryRequest struct {
	ChatId string `protobuf:"bytes,1,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
	// contains filtered or unexported fields
}

HistoryRequest contains the id of the chat we want the history for. This RPC will return all historical messages, however in a real life application we'd introduce some form of pagination here, only loading the older messages when required.

func (*HistoryRequest) Descriptor deprecated

func (*HistoryRequest) Descriptor() ([]byte, []int)

Deprecated: Use HistoryRequest.ProtoReflect.Descriptor instead.

func (*HistoryRequest) GetChatId

func (x *HistoryRequest) GetChatId() string

func (*HistoryRequest) ProtoMessage

func (*HistoryRequest) ProtoMessage()

func (*HistoryRequest) ProtoReflect

func (x *HistoryRequest) ProtoReflect() protoreflect.Message

func (*HistoryRequest) Reset

func (x *HistoryRequest) Reset()

func (*HistoryRequest) String

func (x *HistoryRequest) String() string

type HistoryResponse

type HistoryResponse struct {
	Messages []*Message `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"`
	// contains filtered or unexported fields
}

HistoryResponse contains the historical messages in a chat

func (*HistoryResponse) Descriptor deprecated

func (*HistoryResponse) Descriptor() ([]byte, []int)

Deprecated: Use HistoryResponse.ProtoReflect.Descriptor instead.

func (*HistoryResponse) GetMessages

func (x *HistoryResponse) GetMessages() []*Message

func (*HistoryResponse) ProtoMessage

func (*HistoryResponse) ProtoMessage()

func (*HistoryResponse) ProtoReflect

func (x *HistoryResponse) ProtoReflect() protoreflect.Message

func (*HistoryResponse) Reset

func (x *HistoryResponse) Reset()

func (*HistoryResponse) String

func (x *HistoryResponse) String() string

type Message

type Message struct {

	// id of the message, allocated by the server
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// a client side id, should be validated by the server to make the request retry safe
	ClientId string `protobuf:"bytes,2,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
	// id of the chat the message is being sent to / from
	ChatId string `protobuf:"bytes,3,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
	// id of the user who sent the message
	UserId string `protobuf:"bytes,4,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	// time time the message was sent in unix format
	SentAt *timestamp.Timestamp `protobuf:"bytes,5,opt,name=sent_at,json=sentAt,proto3" json:"sent_at,omitempty"`
	// subject of the message
	Subject string `protobuf:"bytes,6,opt,name=subject,proto3" json:"subject,omitempty"`
	// text of the message
	Text string `protobuf:"bytes,7,opt,name=text,proto3" json:"text,omitempty"`
	// contains filtered or unexported fields
}

Message sent to a chat

func (*Message) Descriptor deprecated

func (*Message) Descriptor() ([]byte, []int)

Deprecated: Use Message.ProtoReflect.Descriptor instead.

func (*Message) GetChatId

func (x *Message) GetChatId() string

func (*Message) GetClientId

func (x *Message) GetClientId() string

func (*Message) GetId

func (x *Message) GetId() string

func (*Message) GetSentAt

func (x *Message) GetSentAt() *timestamp.Timestamp

func (*Message) GetSubject

func (x *Message) GetSubject() string

func (*Message) GetText

func (x *Message) GetText() string

func (*Message) GetUserId

func (x *Message) GetUserId() string

func (*Message) ProtoMessage

func (*Message) ProtoMessage()

func (*Message) ProtoReflect

func (x *Message) ProtoReflect() protoreflect.Message

func (*Message) Reset

func (x *Message) Reset()

func (*Message) String

func (x *Message) String() string

type NewRequest

type NewRequest struct {
	UserIds []string `protobuf:"bytes,1,rep,name=user_ids,json=userIds,proto3" json:"user_ids,omitempty"`
	// contains filtered or unexported fields
}

NewRequest contains the infromation needed to create a new chat

func (*NewRequest) Descriptor deprecated

func (*NewRequest) Descriptor() ([]byte, []int)

Deprecated: Use NewRequest.ProtoReflect.Descriptor instead.

func (*NewRequest) GetUserIds

func (x *NewRequest) GetUserIds() []string

func (*NewRequest) ProtoMessage

func (*NewRequest) ProtoMessage()

func (*NewRequest) ProtoReflect

func (x *NewRequest) ProtoReflect() protoreflect.Message

func (*NewRequest) Reset

func (x *NewRequest) Reset()

func (*NewRequest) String

func (x *NewRequest) String() string

type NewResponse

type NewResponse struct {
	ChatId string `protobuf:"bytes,1,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
	// contains filtered or unexported fields
}

NewResponse contains the chat id for the users

func (*NewResponse) Descriptor deprecated

func (*NewResponse) Descriptor() ([]byte, []int)

Deprecated: Use NewResponse.ProtoReflect.Descriptor instead.

func (*NewResponse) GetChatId

func (x *NewResponse) GetChatId() string

func (*NewResponse) ProtoMessage

func (*NewResponse) ProtoMessage()

func (*NewResponse) ProtoReflect

func (x *NewResponse) ProtoReflect() protoreflect.Message

func (*NewResponse) Reset

func (x *NewResponse) Reset()

func (*NewResponse) String

func (x *NewResponse) String() string

type SendRequest

type SendRequest struct {

	// a client side id, should be validated by the server to make the request retry safe
	ClientId string `protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
	// id of the chat the message is being sent to / from
	ChatId string `protobuf:"bytes,2,opt,name=chat_id,json=chatId,proto3" json:"chat_id,omitempty"`
	// id of the user who sent the message
	UserId string `protobuf:"bytes,3,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	// subject of the message
	Subject string `protobuf:"bytes,4,opt,name=subject,proto3" json:"subject,omitempty"`
	// text of the message
	Text string `protobuf:"bytes,5,opt,name=text,proto3" json:"text,omitempty"`
	// contains filtered or unexported fields
}

SendRequest contains a single message to send to a chat

func (*SendRequest) Descriptor deprecated

func (*SendRequest) Descriptor() ([]byte, []int)

Deprecated: Use SendRequest.ProtoReflect.Descriptor instead.

func (*SendRequest) GetChatId

func (x *SendRequest) GetChatId() string

func (*SendRequest) GetClientId

func (x *SendRequest) GetClientId() string

func (*SendRequest) GetSubject

func (x *SendRequest) GetSubject() string

func (*SendRequest) GetText

func (x *SendRequest) GetText() string

func (*SendRequest) GetUserId

func (x *SendRequest) GetUserId() string

func (*SendRequest) ProtoMessage

func (*SendRequest) ProtoMessage()

func (*SendRequest) ProtoReflect

func (x *SendRequest) ProtoReflect() protoreflect.Message

func (*SendRequest) Reset

func (x *SendRequest) Reset()

func (*SendRequest) String

func (x *SendRequest) String() string

type SendResponse

type SendResponse struct {
	Message *Message `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

SendResponse is a blank message returned when a message is successfully created

func (*SendResponse) Descriptor deprecated

func (*SendResponse) Descriptor() ([]byte, []int)

Deprecated: Use SendResponse.ProtoReflect.Descriptor instead.

func (*SendResponse) GetMessage

func (x *SendResponse) GetMessage() *Message

func (*SendResponse) ProtoMessage

func (*SendResponse) ProtoMessage()

func (*SendResponse) ProtoReflect

func (x *SendResponse) ProtoReflect() protoreflect.Message

func (*SendResponse) Reset

func (x *SendResponse) Reset()

func (*SendResponse) String

func (x *SendResponse) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL