49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package chatcore
|
|
|
|
type SessionType string
|
|
|
|
const (
|
|
SessionTypeGroup SessionType = "group"
|
|
SessionTypeDM SessionType = "dm"
|
|
)
|
|
|
|
type MessageType string
|
|
|
|
const (
|
|
MessageTypeText MessageType = "text"
|
|
MessageTypeImage MessageType = "image"
|
|
MessageTypeSystem MessageType = "system"
|
|
)
|
|
|
|
type Session struct {
|
|
Id int64 `json:"id" bson:"_id"`
|
|
Type SessionType `json:"type" bson:"type"`
|
|
Name string `json:"name" bson:"name"`
|
|
CreatorId int64 `json:"creatorId" bson:"creatorId"`
|
|
Participants []int64 `json:"participants" bson:"participants"`
|
|
LastMessage string `json:"lastMessage" bson:"lastMessage"`
|
|
LastMessageAt int64 `json:"lastMessageAt" bson:"lastMessageAt"`
|
|
CreatedAt int64 `json:"createdAt" bson:"createdAt"`
|
|
UpdatedAt int64 `json:"updatedAt" bson:"updatedAt"`
|
|
}
|
|
|
|
type Message struct {
|
|
Id int64 `json:"id" bson:"_id"`
|
|
SessionId int64 `json:"sessionId" bson:"sessionId"`
|
|
SenderId int64 `json:"senderId" bson:"senderId"`
|
|
Type MessageType `json:"type" bson:"type"`
|
|
Content string `json:"content" bson:"content"`
|
|
CreatedAt int64 `json:"createdAt" bson:"createdAt"`
|
|
}
|
|
|
|
type Store interface {
|
|
CreateSession(typ SessionType, name string, creatorId int64, participants []int64) (*Session, error)
|
|
GetSession(id int64) (*Session, error)
|
|
ListUserSessions(userId int64, page, limit int) []*Session
|
|
AddParticipant(sessionId, userId int64) error
|
|
RemoveParticipant(sessionId, userId int64) error
|
|
DeleteSession(id int64)
|
|
AddMessage(sessionId, senderId int64, msgType MessageType, content string) (*Message, error)
|
|
GetMessages(sessionId int64, page, limit int) []*Message
|
|
}
|