@@ -255,12 +255,12 @@ private void PageForward()
255
255
{
256
256
int limit = LimitPerRequest ;
257
257
258
- if ( limit > MaximumLimit )
258
+ if ( limit > MaximumLimit && MaximumLimit != - 1 )
259
259
{
260
260
// If the limit is more than the maximum number of listings, adjust
261
261
limit = MaximumLimit ;
262
262
}
263
- else if ( Count + limit > MaximumLimit )
263
+ else if ( Count + limit > MaximumLimit && MaximumLimit != - 1 )
264
264
{
265
265
// If a smaller subset of listings are needed, adjust the limit
266
266
limit = MaximumLimit - Count ;
@@ -289,7 +289,6 @@ private void PageForward()
289
289
Parse ( json ) ;
290
290
}
291
291
292
-
293
292
private void Parse ( JToken json )
294
293
{
295
294
var children = json [ "data" ] [ "children" ] as JArray ;
@@ -301,8 +300,24 @@ private void Parse(JToken json)
301
300
things . Add ( Thing . Parse < T > ( Listing . Reddit , children [ i ] , Listing . WebAgent ) ) ;
302
301
else
303
302
{
304
- // we only want to see new items.
303
+ var kind = children [ i ] [ "kind" ] . ValueOrDefault < string > ( ) ;
305
304
var id = children [ i ] [ "data" ] [ "id" ] . ValueOrDefault < string > ( ) ;
305
+
306
+ // check for new replies to pm / modmail
307
+ if ( kind == "t4" && children [ i ] [ "data" ] [ "replies" ] . HasValues )
308
+ {
309
+ var replies = children [ i ] [ "data" ] [ "replies" ] [ "data" ] [ "children" ] as JArray ;
310
+ foreach ( var reply in replies )
311
+ {
312
+ var replyId = reply [ "data" ] [ "id" ] . ValueOrDefault < string > ( ) ;
313
+ if ( done . Contains ( replyId ) )
314
+ continue ;
315
+
316
+ things . Add ( Thing . Parse < T > ( Listing . Reddit , reply , Listing . WebAgent ) ) ;
317
+ done . Add ( replyId ) ;
318
+ }
319
+ }
320
+
306
321
if ( String . IsNullOrEmpty ( id ) || done . Contains ( id ) )
307
322
continue ;
308
323
@@ -311,6 +326,7 @@ private void Parse(JToken json)
311
326
}
312
327
}
313
328
329
+ // this doesn't really work when we're processing messages with replies.
314
330
if ( stream )
315
331
things . Reverse ( ) ;
316
332
@@ -390,8 +406,6 @@ private bool MoveNextForward()
390
406
catch ( Exception ex )
391
407
{
392
408
// sleep for a while to see if we can recover
393
- // Sleep() will rethrow after waiting a bit
394
- // todo: make this smarter
395
409
Sleep ( tries , ex ) ;
396
410
}
397
411
0 commit comments