messages

package
v0.0.0-...-6dfde0d Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2017 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SOpen      = "opened"
	SBlocked   = "blocked"
	SEncrypted = "encrypted"
)

Variables

View Source
var (
	ErrMessageSelf          = errors.New("You can't message yourself. Get some friends")
	ErrNoUsers              = errors.New("No Users were found for this thread")
	ErrThreadsNotFound      = errors.New("No threads were found")
	ErrThreadUsersNotFound  = errors.New("No thread users were found")
	ErrThreadUnreciprocated = errors.New("This thread is unreciprocated")
	ErrThreadUser           = errors.New("User isn't in this thread")
)

Functions

func GetThreadIDs

func GetThreadIDs(userID string, db *gorm.DB) (threadIDs []string, err error)

GetThreadIDs returns all the threadIDs for a particular user

func GetUserIDs

func GetUserIDs(userID string, db *gorm.DB) (userIDs []string, err error)

GetUserIDs returns a list of user ids with whom a user has a thread

func HasUnread

func HasUnread(userID, threadID string, db *gorm.DB) (bool, error)

HasUnread returns true if there are unread messages for a thread

func HasUser

func HasUser(userID, threadID string, db *gorm.DB) (bool, error)

HasUser returns true if a user is participating in a particular thread

func MarkAllMessagesRead

func MarkAllMessagesRead(userID, threadID string, db *gorm.DB) error

func UnreadCount

func UnreadCount(userID string, db *gorm.DB) (count int, err error)

Types

type Message

type Message struct {
	ID        string    `json:"id" gorm:"primary_key" sql:"type:uuid;default:uuid_generate_v4()"`
	ThreadID  string    `json:"thread_id" sql:"type:uuid"`
	UserID    string    `json:"user_id" sql:"type:uuid"` // User that sent the message
	Body      string    `json:"body"`                    // The text based body
	Read      bool      `json:"read"`                    // has the message been read?
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	User users.User `json:"user" sql:"-"`
}

Message is a direct message. Its "to" User is set by the MessageThread and MessageThreadUser

func (Message) NewPushNotifications

func (m Message) NewPushNotifications(db *gorm.DB) (pns []notifications.PushNotification, err error)

func (Message) Validate

func (m Message) Validate() (errs models.ValidationErrors)

type MessageCreatorBinding

type MessageCreatorBinding struct {
	ThreadID string `json:"thread_id"`
	UserID   string `json:"user_id"`
	Body     string `json:"body" binding:"required"`
}

type Messages

type Messages []Message

func GetMessages

func GetMessages(threadID string, db *gorm.DB) (msgs Messages, err error)

func GetMessagesAfter

func GetMessagesAfter(threadID string, after time.Time, db *gorm.DB) (msgs Messages, err error)

func (Messages) GetUserIDs

func (ms Messages) GetUserIDs() (userIDs []string)

GetUserIDs satisfies dao.UserIDerSlice

func (*Messages) GetUsers

func (ms *Messages) GetUsers(db *gorm.DB) error

func (Messages) Len

func (ms Messages) Len() int

func (Messages) Less

func (ms Messages) Less(i, j int) bool

func (Messages) Swap

func (ms Messages) Swap(i, j int)

type Thread

type Thread struct {
	ID        string    `json:"id" gorm:"primary_key" sql:"type:uuid;default:uuid_generate_v4()"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	Users       ThreadUsers `json:"users,omitempty" sql:"-"`
	LastMessage Message     `json:"last_message,omitempty" sql:"-"`
}

Thread holds all messages between two (or more, eventually) Users

func GetByUsers

func GetByUsers(db *gorm.DB, userIDs ...string) (thread Thread, err error)

GetByUsers returns a thread based on a group of users

func GetThread

func GetThread(threadID string, db *gorm.DB) (thread Thread, err error)

GetThread will get the thread or throw an error if nothing is found

func NewThread

func NewThread(userID string, b ThreadCreatorBinding) (t Thread, errs models.ValidationErrors)

func (*Thread) GetLastMessage

func (t *Thread) GetLastMessage(db *gorm.DB) error

GetLastMessage returns the most recent message in the thread

func (*Thread) GetUsers

func (t *Thread) GetUsers(db *gorm.DB) error

type ThreadCreatorBinding

type ThreadCreatorBinding struct {
	UserIDs []string `json:"user_ids" binding:"required"`
}

type ThreadUser

type ThreadUser struct {
	ID        string    `json:"id" gorm:"primary_key" sql:"type:uuid;default:uuid_generate_v4()"`
	UserID    string    `json:"user_id" sql:"type:uuid"`
	ThreadID  string    `json:"thread_id" sql:"type:uuid"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	User users.User `json:"user" sql:"-"`
}

MessageThreadUser is a join table between Message and MessageThread

type ThreadUsers

type ThreadUsers []ThreadUser

func GetThreadUsers

func GetThreadUsers(userID string, db *gorm.DB) (mtus ThreadUsers, err error)

GetThreadUsers returns all the ThreadUsers for a user

func (*ThreadUsers) CollectUsers

func (mtus *ThreadUsers) CollectUsers(us []users.User)

func (ThreadUsers) GetUserIDs

func (mtus ThreadUsers) GetUserIDs() (userIDs []string)

type Threads

type Threads []Thread

func ListThreads

func ListThreads(userID string, db *gorm.DB) (threads Threads, err error)

ListThreads returns a list of threads

func (*Threads) CollectLastMessages

func (ts *Threads) CollectLastMessages(db *gorm.DB) error

func (*Threads) CollectUsers

func (ts *Threads) CollectUsers(db *gorm.DB) error

Jump to

Keyboard shortcuts

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