chat

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrChatAlreadyExists    = errors.New("chat record already exists")
	ErrChatNotFound         = errors.New("chat record not found")
	ErrMessageAlreadyExists = errors.New("message record already exists")
	ErrMessageNotFound      = errors.New("message record not found")
	ErrInvalidMessageCursor = errors.New("message cursor is invalid")
)

Functions

This section is empty.

Types

type Chat

type Chat struct {
	Id uint64

	ChatId     ChatId
	ChatType   ChatType
	ChatTitle  string // The message sender
	IsVerified bool

	CodeUser string // Always a receiver of messages

	ReadPointer    *string
	IsMuted        bool
	IsUnsubscribed bool

	CreatedAt time.Time
}

func (*Chat) Clone

func (r *Chat) Clone() Chat

func (*Chat) CopyTo

func (r *Chat) CopyTo(dst *Chat)

func (*Chat) Validate

func (r *Chat) Validate() error

type ChatId

type ChatId [32]byte

func ChatIdFromProto

func ChatIdFromProto(proto *chatpb.ChatId) ChatId

func GetChatId

func GetChatId(sender, receiver string, isVerified bool) ChatId

func (ChatId) String

func (c ChatId) String() string

func (ChatId) ToProto

func (c ChatId) ToProto() *chatpb.ChatId

type ChatType

type ChatType uint8
const (
	ChatTypeUnknown  ChatType = iota
	ChatTypeInternal          // todo: better name, or split into the various buckets (eg. Code Team vs Cash Transactions)
	ChatTypeExternalApp
)

type Message

type Message struct {
	Id uint64

	ChatId ChatId

	MessageId string
	Data      []byte

	IsSilent      bool
	ContentLength uint8

	Timestamp time.Time
}

func (*Message) Clone

func (r *Message) Clone() Message

func (*Message) CopyTo

func (r *Message) CopyTo(dst *Message)

func (*Message) Validate

func (r *Message) Validate() error

type Store

type Store interface {
	// PutChat creates a new chat metadata
	PutChat(ctx context.Context, record *Chat) error

	// GetChatById gets a chat by its chat ID
	GetChatById(ctx context.Context, chatId ChatId) (*Chat, error)

	// GetAllChatsForUser gets all chats for a given user
	//
	// Note: Cursor is the auto-incrementing ID
	GetAllChatsForUser(ctx context.Context, user string, cursor query.Cursor, direction query.Ordering, limit uint64) ([]*Chat, error)

	// PutMessage creates a new new chat message
	PutMessage(ctx context.Context, record *Message) error

	// Delete message deletes a message within a chat. The call is idempotent
	// and will not fail if the message doesn't exist.
	DeleteMessage(ctx context.Context, chatId ChatId, messageId string) error

	// GetMessageById gets a chat message by its message ID within a chat
	GetMessageById(ctx context.Context, chatId ChatId, messageId string) (*Message, error)

	// GetAllMessagesByChat gets all messages for a given chat
	//
	// Note: Cursor is a message ID
	GetAllMessagesByChat(ctx context.Context, chatId ChatId, cursor query.Cursor, direction query.Ordering, limit uint64) ([]*Message, error)

	// AdvancePointer advances a chat pointer
	AdvancePointer(ctx context.Context, chatId ChatId, pointer string) error

	// GetUnreadCount gets the unread message count for a chat ID
	GetUnreadCount(ctx context.Context, chatId ChatId) (uint32, error)

	// SetMuteState updates the mute state for a chat
	SetMuteState(ctx context.Context, chatId ChatId, isMuted bool) error

	// SetSubscriptionState updates the subscription state for a chat
	SetSubscriptionState(ctx context.Context, chatId ChatId, isSubscribed bool) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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