@@ -1341,69 +1341,59 @@ - (void)fillTypedMessage:(LCIMTypedMessage *)typedMessage withFile:(LCFile *)fil
13411341{
13421342 NSMutableDictionary *metaData = (file.metaData .mutableCopy
13431343 ?: [NSMutableDictionary dictionary ]);
1344- switch (typedMessage.mediaType ) {
1345- case kLCIMMessageMediaTypeImage :
1346- {
1347- double width = [metaData[@" width" ] doubleValue ];
1348- double height = [metaData[@" height" ] doubleValue ];
1349- if (!(width > 0 && height > 0 )) {
1344+ if (typedMessage.mediaType == LCIMMessageMediaTypeImage) {
1345+ double width = [metaData[@" width" ] doubleValue ];
1346+ double height = [metaData[@" height" ] doubleValue ];
1347+ if (!(width > 0 && height > 0 )) {
13501348#if TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH
1351- UIImage *image = ({
1352- UIImage *image;
1353- NSString *cachedPath = file.persistentCachePath ;
1354- if ([[NSFileManager defaultManager ] fileExistsAtPath: cachedPath]) {
1355- NSData *data = [NSData dataWithContentsOfFile: cachedPath];
1356- image = [UIImage imageWithData: data];
1357- }
1358- image;
1359- });
1360- width = image.size .width * image.scale ;
1361- height = image.size .height * image.scale ;
1362- #elif TARGET_OS_OSX
1363- NSImage *image = ({
1364- NSImage *image;
1365- NSString *cachedPath = file.persistentCachePath ;
1366- if ([[NSFileManager defaultManager ] fileExistsAtPath: cachedPath]) {
1367- NSData *data = [NSData dataWithContentsOfFile: cachedPath];
1368- image = [[NSImage alloc ] initWithData: data];
1369- }
1370- image;
1371- });
1372- width = image.size .width ;
1373- height = image.size .height ;
1374- #endif
1375- if (width > 0 ) {
1376- metaData[@" width" ] = @(width);
1349+ UIImage *image = ({
1350+ UIImage *image;
1351+ NSString *cachedPath = file.persistentCachePath ;
1352+ if ([[NSFileManager defaultManager ] fileExistsAtPath: cachedPath]) {
1353+ NSData *data = [NSData dataWithContentsOfFile: cachedPath];
1354+ image = [UIImage imageWithData: data];
13771355 }
1378- if (height > 0 ) {
1379- metaData[@" height" ] = @(height);
1356+ image;
1357+ });
1358+ width = image.size .width * image.scale ;
1359+ height = image.size .height * image.scale ;
1360+ #elif TARGET_OS_OSX
1361+ NSImage *image = ({
1362+ NSImage *image;
1363+ NSString *cachedPath = file.persistentCachePath ;
1364+ if ([[NSFileManager defaultManager ] fileExistsAtPath: cachedPath]) {
1365+ NSData *data = [NSData dataWithContentsOfFile: cachedPath];
1366+ image = [[NSImage alloc ] initWithData: data];
13801367 }
1368+ image;
1369+ });
1370+ width = image.size .width ;
1371+ height = image.size .height ;
1372+ #endif
1373+ if (width > 0 ) {
1374+ metaData[@" width" ] = @(width);
1375+ }
1376+ if (height > 0 ) {
1377+ metaData[@" height" ] = @(height);
13811378 }
13821379 }
1383- break ;
1384- case kLCIMMessageMediaTypeAudio :
1385- case kLCIMMessageMediaTypeVideo :
1386- {
1387- double seconds = [metaData[@" duration" ] doubleValue ];
1388- if (!(seconds > 0 )) {
1389- NSString *path = file.persistentCachePath ;
1390- if ([[NSFileManager defaultManager ] fileExistsAtPath: path]) {
1391- NSURL *fileURL = [NSURL fileURLWithPath: path];
1392- if (fileURL) {
1393- AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL: fileURL
1394- options: nil ];
1395- seconds = CMTimeGetSeconds (audioAsset.duration );
1396- if (seconds > 0 ) {
1397- metaData[@" duration" ] = @(seconds);
1398- }
1380+ } else if (typedMessage.mediaType == LCIMMessageMediaTypeAudio ||
1381+ typedMessage.mediaType == LCIMMessageMediaTypeVideo) {
1382+ double seconds = [metaData[@" duration" ] doubleValue ];
1383+ if (!(seconds > 0 )) {
1384+ NSString *path = file.persistentCachePath ;
1385+ if ([[NSFileManager defaultManager ] fileExistsAtPath: path]) {
1386+ NSURL *fileURL = [NSURL fileURLWithPath: path];
1387+ if (fileURL) {
1388+ AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL: fileURL
1389+ options: nil ];
1390+ seconds = CMTimeGetSeconds (audioAsset.duration );
1391+ if (seconds > 0 ) {
1392+ metaData[@" duration" ] = @(seconds);
13991393 }
14001394 }
14011395 }
14021396 }
1403- break ;
1404- case kLCIMMessageMediaTypeFile :
1405- default :
1406- break ;
14071397 }
14081398 NSString *fileName = file.name ;
14091399 if (fileName) {
0 commit comments