aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-02-11 22:36:17 +0100
committersteckbrief <steckbrief@chefmail.de>2016-02-11 22:40:48 +0100
commit9c87e2269cc1d427fab42047cd8993b6bfb07b6f (patch)
treecff8d8c37e416b43c8eb84216116883bdf1655fa /src/main/java/de
parentd38b3c2cf2134738781da626fa7ed49046c9a00f (diff)
Compilation errors and merge mixups fixed
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java13
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java22
2 files changed, 29 insertions, 6 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
index ac58e698..7d676022 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ResizePictureUserDecisionListener.java
@@ -60,6 +60,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
@Override
public void error(int error, Message message) {
hidePrepareFileToast();
+ //TODO Find another way to display an error dialog
ResizePictureUserDecisionListener.this.activity.displayErrorDialog(error);
}
@@ -97,10 +98,10 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
this.showPrepareFileToast();
final Message message;
final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
} else {
- message = new Message(conversation, "", conversation.getNextEncryption(forceEncryption));
+ message = new Message(conversation, "", conversation.getNextEncryption());
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
@@ -116,7 +117,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
int imageWidth = resizedAndRotatedImage.getWidth();
int imageHeight = resizedAndRotatedImage.getHeight();
MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
xmppConnectionService.getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
@@ -134,10 +135,10 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
this.showPrepareFileToast();
final Message message;
final boolean forceEncryption = ConversationsPlusPreferences.forceEncryption();
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
message = new Message(conversation, "", Message.ENCRYPTION_DECRYPTED);
} else {
- message = new Message(conversation, "", conversation.getNextEncryption(forceEncryption));
+ message = new Message(conversation, "", conversation.getNextEncryption());
}
message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_IMAGE);
@@ -155,7 +156,7 @@ public class ResizePictureUserDecisionListener implements UserDecisionListener {
int imageWidth = options.outWidth;
String filePath = FileHelper.getRealPathFromUri(uri);
MessageUtil.updateMessageWithImageDetails(message, filePath, imageSize, imageWidth, imageHeight);
- if (conversation.getNextEncryption(forceEncryption) == Message.ENCRYPTION_PGP) {
+ if (conversation.getNextEncryption() == Message.ENCRYPTION_PGP) {
xmppConnectionService.getPgpEngine().encrypt(message, callback);
} else {
callback.success(message);
diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
index 9fedada6..81f5b843 100644
--- a/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
+++ b/src/main/java/de/thedevstack/conversationsplus/utils/MessageUtil.java
@@ -3,6 +3,8 @@ package de.thedevstack.conversationsplus.utils;
import android.graphics.BitmapFactory;
import java.net.URL;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
@@ -12,6 +14,26 @@ import eu.siacs.conversations.persistance.FileBackend;
* Created by tzur on 15.12.2015.
*/
public final class MessageUtil {
+ public static boolean wasHighlightedOrPrivate(final Message message) {
+ final String nick = message.getConversation().getMucOptions().getActualNick();
+ final Pattern highlight = generateNickHighlightPattern(nick);
+ if (message.getBody() == null || nick == null) {
+ return false;
+ }
+ final Matcher m = highlight.matcher(message.getBody());
+ return (m.find() || message.getType() == Message.TYPE_PRIVATE);
+ }
+
+ private static Pattern generateNickHighlightPattern(final String nick) {
+ // We expect a word boundary, i.e. space or start of string, followed by
+ // the
+ // nick (matched in case-insensitive manner), followed by optional
+ // punctuation (for example "bob: i disagree" or "how are you alice?"),
+ // followed by another word boundary.
+ return Pattern.compile("\\b" + Pattern.quote(nick) + "\\p{Punct}?\\b",
+ Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE);
+ }
+
public static void updateMessageWithImageDetails(Message message, String filePath, long size, int imageWidth, int imageHeight) {
message.setRelativeFilePath(filePath);
MessageUtil.updateMessageBodyWithImageParams(message, size, imageWidth, imageHeight);