2525use OCP \AppFramework \Http \ContentSecurityPolicy ;
2626use OCP \AppFramework \Http \JSONResponse ;
2727use OCP \AppFramework \Http \TemplateResponse ;
28- use OCP \Files \IMimeTypeDetector ;
2928use OCP \IL10N ;
3029use OCP \Util ;
3130
@@ -59,11 +58,6 @@ class MessagesController extends Controller {
5958 */
6059 private $ l10n ;
6160
62- /**
63- * @var IMimeTypeDetector
64- */
65- private $ mimeTypeDetector ;
66-
6761 /**
6862 * @var IAccount[]
6963 */
@@ -78,7 +72,6 @@ class MessagesController extends Controller {
7872 * @param $contactsIntegration
7973 * @param $logger
8074 * @param $l10n
81- * @param IMimeTypeDetector $mimeTypeDetector
8275 */
8376 public function __construct ($ appName ,
8477 $ request ,
@@ -87,16 +80,14 @@ public function __construct($appName,
8780 $ userFolder ,
8881 $ contactsIntegration ,
8982 $ logger ,
90- $ l10n ,
91- IMimeTypeDetector $ mimeTypeDetector ) {
83+ $ l10n ) {
9284 parent ::__construct ($ appName , $ request );
9385 $ this ->accountService = $ accountService ;
9486 $ this ->currentUserId = $ currentUserId ;
9587 $ this ->userFolder = $ userFolder ;
9688 $ this ->contactsIntegration = $ contactsIntegration ;
9789 $ this ->logger = $ logger ;
9890 $ this ->l10n = $ l10n ;
99- $ this ->mimeTypeDetector = $ mimeTypeDetector ;
10091 }
10192
10293 /**
@@ -384,7 +375,7 @@ private function enrichDownloadUrl($accountId, $folderId, $messageId, $attachmen
384375 ]);
385376 $ downloadUrl = \OC ::$ server ->getURLGenerator ()->getAbsoluteURL ($ downloadUrl );
386377 $ attachment ['downloadUrl ' ] = $ downloadUrl ;
387- $ attachment ['mimeUrl ' ] = $ this ->mimeTypeDetector -> mimeTypeIcon ($ attachment ['mime ' ]);
378+ $ attachment ['mimeUrl ' ] = $ this ->mimeTypeIcon ($ attachment ['mime ' ]);
388379
389380 if ($ this ->attachmentIsImage ($ attachment )) {
390381 $ attachment ['isImage ' ] = true ;
@@ -469,4 +460,22 @@ private function enhanceMessage($accountId, $folderId, $id, $m, IAccount $accoun
469460 return $ json ;
470461 }
471462
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+
472481}
0 commit comments