feat: complete im p2p relationship onboarding
This commit is contained in:
+43
-5
@@ -997,7 +997,9 @@ func (messagesMapper) Edit(tenantID types.TenantID, topic string, seq int, actor
|
||||
|
||||
type RelationsPersistenceInterface interface {
|
||||
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)
|
||||
ResolveFriendRequest(tenantID types.TenantID, requestID string, actor types.Uid, status string, handledAt time.Time) (*types.FriendRequest, error)
|
||||
ListFriends(tenantID types.TenantID, uid types.Uid, query, initial, cursor string, limit int) ([]types.FriendListItem, string, error)
|
||||
GetRelationshipContext(tenantID types.TenantID, userID, peerID types.Uid, topic string) (*types.RelationshipContext, error)
|
||||
CanSendP2P(tenantID types.TenantID, userID, peerID types.Uid) (bool, string, error)
|
||||
BlockUser(tenantID types.TenantID, blockerID, blockedID types.Uid, now time.Time) (*types.UserBlock, error)
|
||||
@@ -1020,6 +1022,30 @@ func (relationsMapper) CreateFriendRequest(tenantID types.TenantID, req *types.F
|
||||
return tenantAdp.TenantFriendRequestCreate(tenantID, req)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
switch direction {
|
||||
case "", "inbound", "outbound", "all":
|
||||
default:
|
||||
return nil, "", types.ErrMalformed
|
||||
}
|
||||
switch status {
|
||||
case "", "all", types.FriendRequestPending, types.FriendRequestAccepted, types.FriendRequestRejected, types.FriendRequestExpired:
|
||||
default:
|
||||
return nil, "", types.ErrMalformed
|
||||
}
|
||||
if limit <= 0 || limit > 100 {
|
||||
limit = 20
|
||||
}
|
||||
tenantAdp, err := tenantBusinessAdapter(tenantID)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return tenantAdp.TenantFriendRequestList(tenantID, uid, direction, status, cursor, limit)
|
||||
}
|
||||
|
||||
func (relationsMapper) ResolveFriendRequest(tenantID types.TenantID, requestID string, actor types.Uid, status string, handledAt time.Time) (*types.FriendRequest, error) {
|
||||
if strings.TrimSpace(requestID) == "" || actor.IsZero() || (status != types.FriendRequestAccepted && status != types.FriendRequestRejected) {
|
||||
return nil, types.ErrMalformed
|
||||
@@ -1028,18 +1054,30 @@ func (relationsMapper) ResolveFriendRequest(tenantID types.TenantID, requestID s
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if status == types.FriendRequestAccepted {
|
||||
return tenantAdp.TenantFriendRequestAccept(tenantID, requestID, actor, handledAt)
|
||||
}
|
||||
req, err := tenantAdp.TenantFriendRequestResolve(tenantID, requestID, actor, status, handledAt)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if status == types.FriendRequestAccepted {
|
||||
if err := tenantAdp.TenantFriendshipUpsertPair(tenantID, req.ApplicantID, req.TargetID, "", handledAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (relationsMapper) ListFriends(tenantID types.TenantID, uid types.Uid, query, initial, cursor string, limit int) ([]types.FriendListItem, string, error) {
|
||||
if uid.IsZero() {
|
||||
return nil, "", types.ErrMalformed
|
||||
}
|
||||
if limit <= 0 || limit > 100 {
|
||||
limit = 50
|
||||
}
|
||||
tenantAdp, err := tenantBusinessAdapter(tenantID)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
return tenantAdp.TenantFriendshipList(tenantID, uid, query, initial, cursor, limit)
|
||||
}
|
||||
|
||||
func (relationsMapper) GetRelationshipContext(tenantID types.TenantID, userID, peerID types.Uid, topic string) (*types.RelationshipContext, error) {
|
||||
if userID.IsZero() || peerID.IsZero() || userID == peerID {
|
||||
return nil, types.ErrMalformed
|
||||
|
||||
@@ -63,3 +63,14 @@ type RelationshipContext struct {
|
||||
PendingStatus string `json:"pending_status,omitempty"`
|
||||
Peer *User `json:"peer,omitempty"`
|
||||
}
|
||||
|
||||
type FriendListItem struct {
|
||||
Friendship Friendship
|
||||
Peer *User
|
||||
}
|
||||
|
||||
type FriendRequestListItem struct {
|
||||
Request FriendRequest
|
||||
Peer *User
|
||||
Direction string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user