@@ -2,6 +2,7 @@ import type { Federation } from '@fedify/fedify';
2
2
import type { Account } from 'account/account.entity' ;
3
3
import type { KnexAccountRepository } from 'account/account.repository.knex' ;
4
4
import type { AccountService } from 'account/account.service' ;
5
+ import type { FedifyContextFactory } from 'activitypub/fedify-context.factory' ;
5
6
import type { AppContext , ContextData } from 'app' ;
6
7
import { isHandle } from 'helpers/activitypub/actor' ;
7
8
import { lookupAPIdByHandle } from 'lookup-helpers' ;
@@ -11,7 +12,10 @@ import {
11
12
getAccountDTOFromAccount ,
12
13
} from './helpers/account' ;
13
14
import type { AccountDTO } from './types' ;
14
- import type { AccountFollowsView } from './views/account.follows.view' ;
15
+ import type {
16
+ AccountFollows ,
17
+ AccountFollowsView ,
18
+ } from './views/account.follows.view' ;
15
19
16
20
/**
17
21
* Default number of posts to return in a profile
@@ -112,6 +116,7 @@ export function createGetAccountHandler(
112
116
export function createGetAccountFollowsHandler (
113
117
accountRepository : KnexAccountRepository ,
114
118
accountFollowsView : AccountFollowsView ,
119
+ fedifyContextFactory : FedifyContextFactory ,
115
120
) {
116
121
/**
117
122
* Handle a request for a list of account follows
@@ -121,30 +126,51 @@ export function createGetAccountFollowsHandler(
121
126
return async function handleGetAccountFollows ( ctx : AppContext ) {
122
127
const site = ctx . get ( 'site' ) ;
123
128
124
- // Validate input
125
129
const handle = ctx . req . param ( 'handle' ) || '' ;
126
-
127
130
if ( handle === '' ) {
128
131
return new Response ( null , { status : 400 } ) ;
129
132
}
130
133
131
134
const type = ctx . req . param ( 'type' ) ;
132
-
133
135
if ( ! [ 'following' , 'followers' ] . includes ( type ) ) {
134
136
return new Response ( null , { status : 400 } ) ;
135
137
}
136
138
137
139
const siteDefaultAccount = await accountRepository . getBySite ( site ) ;
138
140
139
- // Get follows accounts and paginate
140
- const queryNext = ctx . req . query ( 'next' ) || '0' ;
141
- const offset = Number . parseInt ( queryNext ) ;
141
+ const queryNext = ctx . req . query ( 'next' ) ;
142
+ const next = queryNext ? decodeURIComponent ( queryNext ) : null ;
142
143
143
- const accountFollows = await accountFollowsView . getFollows (
144
- type ,
145
- siteDefaultAccount ,
146
- offset ,
147
- ) ;
144
+ let accountFollows : AccountFollows ;
145
+
146
+ if ( handle === 'me' ) {
147
+ accountFollows = await accountFollowsView . getFollowsByAccount (
148
+ siteDefaultAccount ,
149
+ type ,
150
+ Number . parseInt ( next || '0' ) ,
151
+ siteDefaultAccount ,
152
+ ) ;
153
+ } else {
154
+ const ctx = fedifyContextFactory . getFedifyContext ( ) ;
155
+ const apId = await lookupAPIdByHandle ( ctx , handle ) ;
156
+
157
+ if ( ! apId ) {
158
+ return new Response ( null , { status : 400 } ) ;
159
+ }
160
+
161
+ const account = await accountRepository . getByApId ( new URL ( apId ) ) ;
162
+ if ( ! account ) {
163
+ return new Response ( null , { status : 400 } ) ;
164
+ }
165
+
166
+ accountFollows = await accountFollowsView . getFollowsByHandle (
167
+ handle ,
168
+ account ,
169
+ type ,
170
+ next ,
171
+ siteDefaultAccount ,
172
+ ) ;
173
+ }
148
174
149
175
// Return response
150
176
return new Response (
0 commit comments