fix: preserve pending support state on private profiles
Deploy olons-server production / deploy (push) Successful in 2m42s
Deploy olons-server production / deploy (push) Successful in 2m42s
This commit is contained in:
+21
-23
@@ -125,42 +125,42 @@ func (s *Service) OpenSession(ctx context.Context, tenantID, memberID, serviceID
|
||||
if !strings.EqualFold(strings.TrimSpace(imSession.UserID), strings.TrimSpace(identity.IMUserID)) {
|
||||
return nil, ErrIMUnavailable
|
||||
}
|
||||
var conversation *imclient.Conversation
|
||||
profile, err := s.im.UserProfile(ctx, imSession.Token, agent.IMUserID)
|
||||
relationship := ""
|
||||
if err != nil {
|
||||
if !imclient.IsPermissionDenied(err) {
|
||||
return nil, fmt.Errorf("query customer service relationship: %w", err)
|
||||
}
|
||||
conversation, err = s.im.EnsureP2P(ctx, imSession.Token, agent.IMUserID,
|
||||
fmt.Sprintf("p2p:%s:%s", identity.IMUserID, agent.IMUserID))
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
}
|
||||
relationship := ""
|
||||
if profile != nil {
|
||||
relationship = strings.TrimSpace(profile.Relationship)
|
||||
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)
|
||||
} else {
|
||||
relationship = strings.TrimSpace(conversation.Relationship)
|
||||
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
|
||||
}
|
||||
if requestErr != nil && !imclient.IsConflict(requestErr) {
|
||||
return nil, fmt.Errorf("create customer service friend request: %w", requestErr)
|
||||
}
|
||||
if requestErr != nil {
|
||||
conversation, err = s.im.EnsureP2P(ctx, imSession.Token, agent.IMUserID,
|
||||
fmt.Sprintf("p2p:%s:%s", identity.IMUserID, agent.IMUserID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("refresh customer service relationship: %w", err)
|
||||
}
|
||||
relationship = strings.TrimSpace(conversation.Relationship)
|
||||
return nil, ErrRelationDenied
|
||||
} else {
|
||||
relationship = strings.TrimSpace(request.Status)
|
||||
conversation = nil
|
||||
}
|
||||
if relationship != "accepted" && relationship != "friend" {
|
||||
return nil, ErrRelationPending
|
||||
@@ -170,12 +170,10 @@ func (s *Service) OpenSession(ctx context.Context, tenantID, memberID, serviceID
|
||||
default:
|
||||
return nil, ErrRelationDenied
|
||||
}
|
||||
if conversation == nil {
|
||||
conversation, err = s.im.EnsureP2P(ctx, imSession.Token, agent.IMUserID,
|
||||
fmt.Sprintf("p2p:%s:%s", identity.IMUserID, agent.IMUserID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ensure customer service conversation: %w", err)
|
||||
}
|
||||
conversation, err := s.im.EnsureP2P(ctx, imSession.Token, agent.IMUserID,
|
||||
fmt.Sprintf("p2p:%s:%s", identity.IMUserID, agent.IMUserID))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("ensure customer service conversation: %w", err)
|
||||
}
|
||||
if strings.TrimSpace(conversation.Topic) == "" || (conversation.Relationship != "" && conversation.Relationship != "friend") || !conversation.CanSend {
|
||||
return nil, ErrRelationDenied
|
||||
|
||||
Reference in New Issue
Block a user