ソースを参照

Merge pull request #756 from threema-ch/more-audio-messages

Better MIME handling for audio messages
Danilo Bargen 6 年 前
コミット
17660910dc
3 ファイル変更13 行追加6 行削除
  1. 1 1
      src/partials/messenger.ts
  2. 11 3
      src/services/mime.ts
  3. 1 2
      src/services/webclient.ts

+ 1 - 1
src/partials/messenger.ts

@@ -561,7 +561,7 @@ class ConversationController {
                         }
                         captionSupported = this.mimeService.isImage(msg.fileType);
                         if (this.mimeService.isImage(msg.fileType)
-                            || this.mimeService.isAudio(msg.fileType)
+                            || this.mimeService.isAudio(msg.fileType, this.webClientService.clientInfo.os)
                             || this.mimeService.isVideo(msg.fileType)) {
                             showSendAsFileCheckbox = true;
                             break;

+ 11 - 3
src/services/mime.ts

@@ -24,7 +24,8 @@ export class MimeService {
     private $translate: ng.translate.ITranslateService;
 
     private imageMimeTypes: string[] = ['image/png', 'image/jpg', 'image/jpeg'];
-    private audioMimeTypes: string[] = ['audio/ogg'];
+    private audioMimeTypesAndroid: string[] = ['audio/ogg'];
+    private audioMimeTypesIos: string[] = ['audio/m4a', 'audio/x-m4a', 'audio/mp4'];
     private videoMimeTypes: string[] = ['video/mp4', 'video/mpg', 'video/mpeg'];
 
     constructor($log: ng.ILogService, $translate: ng.translate.ITranslateService) {
@@ -36,8 +37,15 @@ export class MimeService {
         return this.is(mimeType, this.imageMimeTypes);
     }
 
-    public isAudio(mimeType: string): boolean {
-        return this.is(mimeType, this.audioMimeTypes);
+    public isAudio(mimeType: string, os: threema.OperatingSystem): boolean {
+        // Note: Supported audio file types depend on the mobile OS
+        switch (os) {
+            case threema.OperatingSystem.Android:
+                return this.is(mimeType, this.audioMimeTypesAndroid);
+            case threema.OperatingSystem.Ios:
+                return this.is(mimeType, this.audioMimeTypesIos);
+        }
+        return false;
     }
 
     public isVideo(mimeType: string): boolean {

+ 1 - 2
src/services/webclient.ts

@@ -1610,8 +1610,7 @@ export class WebClientService {
                         if ((message as threema.FileMessageData).sendAsFile !== true) {
                             // check mime type
                             const mime = (message as threema.FileMessageData).fileType;
-
-                            if (this.mimeService.isAudio(mime)) {
+                            if (this.mimeService.isAudio(mime, this.clientInfo.os)) {
                                 requiredFeature = ContactReceiverFeature.AUDIO;
                                 invalidFeatureMessage = 'error.AUDIO_MESSAGES_NOT_SUPPORTED';
                             } else if (this.mimeService.isImage(mime) || this.mimeService.isVideo(mime)) {