Replace getAgent() with reading agent (#4243)

* Replace getAgent() with agent

* Replace {agent} with agent
This commit is contained in:
dan 2024-05-28 16:37:51 +01:00 committed by GitHub
parent 8a2f43c218
commit 9bd411c151
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
74 changed files with 400 additions and 438 deletions

View file

@ -14,12 +14,12 @@ export function useUpdateActorDeclaration({
}) {
const queryClient = useQueryClient()
const {currentAccount} = useSession()
const {getAgent} = useAgent()
const agent = useAgent()
return useMutation({
mutationFn: async (allowIncoming: 'all' | 'none' | 'following') => {
if (!currentAccount) throw new Error('Not logged in')
const result = await getAgent().api.com.atproto.repo.putRecord({
const result = await agent.api.com.atproto.repo.putRecord({
repo: currentAccount.did,
collection: 'chat.bsky.actor.declaration',
rkey: 'self',
@ -64,13 +64,13 @@ export function useUpdateActorDeclaration({
// for use in the settings screen for testing
export function useDeleteActorDeclaration() {
const {currentAccount} = useSession()
const {getAgent} = useAgent()
const agent = useAgent()
return useMutation({
mutationFn: async () => {
if (!currentAccount) throw new Error('Not logged in')
// TODO(sam): remove validate: false once PDSes have the new lexicon
const result = await getAgent().api.com.atproto.repo.deleteRecord({
const result = await agent.api.com.atproto.repo.deleteRecord({
repo: currentAccount.did,
collection: 'chat.bsky.actor.declaration',
rkey: 'self',

View file

@ -11,12 +11,12 @@ const RQKEY_ROOT = 'convo'
export const RQKEY = (convoId: string) => [RQKEY_ROOT, convoId]
export function useConvoQuery(convo: ChatBskyConvoDefs.ConvoView) {
const {getAgent} = useAgent()
const agent = useAgent()
return useQuery({
queryKey: RQKEY(convo.id),
queryFn: async () => {
const {data} = await getAgent().api.chat.bsky.convo.getConvo(
const {data} = await agent.api.chat.bsky.convo.getConvo(
{convoId: convo.id},
{headers: DM_SERVICE_HEADERS},
)
@ -30,7 +30,7 @@ export function useConvoQuery(convo: ChatBskyConvoDefs.ConvoView) {
export function useMarkAsReadMutation() {
const optimisticUpdate = useOnMarkAsRead()
const queryClient = useQueryClient()
const {getAgent} = useAgent()
const agent = useAgent()
return useMutation({
mutationFn: async ({
@ -42,7 +42,7 @@ export function useMarkAsReadMutation() {
}) => {
if (!convoId) throw new Error('No convoId provided')
await getAgent().api.chat.bsky.convo.updateRead(
await agent.api.chat.bsky.convo.updateRead(
{
convoId,
messageId,

View file

@ -18,11 +18,11 @@ export function useGetConvoForMembers({
onError?: (error: Error) => void
}) {
const queryClient = useQueryClient()
const {getAgent} = useAgent()
const agent = useAgent()
return useMutation({
mutationFn: async (members: string[]) => {
const {data} = await getAgent().api.chat.bsky.convo.getConvoForMembers(
const {data} = await agent.api.chat.bsky.convo.getConvoForMembers(
{members: members},
{headers: DM_SERVICE_HEADERS},
)
@ -44,16 +44,13 @@ export function useGetConvoForMembers({
* Gets the conversation ID for a given DID. Returns null if it's not possible to message them.
*/
export function useMaybeConvoForUser(did: string) {
const {getAgent} = useAgent()
const agent = useAgent()
return useQuery({
queryKey: RQKEY(did),
queryFn: async () => {
const convo = await getAgent()
.api.chat.bsky.convo.getConvoForMembers(
{members: [did]},
{headers: DM_SERVICE_HEADERS},
)
const convo = await agent.api.chat.bsky.convo
.getConvoForMembers({members: [did]}, {headers: DM_SERVICE_HEADERS})
.catch(() => ({success: null}))
if (convo.success) {

View file

@ -17,13 +17,13 @@ export function useLeaveConvo(
},
) {
const queryClient = useQueryClient()
const {getAgent} = useAgent()
const agent = useAgent()
return useMutation({
mutationFn: async () => {
if (!convoId) throw new Error('No convoId provided')
const {data} = await getAgent().api.chat.bsky.convo.leaveConvo(
const {data} = await agent.api.chat.bsky.convo.leaveConvo(
{convoId},
{headers: DM_SERVICE_HEADERS, encoding: 'application/json'},
)

View file

@ -27,12 +27,12 @@ export const RQKEY = ['convo-list']
type RQPageParam = string | undefined
export function useListConvosQuery() {
const {getAgent} = useAgent()
const agent = useAgent()
return useInfiniteQuery({
queryKey: RQKEY,
queryFn: async ({pageParam}) => {
const {data} = await getAgent().api.chat.bsky.convo.listConvos(
const {data} = await agent.api.chat.bsky.convo.listConvos(
{cursor: pageParam},
{headers: DM_SERVICE_HEADERS},
)

View file

@ -21,13 +21,11 @@ export function useMuteConvo(
},
) {
const queryClient = useQueryClient()
const {getAgent} = useAgent()
const agent = useAgent()
return useMutation({
mutationFn: async ({mute}: {mute: boolean}) => {
if (!convoId) throw new Error('No convoId provided')
const agent = getAgent()
if (mute) {
const {data} = await agent.api.chat.bsky.convo.muteConvo(
{convoId},