feat(call): enhance call handling with user connection events and active call management
All checks were successful
Build Backend / build (push) Successful in 13m52s
Build Backend / build-docker (push) Successful in 1m8s

- Updated CallService to handle user connection and disconnection events, allowing for automatic management of active calls based on user status.
- Introduced methods to retrieve active calls for users and send pending call invites when users reconnect.
- Modified the Invite method to return the callee's online status, improving user experience during call invitations.
- Enhanced WSHandler to support connection and disconnection event handlers, ensuring accurate call state management.
This commit is contained in:
lafay
2026-03-28 04:34:49 +08:00
parent 63cfbad65c
commit d357998321
4 changed files with 255 additions and 35 deletions

View File

@@ -16,6 +16,7 @@ type CallRepository interface {
GetCallByIDWithParticipants(id string) (*model.CallSession, error)
UpdateCall(call *model.CallSession) error
GetActiveCallByConversationID(conversationID string) (*model.CallSession, error)
GetActiveCallsByUserID(userID string) ([]model.CallSession, error) // 获取用户参与的活跃通话
// 通话参与者操作
CreateCallParticipant(participant *model.CallParticipant) error
@@ -83,6 +84,25 @@ func (r *callRepository) GetActiveCallByConversationID(conversationID string) (*
return &call, nil
}
// GetActiveCallsByUserID 获取用户参与的所有活跃通话
func (r *callRepository) GetActiveCallsByUserID(userID string) ([]model.CallSession, error) {
var calls []model.CallSession
// 子查询获取用户参与的通话ID
subQuery := r.db.Model(&model.CallParticipant{}).
Select("DISTINCT call_id").
Where("user_id = ?", userID)
err := r.db.Where("id IN (?) AND status IN ?", subQuery, []model.CallStatus{
model.CallStatusCalling,
model.CallStatusConnected,
}).Preload("Participants").Find(&calls).Error
if err != nil {
return nil, err
}
return calls, nil
}
// CreateCallParticipant 创建通话参与者
func (r *callRepository) CreateCallParticipant(participant *model.CallParticipant) error {
return r.db.Create(participant).Error