mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 11:08:06 +00:00
Upload shared pictures according to chosen quality
This commit is contained in:
parent
df9353d2d4
commit
c6a56491bc
6 changed files with 19 additions and 15 deletions
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
@protocol ChatConversationDelegate <NSObject>
|
||||
|
||||
- (BOOL)startImageUpload:(UIImage *)image url:(NSURL *)url;
|
||||
- (BOOL)startImageUpload:(UIImage *)image url:(NSURL *)url withQuality:(float)quality;
|
||||
- (void)resendChat:(NSString *)message withExternalUrl:(NSString *)url;
|
||||
- (void)tableViewIsScrolling;
|
||||
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
- (void)saveAndSend:(UIImage *)image url:(NSURL *)url {
|
||||
- (void)saveAndSend:(UIImage *)image url:(NSURL *)url withQuality:(float)quality{
|
||||
// photo from Camera, must be saved first
|
||||
if (url == nil) {
|
||||
[LinphoneManager.instance.photoLibrary
|
||||
|
|
@ -282,11 +282,11 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
[self presentViewController:errView animated:YES completion:nil];
|
||||
} else {
|
||||
LOGI(@"Image saved to [%@]", [assetURL absoluteString]);
|
||||
[self startImageUpload:image url:assetURL];
|
||||
[self startImageUpload:image url:assetURL withQuality:quality];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
[self startImageUpload:image url:url];
|
||||
[self startImageUpload:image url:url withQuality:quality];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -294,14 +294,13 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Choose the image size", nil)];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
for (NSString *key in [imageQualities allKeys]) {
|
||||
NSNumber *number = [imageQualities objectForKey:key];
|
||||
NSData *data = UIImageJPEGRepresentation(image, [number floatValue]);
|
||||
NSNumber *quality = [imageQualities objectForKey:key];
|
||||
NSData *data = UIImageJPEGRepresentation(image, [quality floatValue]);
|
||||
NSNumber *size = [NSNumber numberWithInteger:[data length]];
|
||||
|
||||
NSString *text = [NSString stringWithFormat:@"%@ (%@)", key, [size toHumanReadableSize]];
|
||||
[sheet addButtonWithTitle:text
|
||||
block:^() {
|
||||
[self saveAndSend:[UIImage imageWithData:data] url:url];
|
||||
[self saveAndSend:image url:url withQuality:[quality floatValue]];
|
||||
}];
|
||||
}
|
||||
[sheet addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil];
|
||||
|
|
@ -572,9 +571,9 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
|
||||
#pragma mark ChatRoomDelegate
|
||||
|
||||
- (BOOL)startImageUpload:(UIImage *)image url:(NSURL *)url {
|
||||
- (BOOL)startImageUpload:(UIImage *)image url:(NSURL *)url withQuality:(float)quality {
|
||||
FileTransferDelegate *fileTransfer = [[FileTransferDelegate alloc] init];
|
||||
[fileTransfer upload:image withURL:url forChatRoom:_chatRoom];
|
||||
[fileTransfer upload:image withURL:url forChatRoom:_chatRoom withQuality:quality];
|
||||
[_tableController addChatEntry:linphone_chat_message_ref(fileTransfer.message)];
|
||||
[_tableController scrollToBottom:true];
|
||||
return TRUE;
|
||||
|
|
|
|||
|
|
@ -218,6 +218,8 @@
|
|||
if (state == LinphoneChatMessageStateNotDelivered || state == LinphoneChatMessageStateFileTransferError) {
|
||||
if (linphone_chat_message_get_file_transfer_information(_message) != NULL) {
|
||||
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:_message];
|
||||
NSNumber *uploadQuality =[LinphoneManager getMessageAppDataForKey:@"uploadQuality" inMessage:_message];
|
||||
|
||||
NSURL *imageUrl = [NSURL URLWithString:localImage];
|
||||
|
||||
[self onDeleteClick:nil];
|
||||
|
|
@ -226,8 +228,8 @@
|
|||
resultBlock:^(ALAsset *asset) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL),
|
||||
^(void) {
|
||||
UIImage *image = [[UIImage alloc] initWithCGImage:[asset thumbnail]];
|
||||
[_chatRoomDelegate startImageUpload:image url:imageUrl];
|
||||
UIImage *image = [[UIImage alloc] initWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
|
||||
[_chatRoomDelegate startImageUpload:image url:imageUrl withQuality:(uploadQuality ? [uploadQuality floatValue] : 0.9)];
|
||||
});
|
||||
}
|
||||
failureBlock:^(NSError *error) {
|
||||
|
|
|
|||
|
|
@ -765,6 +765,7 @@ void update_hash_cbs(LinphoneAccountCreator *creator, LinphoneAccountCreatorStat
|
|||
LinphoneChatMessage *msg = messages->data;
|
||||
if (!linphone_chat_message_is_outgoing(msg)) {
|
||||
[LinphoneManager setValueInMessageAppData:nil forKey:@"localimage" inMessage:messages->data];
|
||||
[LinphoneManager setValueInMessageAppData:nil forKey:@"uploadQuality" inMessage:messages->data];
|
||||
}
|
||||
messages = messages->next;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
@interface FileTransferDelegate : NSObject
|
||||
|
||||
- (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom;
|
||||
- (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom withQuality:(float)quality;
|
||||
- (void)cancel;
|
||||
- (BOOL)download:(LinphoneChatMessage *)message;
|
||||
- (void)stopAndDestroy;
|
||||
|
|
|
|||
|
|
@ -166,11 +166,11 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
|
|||
return NULL;
|
||||
}
|
||||
|
||||
- (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom {
|
||||
- (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom withQuality:(float)quality {
|
||||
[LinphoneManager.instance.fileTransferDelegates addObject:self];
|
||||
|
||||
LinphoneContent *content = linphone_core_create_content(linphone_chat_room_get_core(chatRoom));
|
||||
_data = [NSMutableData dataWithData:UIImageJPEGRepresentation(image, 1.0)];
|
||||
_data = [NSMutableData dataWithData:UIImageJPEGRepresentation(image, quality)];
|
||||
linphone_content_set_type(content, "image");
|
||||
linphone_content_set_subtype(content, "jpeg");
|
||||
linphone_content_set_name(
|
||||
|
|
@ -187,6 +187,8 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
|
|||
if (url) {
|
||||
// internal url is saved in the appdata for display and later save
|
||||
[LinphoneManager setValueInMessageAppData:[url absoluteString] forKey:@"localimage" inMessage:_message];
|
||||
[LinphoneManager setValueInMessageAppData:[NSNumber numberWithFloat:quality]forKey:@"uploadQuality" inMessage:_message];
|
||||
|
||||
}
|
||||
|
||||
LOGI(@"%p Uploading content from message %p", self, _message);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue