Skip to content

Commit 7a5f9f1

Browse files
Remove initialization on MIMETypeUtil
1 parent 1f61291 commit 7a5f9f1

File tree

3 files changed

+112
-115
lines changed

3 files changed

+112
-115
lines changed

Signal/src/AppDelegate.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
#import "VersionMigrations.h"
2121
#import "UIColor+OWS.h"
2222
#import "CodeVerificationViewController.h"
23-
#import "MIMETypeUtil.h"
24-
#import "TSDatabaseView.h"
25-
#import <PastelogKit/Pastelog.h>
2623

2724
#ifdef __APPLE__
2825
#include "TargetConditionals.h"
@@ -138,7 +135,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
138135
[self refreshContacts];
139136
[TSPreKeyManager refreshPreKeys];
140137
}
141-
[MIMETypeUtil initialize];
138+
142139
return YES;
143140
}
144141

@@ -284,7 +281,11 @@ - (void)prepareScreenshotProtection{
284281
window.windowLevel = CGFLOAT_MAX;
285282

286283
// There appears to be no more reliable way to get the launchscreen image from an asset bundle
287-
NSDictionary *dict = @{@"320x480" : @"LaunchImage-700", @"320x568" : @"LaunchImage-700-568h", @"375x667" : @"LaunchImage-800-667h", @"414x736" : @"LaunchImage-800-Portrait-736h"};
284+
NSDictionary *dict = @{@"320x480" : @"LaunchImage-700",
285+
@"320x568" : @"LaunchImage-700-568h",
286+
@"375x667" : @"LaunchImage-800-667h",
287+
@"414x736" : @"LaunchImage-800-Portrait-736h"};
288+
288289
NSString *key = [NSString stringWithFormat:@"%dx%d", (int)[UIScreen mainScreen].bounds.size.width, (int)[UIScreen mainScreen].bounds.size.height];
289290
UIImage *launchImage = [UIImage imageNamed:dict[key]];
290291
UIImageView *imgView = [[UIImageView alloc] initWithImage:launchImage];

Signal/src/util/MIMETypeUtil.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
@interface MIMETypeUtil : NSObject
44

5-
+(void) initialize;
6-
75
+(BOOL)isSupportedMIMEType:(NSString*)contentType;
86
+(BOOL)isSupportedVideoMIMEType:(NSString*)contentType;
97
+(BOOL)isSupportedAudioMIMEType:(NSString*)contentType;

Signal/src/util/MIMETypeUtil.m

Lines changed: 106 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -3,159 +3,157 @@
33

44
@implementation MIMETypeUtil
55

6-
static NSDictionary *supportedVideoMIMETypesToExtensionTypes;
7-
static NSDictionary *supportedAudioMIMETypesToExtensionTypes;
8-
static NSDictionary *supportedImageMIMETypesToExtensionTypes;
9-
static NSDictionary *supportedVideoExtensionTypesToMIMETypes;
10-
static NSDictionary *supportedAudioExtensionTypesToMIMETypes;
11-
static NSDictionary *supportedImageExtensionTypesToMIMETypes;
12-
13-
#pragma mark uses file extensions or MIME types only
14-
+(void) initialize {
15-
// Initialize must be called before this class is used. Could later be in e.g. a .plist
16-
supportedVideoMIMETypesToExtensionTypes =@{@"video/3gpp":@"3gp",
17-
@"video/3gpp2":@"3g2",
18-
@"video/mp4":@"mp4",
19-
@"video/quicktime":@"mov",
20-
@"video/x-m4v":@"m4v"
21-
};
22-
23-
supportedAudioMIMETypesToExtensionTypes = @{@"audio/x-m4p":@"m4p",
24-
@"audio/x-m4b":@"m4b",
25-
@"audio/x-m4a":@"m4a",
26-
@"audio/wav":@"wav",
27-
@"audio/x-wav":@"wav",
28-
@"audio/x-mpeg":@"mp3",
29-
@"audio/mpeg":@"mp3",
30-
@"audio/mp4":@"mp4",
31-
@"audio/mp3":@"mp3",
32-
@"audio/mpeg3":@"mp3",
33-
@"audio/x-mp3":@"mp3",
34-
@"audio/x-mpeg3":@"mp3",
35-
@"audio/amr":@"amr",
36-
@"audio/aiff":@"aiff",
37-
@"audio/x-aiff":@"aiff",
38-
@"audio/3gpp2":@"3g2",
39-
@"audio/3gpp":@"3gp"
40-
};
41-
42-
43-
supportedImageMIMETypesToExtensionTypes = @{@"image/jpeg":@"jpeg",
44-
@"image/pjpeg":@"jpeg",
45-
@"image/png":@"png",
46-
@"image/gif":@"gif",
47-
@"image/tiff":@"tif",
48-
@"image/x-tiff":@"tif",
49-
@"image/bmp":@"bmp",
50-
@"image/x-windows-bmp":@"bmp"
51-
};
52-
53-
54-
supportedVideoExtensionTypesToMIMETypes = @{@"3gp":@"video/3gpp",
55-
@"3gpp":@"video/3gpp",
56-
@"3gp2":@"video/3gpp2",
57-
@"3gpp2":@"video/3gpp2",
58-
@"mp4":@"video/mp4",
59-
@"mov":@"video/quicktime",
60-
@"mqv":@"video/quicktime",
61-
@"m4v":@"video/x-m4v"
62-
};
63-
64-
supportedAudioExtensionTypesToMIMETypes = @{@"3gp":@"audio/3gpp",
65-
@"3gpp":@"@audio/3gpp",
66-
@"3g2":@"audio/3gpp2",
67-
@"3gp2":@"audio/3gpp2",
68-
@"aiff":@"audio/aiff",
69-
@"aif":@"audio/aiff",
70-
@"aifc":@"audio/aiff",
71-
@"cdda":@"audio/aiff",
72-
@"amr":@"audio/amr",
73-
@"mp3":@"audio/mp3",
74-
@"swa":@"audio/mp3",
75-
@"mp4":@"audio/mp4",
76-
@"mpeg":@"audio/mpeg",
77-
@"mpg":@"audio/mpeg",
78-
@"wav":@"audio/wav",
79-
@"bwf":@"audio/wav",
80-
@"m4a":@"audio/x-m4a",
81-
@"m4b":@"audio/x-m4b",
82-
@"m4p":@"audio/x-m4p"
83-
};
84-
85-
supportedImageExtensionTypesToMIMETypes = @{@"png":@"image/png",
86-
@"x-png":@"image/png",
87-
@"jfif":@"image/jpeg",
88-
@"jfif":@"image/pjpeg",
89-
@"jfif-tbnl":@"image/jpeg",
90-
@"jpe":@"image/jpeg",
91-
@"jpe":@"image/pjpeg",
92-
@"jpeg":@"image/jpeg",
93-
@"jpg":@"image/jpeg",
94-
@"gif":@"image/gif",
95-
@"tif":@"image/tiff",
96-
@"tiff":@"image/tiff"
97-
};
6+
+ (NSDictionary*)supportedVideoMIMETypesToExtensionTypes{
7+
return @{@"video/3gpp":@"3gp",
8+
@"video/3gpp2":@"3g2",
9+
@"video/mp4":@"mp4",
10+
@"video/quicktime":@"mov",
11+
@"video/x-m4v":@"m4v"
12+
};
13+
}
14+
15+
+ (NSDictionary*)supportedAudioMIMETypesToExtensionTypes{
16+
return @{@"audio/x-m4p":@"m4p",
17+
@"audio/x-m4b":@"m4b",
18+
@"audio/x-m4a":@"m4a",
19+
@"audio/wav":@"wav",
20+
@"audio/x-wav":@"wav",
21+
@"audio/x-mpeg":@"mp3",
22+
@"audio/mpeg":@"mp3",
23+
@"audio/mp4":@"mp4",
24+
@"audio/mp3":@"mp3",
25+
@"audio/mpeg3":@"mp3",
26+
@"audio/x-mp3":@"mp3",
27+
@"audio/x-mpeg3":@"mp3",
28+
@"audio/amr":@"amr",
29+
@"audio/aiff":@"aiff",
30+
@"audio/x-aiff":@"aiff",
31+
@"audio/3gpp2":@"3g2",
32+
@"audio/3gpp":@"3gp"
33+
};
34+
}
35+
36+
+ (NSDictionary*)supportedImageMIMETypesToExtensionTypes{
37+
return @{@"image/jpeg":@"jpeg",
38+
@"image/pjpeg":@"jpeg",
39+
@"image/png":@"png",
40+
@"image/gif":@"gif",
41+
@"image/tiff":@"tif",
42+
@"image/x-tiff":@"tif",
43+
@"image/bmp":@"bmp",
44+
@"image/x-windows-bmp":@"bmp"
45+
};
46+
}
47+
48+
+ (NSDictionary*)supportedVideoExtensionTypesToMIMETypes{
49+
return @{@"3gp":@"video/3gpp",
50+
@"3gpp":@"video/3gpp",
51+
@"3gp2":@"video/3gpp2",
52+
@"3gpp2":@"video/3gpp2",
53+
@"mp4":@"video/mp4",
54+
@"mov":@"video/quicktime",
55+
@"mqv":@"video/quicktime",
56+
@"m4v":@"video/x-m4v"
57+
};
58+
}
59+
+ (NSDictionary*)supportedAudioExtensionTypesToMIMETypes{
60+
return @{@"3gp":@"audio/3gpp",
61+
@"3gpp":@"@audio/3gpp",
62+
@"3g2":@"audio/3gpp2",
63+
@"3gp2":@"audio/3gpp2",
64+
@"aiff":@"audio/aiff",
65+
@"aif":@"audio/aiff",
66+
@"aifc":@"audio/aiff",
67+
@"cdda":@"audio/aiff",
68+
@"amr":@"audio/amr",
69+
@"mp3":@"audio/mp3",
70+
@"swa":@"audio/mp3",
71+
@"mp4":@"audio/mp4",
72+
@"mpeg":@"audio/mpeg",
73+
@"mpg":@"audio/mpeg",
74+
@"wav":@"audio/wav",
75+
@"bwf":@"audio/wav",
76+
@"m4a":@"audio/x-m4a",
77+
@"m4b":@"audio/x-m4b",
78+
@"m4p":@"audio/x-m4p"
79+
};
80+
}
81+
82+
+ (NSDictionary*)supportedImageExtensionTypesToMIMETypes{
83+
return @{@"png":@"image/png",
84+
@"x-png":@"image/png",
85+
@"jfif":@"image/jpeg",
86+
@"jfif":@"image/pjpeg",
87+
@"jfif-tbnl":@"image/jpeg",
88+
@"jpe":@"image/jpeg",
89+
@"jpe":@"image/pjpeg",
90+
@"jpeg":@"image/jpeg",
91+
@"jpg":@"image/jpeg",
92+
@"gif":@"image/gif",
93+
@"tif":@"image/tiff",
94+
@"tiff":@"image/tiff"
95+
};
9896
}
9997

10098
+(BOOL) isSupportedVideoMIMEType:(NSString*)contentType {
101-
return [supportedVideoMIMETypesToExtensionTypes objectForKey:contentType]!=nil;
99+
return [[self supportedVideoMIMETypesToExtensionTypes] objectForKey:contentType]!=nil;
102100
}
103101

104102
+(BOOL) isSupportedAudioMIMEType:(NSString*)contentType {
105-
return [supportedAudioMIMETypesToExtensionTypes objectForKey:contentType]!=nil;
103+
return [[self supportedAudioMIMETypesToExtensionTypes] objectForKey:contentType]!=nil;
106104
}
107105

108106
+(BOOL) isSupportedImageMIMEType:(NSString*)contentType {
109-
return [supportedImageMIMETypesToExtensionTypes objectForKey:contentType]!=nil;
107+
return [[self supportedImageMIMETypesToExtensionTypes] objectForKey:contentType]!=nil;
110108
}
111109

112110
+(BOOL) isSupportedMIMEType:(NSString*)contentType {
113111
return [self isSupportedImageMIMEType:contentType] || [self isSupportedAudioMIMEType:contentType] || [self isSupportedVideoMIMEType:contentType];
114112
}
115113

116114
+(BOOL) isSupportedVideoFile:(NSString*) filePath {
117-
return [supportedVideoExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil;
115+
return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil;
118116
}
119117

120118
+(BOOL) isSupportedAudioFile:(NSString*) filePath {
121-
return [supportedAudioExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil;
119+
return [[self supportedAudioExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil;
122120
}
123121

124122
+(BOOL) isSupportedImageFile:(NSString*) filePath {
125-
return [supportedImageExtensionTypesToMIMETypes objectForKey:[filePath pathExtension]]!=nil;
123+
return [[self supportedImageExtensionTypesToMIMETypes] objectForKey:[filePath pathExtension]]!=nil;
126124
}
127125

128126
+(NSString*) getSupportedExtensionFromVideoMIMEType:(NSString*)supportedMIMEType {
129-
return [supportedVideoMIMETypesToExtensionTypes objectForKey:supportedMIMEType];
127+
return [[self supportedVideoMIMETypesToExtensionTypes] objectForKey:supportedMIMEType];
130128
}
131129

132130
+(NSString*) getSupportedExtensionFromAudioMIMEType:(NSString*)supportedMIMEType {
133-
return [supportedAudioMIMETypesToExtensionTypes objectForKey:supportedMIMEType];
131+
return [[self supportedAudioMIMETypesToExtensionTypes] objectForKey:supportedMIMEType];
134132
}
135133

136134
+(NSString*) getSupportedExtensionFromImageMIMEType:(NSString*)supportedMIMEType {
137-
return [supportedImageMIMETypesToExtensionTypes objectForKey:supportedMIMEType];
135+
return [[self supportedImageMIMETypesToExtensionTypes] objectForKey:supportedMIMEType];
138136
}
139137

140138
+(NSString*) getSupportedMIMETypeFromVideoFile:(NSString*)supportedVideoFile {
141-
return [supportedVideoExtensionTypesToMIMETypes objectForKey:[supportedVideoFile pathExtension]];
142-
}
139+
return [[self supportedVideoExtensionTypesToMIMETypes] objectForKey:[supportedVideoFile pathExtension]];
140+
}
143141

144142
+(NSString*) getSupportedMIMETypeFromAudioFile:(NSString*)supportedAudioFile {
145-
return [supportedAudioExtensionTypesToMIMETypes objectForKey:[supportedAudioFile pathExtension]];
143+
return [[self supportedAudioExtensionTypesToMIMETypes] objectForKey:[supportedAudioFile pathExtension]];
146144
}
147145

148146
+(NSString*) getSupportedMIMETypeFromImageFile:(NSString*)supportedImageFile {
149-
return [supportedImageExtensionTypesToMIMETypes objectForKey:[supportedImageFile pathExtension]];
147+
return [[self supportedImageExtensionTypesToMIMETypes] objectForKey:[supportedImageFile pathExtension]];
150148
}
151149

152150
#pragma mark uses bytes
153151
+(NSString*) getSupportedImageMIMETypeFromImage:(UIImage*)image {
154-
return [image contentType];
152+
return [image contentType];
155153
}
156154

157155
+(BOOL) getIsSupportedTypeFromImage:(UIImage*)image {
158-
return [image isSupportedImageType];
156+
return [image isSupportedImageType];
159157
}
160158

161159
#pragma mark full attachment utilities
@@ -189,7 +187,7 @@ + (NSString*)filePathForAttachment:(NSString*)uniqueId ofMIMEType:(NSString*)con
189187
+(NSURL*) simLinkCorrectExtensionOfFile:(NSURL*)mediaURL ofMIMEType:(NSString*)contentType {
190188
if([self isAudio:contentType]) {
191189
// Audio files in current framework require changing to have extension for player
192-
return [self changeFile:mediaURL toHaveExtension:[supportedAudioMIMETypesToExtensionTypes objectForKey:contentType]];
190+
return [self changeFile:mediaURL toHaveExtension:[[self supportedAudioMIMETypesToExtensionTypes] objectForKey:contentType]];
193191
}
194192
return mediaURL;
195193
}

0 commit comments

Comments
 (0)