Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 4 roky
před 4 roky
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #import "TFHelper.h"
  2. @implementation TFHelper
  3. + (void)getUndeleteDataWithID:(NSString *)ident isComment:(BOOL)isComment timeout:(CGFloat)timeout extraData:(NSDictionary *)extra completionTarget:(id)target completionSelector:(SEL)sel {
  4. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  5. //NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  6. if (isComment){
  7. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
  8. } else {
  9. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", ident]]];
  10. }
  11. [request setHTTPMethod:@"GET"];
  12. [request setTimeoutInterval:timeout];
  13. NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  14. //[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  15. NSString *author = @"[author]";
  16. NSString *body = @"[body]";
  17. if (data) {
  18. id jsonData = [[NSJSONSerialization JSONObjectWithData:data options:0 error:&error] objectForKey:@"data"];
  19. if (jsonData && [jsonData count] != 0) {
  20. author = [jsonData[0] objectForKey:@"author"];
  21. body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[0] objectForKey:@"selftext"];
  22. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  23. body = [NSString stringWithFormat:@"[pushshift was unable to archive this %@]", isComment ? @"comment" : @"post"];
  24. }
  25. } else {
  26. body = [NSString stringWithFormat:@"[no data for this %@ was returned by pushshift]", isComment ? @"comment" : @"post"];
  27. }
  28. }
  29. if (error) {
  30. body = [NSString stringWithFormat:@"[an error occurred while attempting retrieve data from the pushshift api]\n\nHTTP Status Code: %li\n\nError Description: %@",
  31. (long)((NSHTTPURLResponse *)response).statusCode, [error localizedDescription]];
  32. }
  33. NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:@{@"author" : author, @"body" : body}];
  34. if (extra){
  35. [result addEntriesFromDictionary:extra];
  36. }
  37. [target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
  38. }];
  39. [dataTask resume];
  40. }
  41. + (BOOL)shouldShowUndeleteButtonWithInfo:(NSString *) content isDeletedOnly:(BOOL) isDeletedOnly{
  42. if (!isDeletedOnly){
  43. return YES;
  44. } else {
  45. if ([content isEqualToString:@"[deleted]"] || [content isEqualToString:@"[removed]"]){
  46. return YES;
  47. } else if ([content hasPrefix:@"[pushshift"] || [content hasPrefix:@"[an error occured"]){
  48. return YES;
  49. }
  50. }
  51. return NO;
  52. }
  53. @end