message

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 14 Imported by: 0 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

View Source
const (
	JournalMessage        = journal.Message
	JournalFlagRaised     = journal.FlagRaised
	JournalFlagLowered    = journal.FlagLowered
	JournalAccountDeleted = journal.AccountDeleted
	JournalAdDeleted      = journal.AdDeleted
	JournalAdPaused       = journal.AdPaused
	JournalAdUnpaused     = journal.AdUnpaused
)

Variables

View Source
var (
	ErrModalAdNotFound = errors.New("modal ad not found")
	ErrModalAccess     = errors.New("modal conversation access denied")
)
View Source
var ErrConversationNotFound = errors.New("conversation not found")
View Source
var ErrMessagingClosed = errors.New("messaging is closed for this conversation")
View Source
var ErrNotParticipant = errors.New("user is not a participant in this conversation")

Functions

func AppendCloseEntry

func AppendCloseEntry(j, kind string, userID int, at time.Time,
	tz *time.Location) string

func AppendFlagEntry added in v0.0.21

func AppendFlagEntry(j, kind string, userID int, reason string, at time.Time,
	tz *time.Location) string

func AppendJournalEntry

func AppendJournalEntry(j, label, meta, body string, at time.Time,
	tz *time.Location) string

func AppendMessageEntry

func AppendMessageEntry(j string, senderID int, body string, at time.Time,
	tz *time.Location) string

func CanUserPost

func CanUserPost(conversationID, userID int) (bool, error)

CanUserPost checks if a user can post to a conversation (must be participant)

func CanViewConversation

func CanViewConversation(conv Conversation, userID int) bool

func CloseEventText

func CloseEventText(kind, userName string) string

func DisplayName

func DisplayName(userID int) (name string, deleted bool)

func FirstEntryAt

func FirstEntryAt(j string) (time.Time, bool)

func GetHasUnread

func GetHasUnread(userID int) (bool, error)

GetHasUnread checks if the user has any unread conversations

func IsParticipant

func IsParticipant(conv Conversation, userID int) bool

func IsPublic

func IsPublic(conversationID int) (bool, error)

HasFlag reports whether a conversation currently has a flag thrown (assessment may be public; the message thread is not).

func LastMessagePreview

func LastMessagePreview(j string) (content string, at time.Time, ok bool)

func LatestThrownReason

func LatestThrownReason(j string) string

LatestThrownReason returns the reason on the most recent flag-raisen entry.

func MarkConversationAsRead

func MarkConversationAsRead(conversationID, userID int) error

MarkConversationAsRead marks a conversation as read for the given user

func MessagingAllowed

func MessagingAllowed(conv Conversation) bool

MessagingAllowed reports whether new messages/flags are allowed on this thread.

func OtherParticipantID

func OtherParticipantID(conv Conversation, userID int) int

func OtherUserName

func OtherUserName(conv Conversation, currentUserID int) (string, error)

func OwnerAndInquirerNames

func OwnerAndInquirerNames(conv Conversation) (ownerName, inquirerName string,
	err error)

Types

type CloseJournalEvent

type CloseJournalEvent struct {
	UserID    int
	Kind      string
	CreatedAt time.Time
}

CloseJournalEvent is an ad/account deletion timeline entry from the journal.

func CloseEventsFromJournal

func CloseEventsFromJournal(j string, tz *time.Location) []CloseJournalEvent

type Conversation

type Conversation struct {
	ID                int        `db:"id"`
	AdID              int        `db:"ad_id"`
	OwnerID           int        `db:"owner_id"`
	InquirerID        int        `db:"inquirer_id"`
	CreatedAt         time.Time  `db:"created_at"`
	UpdatedAt         time.Time  `db:"updated_at"`
	OwnerHasUnread    bool       `db:"owner_has_unread"`
	InquirerHasUnread bool       `db:"inquirer_has_unread"`
	FlagRaiserID      *int       `db:"flag_raiser_id"`
	FlagRaisedAt      *time.Time `db:"flag_raised_at"`
	Journal           string     `db:"journal"`
}

