25
25
use OCP \AppFramework \Http \ContentSecurityPolicy ;
26
26
use OCP \AppFramework \Http \JSONResponse ;
27
27
use OCP \AppFramework \Http \TemplateResponse ;
28
- use OCP \Files \IMimeTypeDetector ;
29
28
use OCP \IL10N ;
30
29
use OCP \Util ;
31
30
@@ -59,11 +58,6 @@ class MessagesController extends Controller {
59
58
*/
60
59
private $ l10n ;
61
60
62
- /**
63
- * @var IMimeTypeDetector
64
- */
65
- private $ mimeTypeDetector ;
66
-
67
61
/**
68
62
* @var IAccount[]
69
63
*/
@@ -78,7 +72,6 @@ class MessagesController extends Controller {
78
72
* @param $contactsIntegration
79
73
* @param $logger
80
74
* @param $l10n
81
- * @param IMimeTypeDetector $mimeTypeDetector
82
75
*/
83
76
public function __construct ($ appName ,
84
77
$ request ,
@@ -87,16 +80,14 @@ public function __construct($appName,
87
80
$ userFolder ,
88
81
$ contactsIntegration ,
89
82
$ logger ,
90
- $ l10n ,
91
- IMimeTypeDetector $ mimeTypeDetector ) {
83
+ $ l10n ) {
92
84
parent ::__construct ($ appName , $ request );
93
85
$ this ->accountService = $ accountService ;
94
86
$ this ->currentUserId = $ currentUserId ;
95
87
$ this ->userFolder = $ userFolder ;
96
88
$ this ->contactsIntegration = $ contactsIntegration ;
97
89
$ this ->logger = $ logger ;
98
90
$ this ->l10n = $ l10n ;
99
- $ this ->mimeTypeDetector = $ mimeTypeDetector ;
100
91
}
101
92
102
93
/**
@@ -384,7 +375,7 @@ private function enrichDownloadUrl($accountId, $folderId, $messageId, $attachmen
384
375
]);
385
376
$ downloadUrl = \OC ::$ server ->getURLGenerator ()->getAbsoluteURL ($ downloadUrl );
386
377
$ attachment ['downloadUrl ' ] = $ downloadUrl ;
387
- $ attachment ['mimeUrl ' ] = $ this ->mimeTypeDetector -> mimeTypeIcon ($ attachment ['mime ' ]);
378
+ $ attachment ['mimeUrl ' ] = $ this ->mimeTypeIcon ($ attachment ['mime ' ]);
388
379
389
380
if ($ this ->attachmentIsImage ($ attachment )) {
390
381
$ attachment ['isImage ' ] = true ;
@@ -469,4 +460,22 @@ private function enhanceMessage($accountId, $folderId, $id, $m, IAccount $accoun
469
460
return $ json ;
470
461
}
471
462
463
+ /**
464
+ * Get path to the icon of a file type
465
+ *
466
+ * @todo Inject IMimeTypeDetector once core 8.2+ is supported
467
+ *
468
+ * @param string $mimeType the MIME type
469
+ */
470
+ private function mimeTypeIcon ($ mimeType ) {
471
+ $ ocVersion = \OC ::$ server ->getConfig ()->getSystemValue ('version ' , '0.0.0 ' );
472
+ if (version_compare ($ ocVersion , '8.2.0 ' , '< ' )) {
473
+ // Version-hack for 8.1 and lower
474
+ return \OC_Helper::mimetypeIcon ($ mimeType );
475
+ }
476
+ /* @var IMimeTypeDetector */
477
+ $ mimeTypeDetector = \OC ::$ server ->getMimeTypeDetector ();
478
+ return $ mimeTypeDetector ->mimeTypeIcon ($ mimeType );
479
+ }
480
+
472
481
}
0 commit comments