models

package
v0.0.0-...-0e46d6e Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const DirectMessagePerPage = 20

Variables

View Source
var (
	DB                *sql.DB
	ErrNotInitialized = errors.New("database is not initialized")
)

Functions

func CreateChannelID

func CreateChannelID(fromUsername, toUsername string) string

CreateChannelID returns a deterministic channel ID for a direct message conversation.

The usernames (passed in any order) are sorted alphabetically and composed into the channel ID.

func Initialize

func Initialize(connString string) error

func PaginateDirectMessages

func PaginateDirectMessages(fromUsername, toUsername string, beforeID int64) ([]messages.Message, int, error)

PaginateDirectMessages returns a page of messages, the count of remaining, and an error.

Types

type DirectMessage

type DirectMessage struct {
	MessageID int64
	ChannelID string
	Username  string
	Message   string
	Timestamp int64
}

func (DirectMessage) ClearMessages

func (dm DirectMessage) ClearMessages(username string) (int, error)

ClearMessages clears all stored DMs that the username as a participant in.

func (DirectMessage) CreateTable

func (dm DirectMessage) CreateTable() error

func (DirectMessage) LogMessage

func (dm DirectMessage) LogMessage(fromUsername, toUsername string, msg messages.Message) error

LogMessage adds a message to the DM history between two users.

func (DirectMessage) TakebackMessage

func (dm DirectMessage) TakebackMessage(username string, messageID int64, isAdmin bool) (bool, error)

TakebackMessage removes a message by its MID from the DM history.

Because the MessageID may have been from a previous chat session, the server can't immediately verify the current user had permission to take it back. This function instead will check whether a DM history exists sent by this username for that messageID, and if so, returns a boolean true that the username/messageID matched which will satisfy the permission check in the OnTakeback handler.

Jump to

Keyboard shortcuts

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