44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package message
|
|
|
|
import "context"
|
|
|
|
type Message struct {
|
|
ID int64
|
|
ConversationID int64
|
|
SenderID int64
|
|
ClientMsgID string
|
|
Type int
|
|
Content []byte
|
|
Status int
|
|
CreatedAtMS int64
|
|
}
|
|
|
|
type Repository interface {
|
|
Create(ctx context.Context, message *Message) error
|
|
GetByID(ctx context.Context, id int64) (*Message, error)
|
|
GetByClientMsgID(ctx context.Context, senderID, conversationID int64, clientMsgID string) (*Message, error)
|
|
ListByConversation(ctx context.Context, conversationID, lastMsgID int64, limit int) ([]*Message, error)
|
|
}
|
|
|
|
type SendRequest struct {
|
|
ConversationID int64
|
|
SenderID int64
|
|
DeviceID uint64
|
|
ClientMsgID string
|
|
MsgID int64
|
|
Type int
|
|
Content []byte
|
|
}
|
|
|
|
type SendResponse struct {
|
|
MsgID int64
|
|
ClientMsgID string
|
|
ServerTimeMS int64
|
|
}
|
|
|
|
// Service owns persist + enqueue. SEND_ACK happens only after both succeed.
|
|
type Service interface {
|
|
GenerateMsgID(ctx context.Context) (int64, error)
|
|
SendMessage(ctx context.Context, req *SendRequest) (*SendResponse, error)
|
|
}
|