chat

package
v0.0.0-...-e9c30ff Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrChatMessageNotFound = errors.New("chat message not found")

ErrChatMessageNotFound is returned by a ChatStore when LoadMessage or DeleteMessage does not find the given message

Functions

This section is empty.

Types

type AttachmentLoader

type AttachmentLoader func(context.Context, string) (MessageAttachmentView, error)

AttachmentLoader transforms a DB-serialized attachment storage model into the respective view model

type ChatStoreDatabase

type ChatStoreDatabase struct {
	// contains filtered or unexported fields
}

ChatStoreDatabase stores messages in the database

func NewStoreDatabase

func NewStoreDatabase(log *log.Logger, nicknameCache usercache.UserCache) *ChatStoreDatabase

NewStoreDatabase initializes and returns a new ChatStoreDatabase

func (*ChatStoreDatabase) DeleteMessage

func (s *ChatStoreDatabase) DeleteMessage(ctxCtx context.Context, id snowflake.ID) (*Message, error)

func (*ChatStoreDatabase) GetUserNickname

func (s *ChatStoreDatabase) GetUserNickname(ctx context.Context, user auth.User) *string

func (*ChatStoreDatabase) LoadAttachment

func (s *ChatStoreDatabase) LoadAttachment(ctx context.Context, attachmentString string) (MessageAttachmentView, error)

func (*ChatStoreDatabase) LoadMessage

func (s *ChatStoreDatabase) LoadMessage(ctxCtx context.Context, id snowflake.ID) (*Message, error)

func (*ChatStoreDatabase) LoadMessagesBetween

func (s *ChatStoreDatabase) LoadMessagesBetween(ctxCtx context.Context, includeShadowbanned auth.User, since, until time.Time) ([]*Message, error)

func (*ChatStoreDatabase) LoadNumLatestMessages

func (s *ChatStoreDatabase) LoadNumLatestMessages(ctxCtx context.Context, includeShadowbanned auth.User, num int) ([]*Message, error)

func (*ChatStoreDatabase) LoadNumLatestMessagesFromUser

func (s *ChatStoreDatabase) LoadNumLatestMessagesFromUser(ctxCtx context.Context, user auth.User, num int) ([]*Message, error)

func (*ChatStoreDatabase) SetAttachmentLoaderForType

func (s *ChatStoreDatabase) SetAttachmentLoaderForType(attachmentType string, attachmentLoader AttachmentLoader)

func (*ChatStoreDatabase) SetUserNickname

func (s *ChatStoreDatabase) SetUserNickname(ctxCtx context.Context, user auth.User, nickname *string) error

func (*ChatStoreDatabase) StoreMessage

func (s *ChatStoreDatabase) StoreMessage(ctxCtx context.Context, m *Message) (*string, error)

type EmoteCache

type EmoteCache struct {
	// contains filtered or unexported fields
}

EmoteCache caches chat emote information

func (*EmoteCache) ChatEmotes

func (c *EmoteCache) ChatEmotes(ctx context.Context) ([]*types.ChatEmote, error)

func (*EmoteCache) EmoteByID

func (c *EmoteCache) EmoteByID(ctx context.Context, id snowflake.ID) (*types.ChatEmote, bool)

type Message

type Message struct {
	ID              snowflake.ID
	CreatedAt       time.Time
	Author          auth.User
	Content         string
	Reference       *Message // may be nil
	Shadowbanned    bool
	Attachments     []MessageAttachmentStorage
	AttachmentsView []MessageAttachmentView
}

Message represents a single chat message

func (*Message) SerializeForAPI

func (m *Message) SerializeForAPI(ctx context.Context, userSerializer auth.APIUserSerializer) *proto.ChatMessage

type MessageAttachmentStorage

type MessageAttachmentStorage interface {
	AttachmentType() string
	SerializeForDatabase(ctx context.Context) string
}

MessageAttachmentStorage represents the submission and storage model for an attachment

type MessageAttachmentStorageWithCost

type MessageAttachmentStorageWithCost interface {
	MessageAttachmentStorage
	PointsCost() int
	PointsTxType() types.PointsTxType
}

MessageAttachmentStorage represents the submission and storage model for an attachment that has a points cost

type MessageAttachmentView

type MessageAttachmentView interface {
	SerializeForAPI(ctx context.Context) *proto.ChatMessageAttachment
	SerializeForModLog(ctx context.Context) string
	SerializeForJS(ctx context.Context, vm *goja.Runtime) map[string]interface{}
}

MessageAttachmentView represents the view model for an attachment

type Store

type Store interface {
	StoreMessage(context.Context, *Message) (*string, error)
	DeleteMessage(context.Context, snowflake.ID) (*Message, error)
	LoadMessagesBetween(context.Context, auth.User, time.Time, time.Time) ([]*Message, error)
	LoadNumLatestMessages(context.Context, auth.User, int) ([]*Message, error)
	LoadNumLatestMessagesFromUser(context.Context, auth.User, int) ([]*Message, error)
	LoadMessage(context.Context, snowflake.ID) (*Message, error)
	SetUserNickname(context.Context, auth.User, *string) error
	GetUserNickname(context.Context, auth.User) *string
	SetAttachmentLoaderForType(attachmentType string, attachmentLoader AttachmentLoader)
	LoadAttachment(ctx context.Context, attachmentString string) (MessageAttachmentView, error)
}

Store can save and load chat messages

Jump to

Keyboard shortcuts

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