()
| 254 | } |
| 255 | |
| 256 | export function useUpdateManagedAgentMutation() { |
| 257 | const queryClient = useQueryClient(); |
| 258 | |
| 259 | return useMutation({ |
| 260 | mutationFn: (input: UpdateManagedAgentInput) => updateManagedAgent(input), |
| 261 | onSuccess: (result) => { |
| 262 | queryClient.setQueryData<ManagedAgent[]>( |
| 263 | managedAgentsQueryKey, |
| 264 | (current) => { |
| 265 | if (!current) return current; |
| 266 | return current.map((agent) => |
| 267 | agent.pubkey === result.agent.pubkey ? result.agent : agent, |
| 268 | ); |
| 269 | }, |
| 270 | ); |
| 271 | }, |
| 272 | onSettled: async (_data, _error, variables) => { |
| 273 | // Backend republishes kind:0 on a name change (sync_managed_agent_profile), |
| 274 | // so the relay has fresh profile data — but the desktop's React Query cache |
| 275 | // for ["user-profile", pubkey] has a 60s staleTime and will not refetch on |
| 276 | // its own. Invalidate explicitly so the profile pane re-renders against |
| 277 | // the new display name / about / NIP-05 immediately. Also poke any |
| 278 | // ["users-batch", ...] entries that include this pubkey so sidebar member |
| 279 | // rows, channel header chips, and message author labels refresh too. |
| 280 | const lowerPubkey = variables.pubkey.toLowerCase(); |
| 281 | |
| 282 | // The users-batch delta fetch resolves from per-pubkey |
| 283 | // ["users-batch-entry", pubkey] entries with their own 60s freshness — |
| 284 | // invalidating the aggregate queries alone would just re-read the stale |
| 285 | // entry. Evict it first so the re-run refetches this profile. |
| 286 | evictUsersBatchEntries(queryClient, [lowerPubkey]); |
| 287 | |
| 288 | await Promise.all([ |
| 289 | queryClient.invalidateQueries({ queryKey: managedAgentsQueryKey }), |
| 290 | queryClient.invalidateQueries({ queryKey: relayAgentsQueryKey }), |
| 291 | queryClient.invalidateQueries({ |
| 292 | queryKey: ["user-profile", lowerPubkey], |
| 293 | }), |
| 294 | queryClient.invalidateQueries({ |
| 295 | predicate: (query) => |
| 296 | query.queryKey[0] === "users-batch" && |
| 297 | query.queryKey.includes(lowerPubkey), |
| 298 | }), |
| 299 | ]); |
| 300 | }, |
| 301 | }); |
| 302 | } |
| 303 | |
| 304 | export function useCreatePersonaMutation() { |
| 305 | const queryClient = useQueryClient(); |
no test coverage detected