feat: add chapter eight call records
This commit is contained in:
@@ -1014,6 +1014,56 @@ func (messagesMapper) Edit(tenantID types.TenantID, topic string, seq int, actor
|
||||
return tenantAdp.TenantMessageEdit(tenantID, topic, seq, actor, expectedVersion, head, content, reason, editedAt)
|
||||
}
|
||||
|
||||
type CallsPersistenceInterface interface {
|
||||
Create(tenantID types.TenantID, record *types.CallRecord) error
|
||||
Accept(tenantID types.TenantID, callID string, seq int, acceptedAt time.Time) error
|
||||
Finish(tenantID types.TenantID, callID string, seq int, status string, durationMS int64, finishedAt time.Time) error
|
||||
}
|
||||
|
||||
type callsMapper struct{}
|
||||
|
||||
var Calls CallsPersistenceInterface
|
||||
|
||||
func (callsMapper) Create(tenantID types.TenantID, record *types.CallRecord) error {
|
||||
if record == nil || record.TenantID != tenantID || strings.TrimSpace(record.CallID) == "" ||
|
||||
record.Topic == "" || record.SeqID <= 0 || record.CallerID.IsZero() || record.CalleeID.IsZero() ||
|
||||
record.CallType == "" {
|
||||
return types.ErrMalformed
|
||||
}
|
||||
tenantAdp, err := tenantBusinessAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tenantAdp.TenantCallCreate(tenantID, record)
|
||||
}
|
||||
|
||||
func (callsMapper) Accept(tenantID types.TenantID, callID string, seq int, acceptedAt time.Time) error {
|
||||
if strings.TrimSpace(callID) == "" || seq <= 0 || acceptedAt.IsZero() {
|
||||
return types.ErrMalformed
|
||||
}
|
||||
tenantAdp, err := tenantBusinessAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tenantAdp.TenantCallAccept(tenantID, callID, seq, acceptedAt)
|
||||
}
|
||||
|
||||
func (callsMapper) Finish(tenantID types.TenantID, callID string, seq int, status string, durationMS int64, finishedAt time.Time) error {
|
||||
switch status {
|
||||
case types.CallStatusFinished, types.CallStatusMissed, types.CallStatusDeclined, types.CallStatusDisconnected:
|
||||
default:
|
||||
return types.ErrMalformed
|
||||
}
|
||||
if strings.TrimSpace(callID) == "" || seq <= 0 || finishedAt.IsZero() || durationMS < 0 {
|
||||
return types.ErrMalformed
|
||||
}
|
||||
tenantAdp, err := tenantBusinessAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tenantAdp.TenantCallFinish(tenantID, callID, seq, status, durationMS, finishedAt)
|
||||
}
|
||||
|
||||
type RelationsPersistenceInterface interface {
|
||||
CreateFriendRequest(tenantID types.TenantID, req *types.FriendRequest) (*types.FriendRequest, error)
|
||||
ListFriendRequests(tenantID types.TenantID, uid types.Uid, direction, status, cursor string, limit int) ([]types.FriendRequestListItem, string, error)
|
||||
@@ -2181,6 +2231,7 @@ func init() {
|
||||
Topics = topicsMapper{}
|
||||
Subs = subsMapper{}
|
||||
Messages = messagesMapper{}
|
||||
Calls = callsMapper{}
|
||||
Devices = deviceMapper{}
|
||||
Files = fileMapper{}
|
||||
PCache = pcacheMapper{}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
CallStatusStarted = "started"
|
||||
CallStatusAccepted = "accepted"
|
||||
CallStatusFinished = "finished"
|
||||
CallStatusMissed = "missed"
|
||||
CallStatusDeclined = "declined"
|
||||
CallStatusDisconnected = "disconnected"
|
||||
)
|
||||
|
||||
type CallRecord struct {
|
||||
TenantID TenantID `db:"tenant_id" json:"-" bson:"tenant_id"`
|
||||
CallID string `db:"call_id"`
|
||||
Topic string
|
||||
SeqID int `db:"seq_id"`
|
||||
CallerID Uid `db:"caller_id"`
|
||||
CalleeID Uid `db:"callee_id"`
|
||||
CallType string `db:"call_type"`
|
||||
Status string
|
||||
EndReason string `db:"end_reason"`
|
||||
DurationMS int64 `db:"duration_ms"`
|
||||
StartedAt time.Time `db:"started_at"`
|
||||
AcceptedAt *time.Time `db:"accepted_at"`
|
||||
FinishedAt *time.Time `db:"finished_at"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
Reference in New Issue
Block a user