@@ -43,6 +43,55 @@ public Comment Init(Reddit reddit, JToken json, IWebAgent webAgent, Thing sender
43
43
return this ;
44
44
}
45
45
46
+ public Comment PopulateComments ( IEnumerator < Thing > things )
47
+ {
48
+ Thing first = things . Current ;
49
+ Dictionary < string , Tuple < Comment , List < Comment > > > comments = new Dictionary < string , Tuple < Comment , List < Comment > > > ( ) ;
50
+ comments [ this . FullName ] = Tuple . Create < Comment , List < Comment > > ( this , new List < Comment > ( ) ) ;
51
+
52
+ while ( things . MoveNext ( ) && ( first is Comment || first is More ) )
53
+ {
54
+ first = things . Current ;
55
+ if ( first is Comment )
56
+ {
57
+ Comment comment = ( Comment ) first ;
58
+ comments [ comment . FullName ] = Tuple . Create < Comment , List < Comment > > ( comment , new List < Comment > ( ) ) ;
59
+ if ( comments . ContainsKey ( comment . ParentId ) )
60
+ {
61
+ comments [ comment . ParentId ] . Item2 . Add ( comment ) ;
62
+ }
63
+ else if ( comment . ParentId == this . ParentId )
64
+ {
65
+ //only want sub comments.
66
+ break ;
67
+ }
68
+ }
69
+ else if ( first is More )
70
+ {
71
+ More more = ( More ) first ;
72
+ if ( comments . ContainsKey ( more . ParentId ) )
73
+ {
74
+ comments [ more . ParentId ] . Item1 . More = more ;
75
+ }
76
+ else if ( more . ParentId == this . ParentId )
77
+ {
78
+ // This is more for parent.
79
+ // Need to process the comments dictionary.
80
+ break ;
81
+ }
82
+ }
83
+ //things.MoveNext();
84
+
85
+ }
86
+
87
+ foreach ( KeyValuePair < string , Tuple < Comment , List < Comment > > > kvp in comments )
88
+ {
89
+ kvp . Value . Item1 . Comments = kvp . Value . Item2 . ToArray ( ) ;
90
+ }
91
+
92
+ return this ;
93
+ }
94
+
46
95
private JToken CommonInit ( Reddit reddit , JToken json , IWebAgent webAgent , Thing sender )
47
96
{
48
97
Init ( reddit , webAgent , json ) ;
@@ -57,7 +106,7 @@ private JToken CommonInit(Reddit reddit, JToken json, IWebAgent webAgent, Thing
57
106
var context = data [ "context" ] . Value < string > ( ) ;
58
107
LinkId = context . Split ( '/' ) [ 4 ] ;
59
108
}
60
-
109
+
61
110
return data ;
62
111
}
63
112
private async Task < JToken > CommonInitAsync ( Reddit reddit , JToken json , IWebAgent webAgent , Thing sender )
@@ -86,7 +135,7 @@ private void ParseComments(Reddit reddit, JToken data, IWebAgent webAgent, Thing
86
135
if ( replies != null && replies . Count ( ) > 0 )
87
136
{
88
137
foreach ( var comment in replies [ "data" ] [ "children" ] )
89
- subComments . Add ( new Comment ( ) . Init ( reddit , comment , webAgent , sender ) ) ;
138
+ subComments . Add ( new Comment ( ) . Init ( reddit , comment , webAgent , sender ) ) ;
90
139
}
91
140
Comments = subComments . ToArray ( ) ;
92
141
}
@@ -133,6 +182,9 @@ private async Task ParseCommentsAsync(Reddit reddit, JToken data, IWebAgent webA
133
182
[ JsonProperty ( "stickied" ) ]
134
183
public bool IsStickied { get ; set ; }
135
184
185
+ [ JsonIgnore ]
186
+ public More More { get ; set ; }
187
+
136
188
[ JsonIgnore ]
137
189
public IList < Comment > Comments { get ; private set ; }
138
190
@@ -280,11 +332,11 @@ public void SetAsRead()
280
332
{
281
333
var request = WebAgent . CreatePost ( SetAsReadUrl ) ;
282
334
WebAgent . WritePostBody ( request . GetRequestStream ( ) , new
283
- {
284
- id = FullName ,
285
- uh = Reddit . User . Modhash ,
286
- api_type = "json"
287
- } ) ;
335
+ {
336
+ id = FullName ,
337
+ uh = Reddit . User . Modhash ,
338
+ api_type = "json"
339
+ } ) ;
288
340
var response = request . GetResponse ( ) ;
289
341
var data = WebAgent . GetResponseString ( response . GetResponseStream ( ) ) ;
290
342
}
0 commit comments