@@ -2248,12 +2248,18 @@ public function getPaginateThreads($limit = 10, $messageLimit = 10, $cursor = nu
2248
2248
*/
2249
2249
public function getThreads ($ count = 10 , $ limit = 10 , $ messageLimit = 10 )
2250
2250
{
2251
+ $ this ->allowPendingRequests ();
2252
+
2251
2253
$ threads = [];
2252
2254
$ cursor = null ;
2253
2255
2254
2256
while (count ($ threads ) < $ count ) {
2255
2257
$ result = $ this ->getPaginateThreads ($ limit , $ messageLimit , $ cursor );
2256
2258
2259
+ if (!isset ($ result ['threads ' ])) {
2260
+ break ;
2261
+ }
2262
+
2257
2263
$ threads = array_merge ($ threads , $ result ['threads ' ]);
2258
2264
2259
2265
if (!$ result ['hasOlder ' ] || !$ result ['oldestCursor ' ]) {
@@ -2265,4 +2271,50 @@ public function getThreads($count = 10, $limit = 10, $messageLimit = 10)
2265
2271
2266
2272
return $ threads ;
2267
2273
}
2274
+
2275
+ /**
2276
+ * @param int $limit
2277
+ *
2278
+ * @return void
2279
+ * @throws InstagramException
2280
+ */
2281
+ public function allowPendingRequests ($ limit = 10 )
2282
+ {
2283
+ $ response = Request::get (
2284
+ Endpoints::getThreadsPendingRequestsUrl ($ limit ),
2285
+ array_merge (
2286
+ ['x-ig-app-id ' => self ::X_IG_APP_ID ],
2287
+ $ this ->generateHeaders ($ this ->userSession )
2288
+ )
2289
+ );
2290
+
2291
+ if ($ response ->code !== static ::HTTP_OK ) {
2292
+ throw new InstagramException ('Response code is ' . $ response ->code . '. Body: ' . static ::getErrorBody ($ response ->body ) . ' Something went wrong. Please report issue. ' );
2293
+ }
2294
+
2295
+ $ jsonResponse = $ this ->decodeRawBodyToJson ($ response ->raw_body );
2296
+
2297
+ if (!isset ($ jsonResponse ['status ' ]) || $ jsonResponse ['status ' ] !== 'ok ' ) {
2298
+ throw new InstagramException ('Response code is not equal 200. Something went wrong. Please report issue. ' );
2299
+ }
2300
+
2301
+ if (!isset ($ jsonResponse ['inbox ' ]['threads ' ]) || empty ($ jsonResponse ['inbox ' ]['threads ' ])) {
2302
+ return ;
2303
+ }
2304
+
2305
+ $ threadIds = [];
2306
+
2307
+ foreach ($ jsonResponse ['inbox ' ]['threads ' ] as $ thread ) {
2308
+ $ threadIds [] = $ thread ['thread_id ' ];
2309
+ }
2310
+
2311
+ Request::post (
2312
+ Endpoints::getThreadsApproveMultipleUrl (),
2313
+ array_merge (
2314
+ ['x-ig-app-id ' => self ::X_IG_APP_ID ],
2315
+ $ this ->generateHeaders ($ this ->userSession )
2316
+ ),
2317
+ ['thread_ids ' => json_encode ($ threadIds )]
2318
+ );
2319
+ }
2268
2320
}
0 commit comments