Documentation
¶
Index ¶
- Constants
- Variables
- func AppendCloseEntry(j, kind string, userID int, at time.Time, tz *time.Location) string
- func AppendJournalEntry(j, label, meta, body string, at time.Time, tz *time.Location) string
- func AppendMessageEntry(j string, senderID int, body string, at time.Time, tz *time.Location) string
- func AppendRockEntry(j, kind string, userID int, reason string, at time.Time, tz *time.Location) string
- func CanUserPost(conversationID, userID int) (bool, error)
- func CanViewConversation(conv Conversation, userID int) bool
- func CloseEventText(kind, userName string) string
- func DisplayName(userID int) (name string, deleted bool)
- func FirstEntryAt(j string) (time.Time, bool)
- func GetHasUnread(userID int) (bool, error)
- func IsParticipant(conv Conversation, userID int) bool
- func IsPublic(conversationID int) (bool, error)
- func LastMessagePreview(j string) (content string, at time.Time, ok bool)
- func LatestThrownReason(j string) string
- func MarkConversationAsRead(conversationID, userID int) error
- func MessagingAllowed(conv Conversation) bool
- func OtherParticipantID(conv Conversation, userID int) int
- func OtherUserName(conv Conversation, currentUserID int) (string, error)
- func OwnerAndInquirerNames(conv Conversation) (ownerName, inquirerName string, err error)
- type CloseJournalEvent
- type Conversation
- func CloseConversationsForDeletedAccount(userID int) ([]Conversation, error)
- func CloseConversationsForDeletedAd(adID, actorID int) ([]Conversation, error)
- func CreateConversation(adID, ownerID, inquirerID int) (Conversation, error)
- func GetConversation(conversationID, userID int) (Conversation, error)
- func GetConversationByAdAndInquirer(adID, ownerID, inquirerID int) (Conversation, error)
- func GetConversationByID(conversationID int) (Conversation, error)
- func GetPublicConversations(adID int) ([]Conversation, error)
- func OpenConversation(conversationID, userID int) (Conversation, bool, error)
- func ResumeConversationsForUnpausedAd(adID, actorID int) ([]Conversation, error)
- func SuspendConversationsForPausedAd(adID, actorID int) ([]Conversation, error)
- type ConversationModalView
- type ConversationWithAd
- type ConversationWithLastMessage
- type JournalEntry
- type Message
- type RockJournalEvent
Constants ¶
const ( JournalMessage = journal.Message JournalRockThrown = journal.RockThrown JournalRockUnthrown = journal.RockUnthrown JournalAccountDeleted = journal.AccountDeleted JournalAdDeleted = journal.AdDeleted JournalAdPaused = journal.AdPaused JournalAdUnpaused = journal.AdUnpaused )
Variables ¶
var ( ErrModalAdNotFound = errors.New("modal ad not found") ErrModalAccess = errors.New("modal conversation access denied") )
var ErrConversationNotFound = errors.New("conversation not found")
var ErrMessagingClosed = errors.New("messaging is closed for this conversation")
var ErrNotParticipant = errors.New("user is not a participant in this conversation")
Functions ¶
func AppendCloseEntry ¶
func AppendJournalEntry ¶
func AppendMessageEntry ¶
func AppendRockEntry ¶
func CanUserPost ¶
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 DisplayName ¶
func GetHasUnread ¶
GetHasUnread checks if the user has any unread conversations
func IsParticipant ¶
func IsParticipant(conv Conversation, userID int) bool
func IsPublic ¶
HasRock reports whether a conversation currently has a rock thrown (assessment may be public; the message thread is not).
func LatestThrownReason ¶
LatestThrownReason returns the reason on the most recent rock-thrown entry.
func MarkConversationAsRead ¶
MarkConversationAsRead marks a conversation as read for the given user
func MessagingAllowed ¶
func MessagingAllowed(conv Conversation) bool
MessagingAllowed reports whether new messages/rocks 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 ¶
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"`
RockThrowerID *int `db:"rock_thrower_id"`
RockThrownAt *time.Time `db:"rock_thrown_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
RockEvents []RockJournalEvent
CloseEvents []CloseJournalEvent
InquirerRockCount int
OwnerRockCount int
CanPost bool
HasThrownRock bool
CanThrowRock 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"`
RockCount int `db:"rock_count"`
OtherUserName string
OtherUserRockCount int
OtherUserDeleted bool
}
func GetUserConversations ¶
func GetUserConversations(userID int, tz *time.Location) ([]ConversationWithLastMessage, error)
type JournalEntry ¶
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 GetConversationMessages ¶
type RockJournalEvent ¶
RockJournalEvent is a rock throw/unthrow timeline entry from the journal.
func RockEventsFromJournal ¶
func RockEventsFromJournal(j string, tz *time.Location) []RockJournalEvent