From 4c4c583923bccdd67cd9ab977b59b275ae28ca25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 14 Jul 2021 09:26:17 +0200 Subject: [PATCH 1/3] Remove media in text message detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The method 'TextMatchers#getMessageTypeFromString' suggested MIME types for linked files in text message. Also for links like this not working example: - http://example.local/image.png - image.png In those cases no image can be loaded and that results in empty previews like shown in the issue #1167. So for alignment reasons to spreed and Talk iOS app this media detection is removed and only links will be shown. Resolves: #1167 Signed-off-by: Tim Krüger --- .../java/com/nextcloud/talk/models/json/chat/ChatMessage.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java index 41c5c48c3..700db89ed 100644 --- a/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java +++ b/app/src/main/java/com/nextcloud/talk/models/json/chat/ChatMessage.java @@ -2,6 +2,8 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Tim Krüger + * Copyright (C) 2021 Tim Krüger * Copyright (C) 2017-2018 Mario Danic * * This program is free software: you can redistribute it and/or modify @@ -180,7 +182,7 @@ public class ChatMessage implements MessageContentType, MessageContentType.Image } - return TextMatchers.getMessageTypeFromString(getText()); + return MessageType.REGULAR_TEXT_MESSAGE; } public Map getSelectedIndividualHashMap() { From 8468535a1e3e8bcaf1641f0f1e6a991109295575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Kr=C3=BCger?= Date: Wed, 14 Jul 2021 09:49:06 +0200 Subject: [PATCH 2/3] Remove unused method and dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See: commit 4c4c5839, #1167 Signed-off-by: Tim Krüger --- app/build.gradle | 4 - .../nextcloud/talk/utils/TextMatchers.java | 62 +--------- .../talk/utils/TextMatchersTest.java | 109 ------------------ 3 files changed, 3 insertions(+), 172 deletions(-) delete mode 100644 app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java diff --git a/app/build.gradle b/app/build.gradle index 1e8fe8a1e..9286fc31f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -269,10 +269,6 @@ dependencies { implementation 'com.github.nextcloud:PopupBubble:1.0.6' implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' - implementation('eu.medsea.mimeutil:mime-util:2.1.3', { - exclude group: 'org.slf4j' - }) - implementation "com.afollestad.material-dialogs:core:${materialDialogsVersion}" implementation "com.afollestad.material-dialogs:datetime:${materialDialogsVersion}" implementation "com.afollestad.material-dialogs:bottomsheets:${materialDialogsVersion}" diff --git a/app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java b/app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java index 3988f6e31..25fda04e9 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java +++ b/app/src/main/java/com/nextcloud/talk/utils/TextMatchers.java @@ -2,6 +2,8 @@ * Nextcloud Talk application * * @author Mario Danic + * @author Tim Krüger + * Copyright (C) 2021 Tim Krüger * Copyright (C) 2017-2018 Mario Danic * * This program is free software: you can redistribute it and/or modify @@ -22,71 +24,13 @@ package com.nextcloud.talk.utils; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.util.PatternsCompat; -import com.nextcloud.talk.models.json.chat.ChatMessage; import com.vanniktech.emoji.EmojiInformation; import com.vanniktech.emoji.EmojiUtils; -import eu.medsea.mimeutil.MimeUtil; -import eu.medsea.mimeutil.detector.ExtensionMimeDetector; -import eu.medsea.mimeutil.detector.MagicMimeMimeDetector; -import eu.medsea.mimeutil.detector.OpendesktopMimeDetector; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; +import androidx.annotation.Nullable; public final class TextMatchers { - private static final String TAG = "TextMatchers"; - - public static ChatMessage.MessageType getMessageTypeFromString(@NonNull final String text) { - List links = new ArrayList<>(); - Matcher m = PatternsCompat.WEB_URL.matcher(text); - while (m.find()) { - String url = m.group(); - links.add(url); - } - - if (links.size() == 1 && text.trim().length() == links.get(0).length()) { - String specialLink = links.get(0); - if (specialLink.startsWith("https://media.giphy.com/") && specialLink.endsWith(".gif")) { - return ChatMessage.MessageType.SINGLE_LINK_GIPHY_MESSAGE; - } else if (specialLink.contains("tenor.com/") && - Pattern.compile("https://media.*\\.tenor\\.com.*\\.gif.*", - Pattern.CASE_INSENSITIVE).matcher(specialLink).matches()) { - return ChatMessage.MessageType.SINGLE_LINK_TENOR_MESSAGE; - } else { - if (specialLink.contains("?")) { - specialLink = specialLink.substring(0, specialLink.indexOf("?")); - } - MimeUtil.registerMimeDetector(MagicMimeMimeDetector.class.getName()); - MimeUtil.registerMimeDetector(ExtensionMimeDetector.class.getName()); - MimeUtil.registerMimeDetector(OpendesktopMimeDetector.class.getName()); - - String mimeType = MimeUtil.getMostSpecificMimeType(MimeUtil.getMimeTypes(specialLink)).toString(); - if (mimeType.startsWith("image/")) { - if (mimeType.equalsIgnoreCase("image/gif")) { - return ChatMessage.MessageType.SINGLE_LINK_GIF_MESSAGE; - } else { - return ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE; - } - } else if (mimeType.startsWith("video/")) { - return ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE; - } else if (mimeType.startsWith("audio/")) { - return ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE; - } - - return ChatMessage.MessageType.SINGLE_LINK_MESSAGE; - } - } - - // if we have 0 or more than 1 link, we're a regular message - return ChatMessage.MessageType.REGULAR_TEXT_MESSAGE; - } - public static boolean isMessageWithSingleEmoticonOnly(@Nullable final String text) { final EmojiInformation emojiInformation = EmojiUtils.emojiInformation(text); return (emojiInformation.isOnlyEmojis && emojiInformation.emojis.size() == 1); diff --git a/app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java b/app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java deleted file mode 100644 index fb295f317..000000000 --- a/app/src/test/java/com/nextcloud/talk/utils/TextMatchersTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk.utils; - -import com.nextcloud.talk.models.json.chat.ChatMessage; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class TextMatchersTest { - - @Test - public void getMessageTypeFromString_regularTextGiven_regularTextMessageTypeReturned() { - String simpleMessageText = "Hello world! Have a cookie!"; - String messageContainingLink = "Hello https://nextcloud.com! Have a good day"; - - assertEquals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE, - TextMatchers.getMessageTypeFromString(simpleMessageText)); - assertEquals(ChatMessage.MessageType.REGULAR_TEXT_MESSAGE, - TextMatchers.getMessageTypeFromString(messageContainingLink)); - } - - @Test - public void getMessageTypeFromString_singleUrlTextGiven_singleLinkMessageTypeReturned() { - String simpleUrlText = "https://nextcloud.com/"; - String complexUrlText = "https://docs.nextcloud.com/server/15/admin_manual/#target-audience"; - - assertEquals(ChatMessage.MessageType.SINGLE_LINK_MESSAGE, - TextMatchers.getMessageTypeFromString(simpleUrlText)); - assertEquals(ChatMessage.MessageType.SINGLE_LINK_MESSAGE, - TextMatchers.getMessageTypeFromString(complexUrlText)); - } - - @Test - public void getMessageTypeFromString_imageLinkGiven_singleLinkImageMessageReturned() { - String simpleImageText = "https://nextcloud.com/image.jpg"; - String complexImageUrlText = "https://nextcloud.com/wp-content/themes/next/assets/img/features/mobileDesktop.png?x22777"; - - assertEquals(ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE, - TextMatchers.getMessageTypeFromString(simpleImageText)); - assertEquals(ChatMessage.MessageType.SINGLE_LINK_IMAGE_MESSAGE, - TextMatchers.getMessageTypeFromString(complexImageUrlText)); - } - - @Test - public void getMessageTypeFromString_gifLinkGiven_gifMessageTypeReturned() { - String gifImageText = "https://nextcloud.com/funny.gif"; - - assertEquals(ChatMessage.MessageType.SINGLE_LINK_GIF_MESSAGE, - TextMatchers.getMessageTypeFromString(gifImageText)); - } - - @Test - public void getMessageTypeFromString_audioLinkGiven_audioMessageTypeReturned() { - String wavLink = "https://nextcloud.com/message.wav"; - String mp3Link = "https://nextcloud.com/message.mp3"; - - assertEquals(ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE, - TextMatchers.getMessageTypeFromString(wavLink)); - assertEquals(ChatMessage.MessageType.SINGLE_LINK_AUDIO_MESSAGE, - TextMatchers.getMessageTypeFromString(mp3Link)); - } - - @Test - public void getMessageTypeFromString_videoLinkGiven_videoMessageTypeReturned() { - String mp4Link = "https://nextcloud.com/message.mp4"; - String flvLink = "https://nextcloud.com/message.flv"; - - assertEquals(ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE, - TextMatchers.getMessageTypeFromString(mp4Link)); - assertEquals(ChatMessage.MessageType.SINGLE_LINK_VIDEO_MESSAGE, - TextMatchers.getMessageTypeFromString(flvLink)); - } - - @Test - public void getMessageTypeFromString_giphyLinkGiven_giphyMessageTypeReturned() { - String giphyLink = "https://media.giphy.com/media/11fucLQCTOdvBS/giphy.gif"; - - assertEquals(ChatMessage.MessageType.SINGLE_LINK_GIPHY_MESSAGE, - TextMatchers.getMessageTypeFromString(giphyLink)); - } - - @Test - public void getMessageTypeFromString_tenorLinkGiven_tenorMessageTypeReturned() { - String tenorLink = "https://media.tenor.com/images/d98e76e3930cf171cc39e301c9e974af/tenor.gif"; - - assertEquals(ChatMessage.MessageType.SINGLE_LINK_TENOR_MESSAGE, - TextMatchers.getMessageTypeFromString(tenorLink)); - } -} From 9aebf05142f72e6e1de4435d0d07fc8774178d15 Mon Sep 17 00:00:00 2001 From: drone Date: Wed, 14 Jul 2021 08:50:56 +0000 Subject: [PATCH 3/3] Drone: update FindBugs results to reflect reduced error/warning count [skip ci] Signed-off-by: drone --- scripts/analysis/findbugs-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index e88ff725a..73623d101 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -602 \ No newline at end of file +600 \ No newline at end of file