filter sequences of more than 3 ltr-rtl
This commit is contained in:
parent
7b3d871f28
commit
96224c0fc6
|
@ -606,7 +606,7 @@ public class Message extends AbstractEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpannableStringBuilder getMergedBody() {
|
public SpannableStringBuilder getMergedBody() {
|
||||||
SpannableStringBuilder body = new SpannableStringBuilder(this.body.trim());
|
SpannableStringBuilder body = new SpannableStringBuilder(MessageUtils.filterLtrRtl(this.body).trim());
|
||||||
Message current = this;
|
Message current = this;
|
||||||
while (current.mergeable(current.next())) {
|
while (current.mergeable(current.next())) {
|
||||||
current = current.next();
|
current = current.next();
|
||||||
|
@ -616,7 +616,7 @@ public class Message extends AbstractEntity {
|
||||||
body.append("\n\n");
|
body.append("\n\n");
|
||||||
body.setSpan(new MergeSeparator(), body.length() - 2, body.length(),
|
body.setSpan(new MergeSeparator(), body.length() - 2, body.length(),
|
||||||
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
body.append(current.getBody().trim());
|
body.append(MessageUtils.filterLtrRtl(current.getBody()).trim());
|
||||||
}
|
}
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,24 +31,30 @@ package eu.siacs.conversations.utils;
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.http.AesGcmURLStreamHandler;
|
import eu.siacs.conversations.http.AesGcmURLStreamHandler;
|
||||||
|
|
||||||
public class MessageUtils {
|
public class MessageUtils {
|
||||||
|
|
||||||
|
private static final Pattern LTR_RTL = Pattern.compile("(\\u200E[^\\u200F]*\\u200F){3,}");
|
||||||
|
|
||||||
|
private static final String EMPTY_STRING = "";
|
||||||
|
|
||||||
public static String prepareQuote(Message message) {
|
public static String prepareQuote(Message message) {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
final String body = message.getMergedBody().toString();
|
final String body = message.getMergedBody().toString();
|
||||||
for(String line : body.split("\n")) {
|
for (String line : body.split("\n")) {
|
||||||
if (line.length() <= 0) {
|
if (line.length() <= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
final char c = line.charAt(0);
|
final char c = line.charAt(0);
|
||||||
if (c == '>' && UIHelper.isPositionFollowedByQuoteableCharacter(line,0)
|
if (c == '>' && UIHelper.isPositionFollowedByQuoteableCharacter(line, 0)
|
||||||
|| (c == '\u00bb' && !UIHelper.isPositionFollowedByQuote(line,0))) {
|
|| (c == '\u00bb' && !UIHelper.isPositionFollowedByQuote(line, 0))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (builder.length() != 0 ) {
|
if (builder.length() != 0) {
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
}
|
}
|
||||||
builder.append(line.trim());
|
builder.append(line.trim());
|
||||||
|
@ -79,4 +85,8 @@ public class MessageUtils {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String filterLtrRtl(String body) {
|
||||||
|
return LTR_RTL.matcher(body).replaceFirst(EMPTY_STRING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -283,7 +283,7 @@ public class UIHelper {
|
||||||
} else if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
|
} else if (message.getType() == Message.TYPE_FILE || message.getType() == Message.TYPE_IMAGE) {
|
||||||
return new Pair<>(getFileDescriptionString(context, message), true);
|
return new Pair<>(getFileDescriptionString(context, message), true);
|
||||||
} else {
|
} else {
|
||||||
final String body = message.getBody();
|
final String body = MessageUtils.filterLtrRtl(message.getBody());
|
||||||
if (body.startsWith(Message.ME_COMMAND)) {
|
if (body.startsWith(Message.ME_COMMAND)) {
|
||||||
return new Pair<>(body.replaceAll("^" + Message.ME_COMMAND,
|
return new Pair<>(body.replaceAll("^" + Message.ME_COMMAND,
|
||||||
UIHelper.getMessageDisplayName(message) + " "), false);
|
UIHelper.getMessageDisplayName(message) + " "), false);
|
||||||
|
|
Loading…
Reference in a new issue