mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-01 10:23:15 +00:00
+ Added preliminary load mechanics for Feedback Images.
This commit is contained in:
parent
5038c3e4e9
commit
3aa45bbb9f
@ -734,6 +734,15 @@
|
||||
message.id = [(NSDictionary *)objMessage objectForKey:@"id"];
|
||||
message.status = BITFeedbackMessageStatusUnread;
|
||||
|
||||
for (NSDictionary *attachmentData in objMessage[@"attachments"]){
|
||||
BITFeedbackMessageAttachment *newAttachment = [BITFeedbackMessageAttachment new];
|
||||
newAttachment.originalFilename = attachmentData[@"file_name"];
|
||||
newAttachment.id = attachmentData[@"id"];
|
||||
newAttachment.sourceURL = attachmentData[@"url"];
|
||||
newAttachment.contentType = @"image/jpg";
|
||||
[message addAttachmentsObject:newAttachment];
|
||||
}
|
||||
|
||||
[_feedbackList addObject:message];
|
||||
|
||||
newMessage = YES;
|
||||
@ -790,11 +799,45 @@
|
||||
[self markSendInProgressMessagesAsPending];
|
||||
}
|
||||
|
||||
[self synchronizeMissingAttachments];
|
||||
|
||||
[self saveMessages];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
Load all attachments without any local data to have them available.
|
||||
*/
|
||||
-(BOOL)synchronizeMissingAttachments {
|
||||
// Extract all Attachments.
|
||||
NSMutableArray *allAttachments = [NSMutableArray new];
|
||||
for (int i = 0; i < [self numberOfMessages]; i++){
|
||||
BITFeedbackMessage *message = [self messageAtIndex:i];
|
||||
for (BITFeedbackMessageAttachment *attachment in message.attachments){
|
||||
if (attachment.needsLoadingFromURL){
|
||||
[allAttachments addObject:attachment];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (BITFeedbackMessageAttachment *attachment in allAttachments){
|
||||
// we will just update the objects here and perform a save after each successful load operation.
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:attachment.sourceURL]];
|
||||
__weak BITFeedbackManager *weakSelf = self;
|
||||
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *err) {
|
||||
if (responseData.length){
|
||||
[attachment replaceData:responseData];
|
||||
[weakSelf saveMessages];
|
||||
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BITFeedbackMessage *)message completionHandler:(void (^)(NSError *err))completionHandler {
|
||||
NSString *boundary = @"----FOO";
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class BITFeedbackMessageAttachment;
|
||||
|
||||
/**
|
||||
* Status for each feedback message
|
||||
*/
|
||||
@ -79,5 +81,7 @@ typedef NS_ENUM(NSInteger, BITFeedbackMessageStatus) {
|
||||
*/
|
||||
-(void)deleteContents;
|
||||
|
||||
-(void)addAttachmentsObject:(BITFeedbackMessageAttachment *)object;
|
||||
|
||||
|
||||
@end
|
||||
|
@ -90,5 +90,10 @@
|
||||
[attachment deleteContents];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)addAttachmentsObject:(BITFeedbackMessageAttachment *)object{
|
||||
if (!self.attachments){
|
||||
self.attachments = [NSArray array];
|
||||
}
|
||||
self.attachments = [self.attachments arrayByAddingObject:object];
|
||||
}
|
||||
@end
|
||||
|
@ -35,6 +35,7 @@
|
||||
@property (nonatomic, copy) NSNumber *id;
|
||||
@property (nonatomic, copy) NSString *originalFilename;
|
||||
@property (nonatomic, copy) NSString *contentType;
|
||||
@property (nonatomic, copy) NSString *sourceURL;
|
||||
@property (nonatomic, readonly) NSData *data;
|
||||
|
||||
@property (readonly) UIImage *imageRepresentation;
|
||||
@ -48,4 +49,6 @@
|
||||
|
||||
- (void)deleteContents;
|
||||
|
||||
-(BOOL)needsLoadingFromURL;
|
||||
|
||||
@end
|
||||
|
@ -39,6 +39,7 @@
|
||||
@property (nonatomic, strong) NSData *internalData;
|
||||
@property (nonatomic, copy) NSString *filename;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation BITFeedbackMessageAttachment
|
||||
@ -92,12 +93,18 @@
|
||||
self.thumbnailRepresentations = [NSMutableDictionary new];
|
||||
}
|
||||
|
||||
-(BOOL)needsLoadingFromURL {
|
||||
return (self.sourceURL);
|
||||
}
|
||||
|
||||
#pragma mark NSCoding
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
||||
[aCoder encodeObject:self.contentType forKey:@"contentType"];
|
||||
[aCoder encodeObject:self.filename forKey:@"filename"];
|
||||
[aCoder encodeObject:self.originalFilename forKey:@"originalFilename"];
|
||||
[aCoder encodeObject:self.sourceURL forKey:@"url"];
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -109,6 +116,8 @@
|
||||
self.filename = [aDecoder decodeObjectForKey:@"filename"];
|
||||
self.thumbnailRepresentations = [NSMutableDictionary new];
|
||||
self.originalFilename = [aDecoder decodeObjectForKey:@"originalFilename"];
|
||||
self.sourceURL = [aDecoder decodeObjectForKey:@"sourceURL"];
|
||||
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -117,7 +126,7 @@
|
||||
#pragma mark - Thubmnails / Image Representation
|
||||
|
||||
- (UIImage *)imageRepresentation {
|
||||
if ([self.contentType rangeOfString:@"image"].location != NSNotFound){
|
||||
if ([self.contentType rangeOfString:@"image"].location != NSNotFound || [self.sourceURL rangeOfString:@"jpeg"].location != NSNotFound){
|
||||
return [UIImage imageWithData:self.data];
|
||||
} else {
|
||||
return bit_imageNamed(@"feedbackActiviy.png", BITHOCKEYSDK_BUNDLE); // TODO add another placeholder.
|
||||
|
Loading…
x
Reference in New Issue
Block a user