feat(call): enhance call handling with user connection events and active call management
- 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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user