func CloseConversationsForDeletedAccount

func CloseConversationsForDeletedAccount(userID int) ([]Conversation, error)

func CloseConversationsForDeletedAd

func CloseConversationsForDeletedAd(adID, actorID int) ([]Conversation, error)

func CreateConversation

func CreateConversation(adID, ownerID, inquirerID int) (Conversation, error)

CreateConversation creates a new conversation

func GetConversation

func GetConversation(conversationID, userID int) (Conversation, error)

func GetConversationByAdAndInquirer

func GetConversationByAdAndInquirer(adID, ownerID,
	inquirerID int) (Conversation, error)

GetConversationByAdAndInquirer gets an existing conversation by ad ID and inquirer ID Returns ErrConversationNotFound if the conversation does not exist

func GetConversationByID

func GetConversationByID(conversationID int) (Conversation, error)

GetConversationByID gets a conversation by ID without user check (for public access)

func GetPublicConversations

func GetPublicConversations(adID int) ([]Conversation, error)

GetPublicConversations returns public conversations for an ad

func OpenConversation

func OpenConversation(conversationID, userID int) (Conversation, bool, error)

OpenConversation loads a conversation the user may view (participants only) and marks it read. The second return value is true when marked.

func ResumeConversationsForUnpausedAd

func ResumeConversationsForUnpausedAd(adID, actorID int) ([]Conversation, error)

func SuspendConversationsForPausedAd

func SuspendConversationsForPausedAd(adID, actorID int) ([]Conversation, error)

type ConversationModalView

type ConversationModalView struct {
	Conversation      Conversation
	AdTitle           string
	OwnerName         string
	InquirerName      string
	OwnerDeleted      bool
	InquirerDeleted   bool
	Messages          []Message
	FlagEvents        []FlagJournalEvent
	CloseEvents       []CloseJournalEvent
	InquirerFlagCount int
	OwnerFlagCount    int
	CanPost           bool
	HasRaisedFlag     bool
	CanRaiseFlag      bool
}

ConversationModalView holds data needed to render a conversation modal.

func BuildConversationModal

func BuildConversationModal(conv Conversation, currentUserID int,
	tz *time.Location) (ConversationModalView, error)

type ConversationWithAd

type ConversationWithAd struct {
	Conversation
	AdTitle string `db:"ad_title"`
}

type ConversationWithLastMessage

type ConversationWithLastMessage struct {
	ConversationWithAd
	LastMessageContent string     `db:"last_message_content"`
	LastMessageAt      *time.Time `db:"last_message_at"`
	OtherUserID        int        `db:"other_user_id"`
	HasUnread          bool       `db:"has_unread"`
	FlagCount          int        `db:"flag_count"`
	OtherUserName      string
	OtherUserFlagCount int
	OtherUserDeleted   bool
}

func GetUserConversations

func GetUserConversations(userID int,
	tz *time.Location) ([]ConversationWithLastMessage, error)

type FlagJournalEvent added in v0.0.21

type FlagJournalEvent struct {
	UserID    int
	Kind      string
	Reason    string
	CreatedAt time.Time
}

FlagJournalEvent is a flag throw/lower timeline entry from the journal.

func FlagEventsFromJournal added in v0.0.21

func FlagEventsFromJournal(j string, tz *time.Location) []FlagJournalEvent

type JournalEntry

type JournalEntry = journal.Entry

func ParseJournal

func ParseJournal(j string) []JournalEntry

type Message

type Message struct {
	ID             int       `db:"id"`
	ConversationID int       `db:"conversation_id"`
	SenderID       int       `db:"sender_id"`
	Content        string    `db:"content"`
	CreatedAt      time.Time `db:"created_at"`
}

func CreateMessage

func CreateMessage(conversationID, senderID int,
	content string) (Message, error)

func GetConversationMessages

func GetConversationMessages(conversationID, userID int,
	tz *time.Location) ([]Message, error)

func MessagesFromJournal

func MessagesFromJournal(conversationID int, j string, tz *time.Location) []Message

Jump to

Keyboard shortcuts

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