Skip to main content

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>
}
PropertyTypeDescription
edgesEdge[]All outgoing relationship edges with to_user profile data
edgesByTypeRecord<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>
}
ParameterTypeRequiredDescription
personIdstringYesThe other user's ID
PropertyTypeDescription
relationshipsEdge[]All edges from the current user to this person
savingbooleanWhether 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>
}
PropertyTypeDescription
outgoingEdge[]Edges from the profile user to others (excludes current viewer)
incomingEdge[]Edges from others to the profile user (excludes current viewer)
mutualEdgesEdge[]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>
}
PropertyTypeDescription
relationshipsEdge[]Visible relationships with to_user profile data
byTypeRecord<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 useRelationshipEncryption reports isInitialized and isUnlocked, create/update operations encrypt label and notes via the save_encrypted_relationship RPC; otherwise, plaintext is stored in the relationship_edges table directly.
  • The visibility field controls who can see the edge: 'private' (only you), 'mutual' (both parties), 'friends' (your friends), or 'public'.
  • useVisibleRelationships excludes private edges and hides the current viewer's own edges (those are managed separately).
  • useRelationshipsWith ensures edge ownership via from_user_id checks on all mutations.

Last updated: 2026-02-07