@@ -53,17 +53,16 @@ - (BOOL)isComment {
5353}
5454
5555- (BOOL )isSubmission {
56- // Checking submission rather than something like title since this will be set
57- // even when the entry hasn't been loaded.
56+ // This is counterintuitive, but we are essentially checking for a parent.
5857 return [self submission ] == nil ;
5958}
6059
61- - (void )loadFromDictionary : (NSDictionary *)response entries : (NSArray **)outEntries {
62- if ([response objectForKey: @" submission" ]) {
63- [self setSubmission: [HNEntry entryWithIdentifier: [response objectForKey: @" submission" ]]];
60+ - (void )loadContentsDictionary : (NSDictionary *)contents entries : (NSArray **)outEntries {
61+ if ([contents objectForKey: @" submission" ]) {
62+ [self setSubmission: [HNEntry entryWithIdentifier: [contents objectForKey: @" submission" ]]];
6463 }
6564
66- id parentId = [response objectForKey: @" parent" ];
65+ id parentId = [contents objectForKey: @" parent" ];
6766 if (parentId) {
6867 HNEntry *parent_ = [HNEntry entryWithIdentifier: parentId];
6968
@@ -76,27 +75,24 @@ - (void)loadFromDictionary:(NSDictionary *)response entries:(NSArray **)outEntri
7675 [self setParent: parent_];
7776 }
7877
79- [self loadFromDictionary: response entries: outEntries withSubmission: [self submission ] ?: self ];
78+ [self loadContentsDictionary: contents entries: outEntries withSubmission: [self submission ] ?: self ];
8079}
8180
82- - (void )loadChildrenFromDictionary : (NSDictionary *)response {
83- }
84-
85- - (void )loadFromDictionary : (NSDictionary *)response entries : (NSArray **)outEntries withSubmission : (HNEntry *)submission_ {
86- if ([response objectForKey: @" url" ] != nil ) [self setDestination: [NSURL URLWithString: [response objectForKey: @" url" ]]];
87- if ([response objectForKey: @" user" ] != nil ) [self setSubmitter: [HNUser userWithIdentifier: [response objectForKey: @" user" ]]];
88- if ([response objectForKey: @" body" ] != nil ) [self setBody: [response objectForKey: @" body" ]];
89- if ([response objectForKey: @" date" ] != nil ) [self setPosted: [response objectForKey: @" date" ]];
90- if ([response objectForKey: @" title" ] != nil ) [self setTitle: [response objectForKey: @" title" ]];
91- if ([response objectForKey: @" points" ] != nil ) [self setPoints: [[response objectForKey: @" points" ] intValue ]];
81+ - (void )loadContentsDictionary : (NSDictionary *)contents entries : (NSArray **)outEntries withSubmission : (HNEntry *)submission_ {
82+ if ([contents objectForKey: @" url" ] != nil ) [self setDestination: [NSURL URLWithString: [contents objectForKey: @" url" ]]];
83+ if ([contents objectForKey: @" user" ] != nil ) [self setSubmitter: [HNUser userWithIdentifier: [contents objectForKey: @" user" ]]];
84+ if ([contents objectForKey: @" body" ] != nil ) [self setBody: [contents objectForKey: @" body" ]];
85+ if ([contents objectForKey: @" date" ] != nil ) [self setPosted: [contents objectForKey: @" date" ]];
86+ if ([contents objectForKey: @" title" ] != nil ) [self setTitle: [contents objectForKey: @" title" ]];
87+ if ([contents objectForKey: @" points" ] != nil ) [self setPoints: [[contents objectForKey: @" points" ] intValue ]];
9288
9389 NSMutableArray *comments = [NSMutableArray array ];
94- if ([response objectForKey: @" children" ] != nil ) {
95- for (NSDictionary *child in [response objectForKey: @" children" ]) {
90+ if ([contents objectForKey: @" children" ] != nil ) {
91+ for (NSDictionary *child in [contents objectForKey: @" children" ]) {
9692 HNEntry *childEntry = [HNEntry entryWithIdentifier: [child objectForKey: @" identifier" ]];
9793 NSArray *childEntries = nil ;
9894
99- [childEntry loadFromDictionary : child entries: &childEntries withSubmission: submission_];
95+ [childEntry loadContentsDictionary : child entries: &childEntries withSubmission: submission_];
10096 [childEntry setEntries: childEntries];
10197 [childEntry setParent: self ];
10298 [childEntry setSubmission: submission_];
@@ -115,8 +111,8 @@ - (void)loadFromDictionary:(NSDictionary *)response entries:(NSArray **)outEntri
115111 }
116112 }
117113
118- if ([response objectForKey: @" numchildren" ] != nil ) {
119- int count = [[response objectForKey: @" numchildren" ] intValue ];
114+ if ([contents objectForKey: @" numchildren" ] != nil ) {
115+ int count = [[contents objectForKey: @" numchildren" ] intValue ];
120116 [self setChildren: count];
121117 } else {
122118 int count = [comments count ];
@@ -126,4 +122,18 @@ - (void)loadFromDictionary:(NSDictionary *)response entries:(NSArray **)outEntri
126122 }
127123}
128124
125+ - (NSDictionary *)contentsDictionary {
126+ NSMutableDictionary *dictionary = [[[super contentsDictionary ] mutableCopy ] autorelease ];
127+
128+ if (destination != nil ) [dictionary setObject: destination forKey: @" url" ];
129+ if (submitter != nil ) [dictionary setObject: [submitter identifier ] forKey: @" user" ];
130+ if (body != nil ) [dictionary setObject: body forKey: @" body" ];
131+ if (posted != nil ) [dictionary setObject: posted forKey: @" date" ];
132+ if (title != nil ) [dictionary setObject: title forKey: @" title" ];
133+ [dictionary setObject: [NSNumber numberWithInt: points] forKey: @" points" ];
134+ [dictionary setObject: [NSNumber numberWithInt: children] forKey: @" numchildren" ];
135+
136+ return dictionary;
137+ }
138+
129139@end
0 commit comments