@@ -7,14 +7,15 @@ async function interactWithBluesky(source: {interaction?: ModalSubmitInteraction
77
88 let { interaction, rkey, targetHandle, actorDID} = source ;
99
10+ const isTargetAccount = action === "deleteFollow" || action === "follow" ;
1011 if ( interaction && ! targetHandle ) {
1112
1213 // Get the rkey of the post.
1314 const originalMessage = await interaction . getOriginal ( ) ;
1415 const originalEmbed = originalMessage . embeds [ 0 ] ;
1516 const value = originalEmbed ?. footer ?. text ;
1617
17- if ( action === "follow" ) {
18+ if ( isTargetAccount ) {
1819
1920 targetHandle = value ;
2021
@@ -30,7 +31,7 @@ async function interactWithBluesky(source: {interaction?: ModalSubmitInteraction
3031
3132 }
3233
33- if ( ! targetHandle || ! actorDID || ( action !== "follow" && ! rkey ) ) throw new Error ( ) ;
34+ if ( ! targetHandle || ! actorDID || ( ! isTargetAccount && ! rkey ) ) throw new Error ( ) ;
3435
3536 // Get the CID of the post if necessary.
3637 const session = await blueskyClient . restore ( actorDID , "auto" , { guildID : source . guildID , decryptionKey : source . decryptionKey } ) ;
@@ -39,10 +40,16 @@ async function interactWithBluesky(source: {interaction?: ModalSubmitInteraction
3940 let cid ;
4041 let uri ;
4142 if ( ! targetDID ) throw new Error ( ) ;
42- if ( action !== "follow" ) {
43+ if ( action === "deleteFollow" ) {
44+
45+ const profileResponse = await agent . getProfile ( { actor : targetDID } ) ;
46+ uri = profileResponse . data . viewer ?. following ;
47+ if ( ! uri ) return ;
48+
49+ } else if ( action !== "follow" ) {
4350
4451 if ( ! rkey ) throw new Error ( ) ;
45-
52+
4653 const recordResponse = await agent . com . atproto . repo . getRecord ( {
4754 collection : "app.bsky.feed.post" ,
4855 repo : targetDID ,
@@ -52,20 +59,20 @@ async function interactWithBluesky(source: {interaction?: ModalSubmitInteraction
5259 cid = recordResponse . data . cid ;
5360
5461 if ( ! cid ) throw new Error ( ) ;
55-
56- // Get the URI we need.
5762 uri = `at://${ targetDID } /app.bsky.feed.post/${ rkey } ` ;
58- if ( action === "deleteLike" || action === "deleteRepost" ) {
59-
60- const response = await agent . getPostThread ( { uri} ) ;
61- if ( isThreadViewPost ( response . data . thread ) ) {
62-
63- const possibleURI = response . data . thread . post . viewer ?. [ action === "deleteLike" ? "like" : "repost" ] ;
64- if ( ! possibleURI ) return ;
65- uri = possibleURI ;
66-
67- }
68-
63+
64+ }
65+
66+ // Get the URI we need.
67+ if ( action === "deleteLike" || action === "deleteRepost" ) {
68+
69+ const response = await agent . getPostThread ( { uri : uri ! } ) ;
70+ if ( isThreadViewPost ( response . data . thread ) ) {
71+
72+ const possibleURI = response . data . thread . post . viewer ?. [ action === "deleteLike" ? "like" : "repost" ] ;
73+ if ( ! possibleURI ) return ;
74+ uri = possibleURI ;
75+
6976 }
7077
7178 }
0 commit comments