feat: add trusted customer service friendships
Deploy im-server production / deploy (push) Successful in 11m38s
Deploy im-server production / deploy (push) Successful in 11m38s
This commit is contained in:
@@ -3065,6 +3065,7 @@ func validUserProfilePatch(patch types.UserProfilePatch) bool {
|
||||
}
|
||||
|
||||
type RelationsPersistenceInterface interface {
|
||||
AddFriendDirect(tenantID types.TenantID, userID, peerID types.Uid, now time.Time) error
|
||||
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)
|
||||
CountPendingFriendRequests(tenantID types.TenantID, uid types.Uid) (int, error)
|
||||
@@ -3153,6 +3154,41 @@ func (relationsMapper) CreateFriendRequest(tenantID types.TenantID, req *types.F
|
||||
return tenantAdp.TenantFriendRequestCreate(tenantID, req)
|
||||
}
|
||||
|
||||
// AddFriendDirect creates a symmetric friendship for trusted server-side
|
||||
// workflows, such as opening a customer-service conversation. It deliberately
|
||||
// does not create a friend-request record, but it still honors either user's
|
||||
// block list.
|
||||
func (relationsMapper) AddFriendDirect(tenantID types.TenantID, userID, peerID types.Uid, now time.Time) error {
|
||||
if userID.IsZero() || peerID.IsZero() || userID == peerID {
|
||||
return types.ErrMalformed
|
||||
}
|
||||
if _, err := Users.Get(tenantID, userID); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := Users.Get(tenantID, peerID); err != nil {
|
||||
return err
|
||||
}
|
||||
tenantAdp, err := tenantBusinessAdapter(tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
relationship, err := relationshipContext(tenantAdp, tenantID, userID, peerID, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if relationship.Relationship == types.RelationshipBlockedByMe || relationship.Relationship == types.RelationshipBlockedByPeer {
|
||||
return types.ErrPermissionDenied
|
||||
}
|
||||
if now.IsZero() {
|
||||
now = time.Now().UTC()
|
||||
}
|
||||
if err = tenantAdp.TenantFriendshipUpsertPair(tenantID, userID, peerID, userID.P2PName(peerID), now); err != nil {
|
||||
return err
|
||||
}
|
||||
cacheFriendPair(tenantID, userID, peerID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (relationsMapper) ListFriendRequests(tenantID types.TenantID, uid types.Uid, direction, status, cursor string, limit int) ([]types.FriendRequestListItem, string, error) {
|
||||
if uid.IsZero() {
|
||||
return nil, "", types.ErrMalformed
|
||||
|
||||
Reference in New Issue
Block a user