feat: directly add customer service friend
Deploy olons-server production / deploy (push) Successful in 3m26s
Deploy olons-server production / deploy (push) Successful in 3m26s
This commit is contained in:
@@ -33,7 +33,7 @@ type IM interface {
|
||||
LoginBasic(context.Context, string, string, string, string) (*imclient.Session, error)
|
||||
ResetPassword(context.Context, string, string) error
|
||||
UserProfile(context.Context, string, string) (*imclient.UserProfile, error)
|
||||
CreateFriendRequest(context.Context, string, string, string) (*imclient.FriendRequest, error)
|
||||
AddFriendDirect(context.Context, string, string) (*imclient.DirectFriendResult, error)
|
||||
EnsureP2P(context.Context, string, string, string) (*imclient.Conversation, error)
|
||||
}
|
||||
|
||||
@@ -131,42 +131,19 @@ func (s *Service) OpenSession(ctx context.Context, tenantID, memberID, serviceID
|
||||
if !imclient.IsPermissionDenied(err) {
|
||||
return nil, fmt.Errorf("query customer service relationship: %w", err)
|
||||
}
|
||||
key := fmt.Sprintf("customer-service:%d:%d:%d", tenantID, memberID, serviceID)
|
||||
request, requestErr := s.im.CreateFriendRequest(ctx, imSession.Token, agent.IMUserID, key)
|
||||
if imclient.IsFriendRequestConflict(requestErr) {
|
||||
return nil, ErrRelationPending
|
||||
}
|
||||
if requestErr != nil {
|
||||
if imclient.IsConflict(requestErr) {
|
||||
return nil, ErrRelationDenied
|
||||
}
|
||||
return nil, fmt.Errorf("create customer service friend request: %w", requestErr)
|
||||
}
|
||||
relationship = strings.TrimSpace(request.Status)
|
||||
relationship = "unknown"
|
||||
} else {
|
||||
relationship = strings.TrimSpace(profile.Relationship)
|
||||
}
|
||||
switch relationship {
|
||||
case "friend":
|
||||
case "none", "":
|
||||
key := fmt.Sprintf("customer-service:%d:%d:%d", tenantID, memberID, serviceID)
|
||||
request, requestErr := s.im.CreateFriendRequest(ctx, imSession.Token, agent.IMUserID, key)
|
||||
if imclient.IsFriendRequestConflict(requestErr) {
|
||||
return nil, ErrRelationPending
|
||||
case "none", "", "pending_inbound", "pending_outbound", "pending", "unknown":
|
||||
if _, err = s.im.AddFriendDirect(ctx, identity.IMUserID, agent.IMUserID); err != nil {
|
||||
if imclient.IsPermissionDenied(err) || imclient.IsConflict(err) {
|
||||
return nil, ErrRelationDenied
|
||||
}
|
||||
return nil, fmt.Errorf("add customer service as friend: %w", err)
|
||||
}
|
||||
if requestErr != nil && !imclient.IsConflict(requestErr) {
|
||||
return nil, fmt.Errorf("create customer service friend request: %w", requestErr)
|
||||
}
|
||||
if requestErr != nil {
|
||||
return nil, ErrRelationDenied
|
||||
} else {
|
||||
relationship = strings.TrimSpace(request.Status)
|
||||
}
|
||||
if relationship != "accepted" && relationship != "friend" {
|
||||
return nil, ErrRelationPending
|
||||
}
|
||||
case "pending_inbound", "pending_outbound", "pending":
|
||||
return nil, ErrRelationPending
|
||||
default:
|
||||
return nil, ErrRelationDenied
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user