useRelationshipEdges
Location: src/hooks/useRelationshipEdges.js
Overview
Provides hooks for managing relationship edges between users. Edges are directional (from the current user to another person) and support optional client-side encryption for sensitive fields (label and notes). Includes useMyRelationshipEdges for fetching all outgoing edges, useRelationshipsWith for managing edges with a specific person, useVisibleRelationships for viewing public relationships on a profile, and useMutualRelationships for fetching mutual/visible connections.
Exported Hooks
useMyRelationshipEdges
Fetches all relationship edges from the current user, with automatic decryption if encryption is unlocked.
function useMyRelationshipEdges(): {
edges: Edge[],
edgesByType: Record<string, Edge[]>,
loading: boolean,
error: string | null,
refetch: () => Promise<void>
}
| Property | Type | Description |
|---|---|---|
edges | Edge[] | All outgoing relationship edges with to_user profile data |
edgesByType | Record<string, Edge[]> | Edges grouped by type_name |
useRelationshipsWith
Full CRUD for relationship edges with a specific person.
function useRelationshipsWith(personId: string): {
relationships: Edge[],
loading: boolean,
error: string | null,
saving: boolean,
createEdge: (options: { typeName, label?, sinceDate?, notes?, visibility? }) => Promise<{ data?: Edge, error?: string }>,
updateEdge: (edgeId: string, updates: object) => Promise<{ data?: Edge, error?: string }>,
deleteEdge: (edgeId: string) => Promise<{ success?: boolean, error?: string }>,
refetch: () => Promise<void>
}
| Parameter | Type | Required | Description |
|---|---|---|---|
personId | string | Yes | The other user's ID |
| Property | Type | Description |
|---|---|---|
relationships | Edge[] | All edges from the current user to this person |
saving | boolean | Whether a create/update/delete operation is in progress |
createEdge | (options) => Promise<Result> | Create a new edge. If encryption is initialized and unlocked, data is encrypted. Options: typeName (required), label, sinceDate, notes, visibility (default 'private'). |
updateEdge | (edgeId, updates) => Promise<Result> | Update an edge. Handles encryption transparently. |
deleteEdge | (edgeId) => Promise<Result> | Delete an edge (ownership verified by from_user_id). |
useVisibleRelationships
Fetches relationships visible on a profile (non-private).
function useVisibleRelationships(profileUserId: string): {
outgoing: Edge[],
incoming: Edge[],
mutualEdges: Edge[],
loading: boolean,
error: string | null,
refetch: () => Promise<void>
}
| Property | Type | Description |
|---|---|---|
outgoing | Edge[] | Edges from the profile user to others (excludes current viewer) |
incoming | Edge[] | Edges from others to the profile user (excludes current viewer) |
mutualEdges | Edge[] | Edges with a mutual_id involving the profile user |
useMutualRelationships
Fetches relationships the profile owner has made visible (mutual, friends, or public visibility).
function useMutualRelationships(profileUserId: string): {
relationships: Edge[],
byType: Record<string, Edge[]>,
loading: boolean,
error: string | null,
refetch: () => Promise<void>
}
| Property | Type | Description |
|---|---|---|
relationships | Edge[] | Visible relationships with to_user profile data |
byType | Record<string, Edge[]> | Relationships grouped by type_name |
Usage
import { useRelationshipsWith } from '../hooks/useRelationshipEdges';
function RelationshipManager({ friendId }) {
const { relationships, saving, createEdge, deleteEdge } = useRelationshipsWith(friendId);
return (
<div>
{relationships.map(edge => (
<div key={edge.id}>
<span>{edge.type_name}: {edge.label}</span>
<button onClick={() => deleteEdge(edge.id)}>Remove</button>
</div>
))}
<button onClick={() => createEdge({
typeName: 'Friend',
label: 'College friend',
visibility: 'mutual'
})}>
Add Relationship
</button>
</div>
);
}
Notes
- Encryption is handled transparently: if
useRelationshipEncryptionreportsisInitializedandisUnlocked, create/update operations encryptlabelandnotesvia thesave_encrypted_relationshipRPC; otherwise, plaintext is stored in therelationship_edgestable directly. - The
visibilityfield controls who can see the edge:'private'(only you),'mutual'(both parties),'friends'(your friends), or'public'. useVisibleRelationshipsexcludes private edges and hides the current viewer's own edges (those are managed separately).useRelationshipsWithensures edge ownership viafrom_user_idchecks on all mutations.
Last updated: 2026-02-07