Documentation ¶
Index ¶
- Constants
- Variables
- func GetThreadIDs(userID string, db *gorm.DB) (threadIDs []string, err error)
- func GetUserIDs(userID string, db *gorm.DB) (userIDs []string, err error)
- func HasUnread(userID, threadID string, db *gorm.DB) (bool, error)
- func HasUser(userID, threadID string, db *gorm.DB) (bool, error)
- func MarkAllMessagesRead(userID, threadID string, db *gorm.DB) error
- func UnreadCount(userID string, db *gorm.DB) (count int, err error)
- type Message
- type MessageCreatorBinding
- type Messages
- type Thread
- type ThreadCreatorBinding
- type ThreadUser
- type ThreadUsers
- type Threads
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 ¶
GetThreadIDs returns all the threadIDs for a particular user
func GetUserIDs ¶
GetUserIDs returns a list of user ids with whom a user has a thread
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 NewMessage ¶
func NewMessage(b MessageCreatorBinding) (Message, models.ValidationErrors)
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 Messages ¶
type Messages []Message
func GetMessagesAfter ¶
func (Messages) GetUserIDs ¶
GetUserIDs satisfies dao.UserIDerSlice
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 ¶
GetByUsers returns a thread based on a group of users
func NewThread ¶
func NewThread(userID string, b ThreadCreatorBinding) (t Thread, errs models.ValidationErrors)
func (*Thread) GetLastMessage ¶
GetLastMessage returns the most recent message in the thread
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)
Click to show internal directories.
Click to hide internal directories.