show link preview also for links in messages

This commit is contained in:
Christian Schneppe 2020-11-17 17:22:13 +01:00
parent 89c7171d11
commit e16b196668
No known key found for this signature in database
GPG key ID: F30B8D686B44D87E
2 changed files with 23 additions and 5 deletions

View file

@ -19,6 +19,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.axolotl.FingerprintStatus;
@ -122,6 +124,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
private Boolean isGeoUri = null;
private Boolean isXmppUri = null;
private Boolean isWebUri = null;
private String WebUri = "";
private Boolean isEmojisOnly = null;
private Boolean treatAsDownloadable = null;
private FileParams fileParams = null;
@ -863,11 +866,24 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
public synchronized boolean isWebUri() {
if (isWebUri == null) {
isWebUri = Patterns.WEB_URL.matcher(body).matches();
Pattern pattern = Patterns.WEB_URL;
Matcher matcher = pattern.matcher(body);
isWebUri = matcher.find();
}
return isWebUri;
}
public synchronized String getWebUri() {
if (isWebUri) {
Pattern pattern = Patterns.WEB_URL;
Matcher matcher = pattern.matcher(body);
if (WebUri.equalsIgnoreCase("") && matcher.find()) {
WebUri = matcher.group(0);
};
}
return WebUri;
}
public synchronized void resetFileParams() {
this.fileParams = null;
}

View file

@ -651,6 +651,9 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
StylingHelper.highlight(activity, body, highlightedTerm, StylingHelper.isDarkText(viewHolder.messageBody));
}
}
if (message.isWebUri() && (message.getWebUri() != null || message.getWebUri().equalsIgnoreCase(""))) {
displayRichLinkMessage(viewHolder, message, darkBackground);
}
MyLinkify.addLinks(body, true);
viewHolder.messageBody.setAutoLinkMask(0);
viewHolder.messageBody.setText(EmojiWrapper.transform(body));
@ -775,7 +778,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.download_button.setVisibility(View.GONE);
viewHolder.progressBar.setVisibility(View.GONE);
final SpannableStringBuilder body = new SpannableStringBuilder(replaceYoutube(activity.getApplicationContext(), message.getMergedBody().toString()));
final SpannableStringBuilder body = new SpannableStringBuilder(replaceYoutube(activity.getApplicationContext(), message.getWebUri()));
final boolean dataSaverDisabled = activity.xmppConnectionService.isDataSaverDisabled();
viewHolder.richlinkview.setVisibility(View.VISIBLE);
if (mShowLinksInside) {
@ -793,12 +796,13 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
viewHolder.richlinkview.setLayoutParams(layoutParams);
final String url = body.toString();
final String weburl;
final String lcUrl = url.toLowerCase(Locale.US).trim();
final String lcUrl = url.trim();
if (lcUrl.startsWith("http://") || lcUrl.startsWith("https://")) {
weburl = removeTrailingBracket(url);
} else {
weburl = "http://" + removeTrailingBracket(url);
}
Log.d(Config.LOGTAG, "Weburi: " + weburl);
viewHolder.richlinkview.setLink(weburl, message.getUuid(), dataSaverDisabled, activity.xmppConnectionService, new RichPreview.ViewListener() {
@Override
@ -1274,8 +1278,6 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
UIHelper.getFileDescriptionString(activity, message)),
darkBackground);
}
} else if (message.isWebUri()) {
displayRichLinkMessage(viewHolder, message, darkBackground);
} else {
displayTextMessage(viewHolder, message, darkBackground, type);
}