mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Implement link previews for group conversations
This commit is contained in:
parent
9d76b8bdf7
commit
e109df7525
@ -954,23 +954,59 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
content.isNeedsReceipt());
|
content.isNeedsReceipt());
|
||||||
|
|
||||||
textMessage = new IncomingEncryptedMessage(textMessage, body);
|
textMessage = new IncomingEncryptedMessage(textMessage, body);
|
||||||
Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage);
|
|
||||||
|
|
||||||
if (insertResult.isPresent()) threadId = insertResult.get().getThreadId();
|
List<Link> urls = LinkPreviewUtil.findWhitelistedUrls(body);
|
||||||
else threadId = null;
|
int urlCount = urls.size();
|
||||||
|
if (urlCount != 0) {
|
||||||
|
IncomingMediaMessage mediaMessage = new IncomingMediaMessage(Address.fromExternal(context, content.getSender()),
|
||||||
|
message.getTimestamp(), -1,
|
||||||
|
message.getExpiresInSeconds() * 1000L, false,
|
||||||
|
content.isNeedsReceipt(),
|
||||||
|
message.getBody(),
|
||||||
|
message.getGroupInfo(),
|
||||||
|
message.getAttachments(),
|
||||||
|
Optional.absent(),
|
||||||
|
Optional.absent(),
|
||||||
|
Optional.of(new ArrayList<>()),
|
||||||
|
Optional.absent());
|
||||||
|
LinkPreviewRepository lpr = new LinkPreviewRepository(context);
|
||||||
|
final int[] count = { 0 };
|
||||||
|
for (Link url : urls) {
|
||||||
|
lpr.getLinkPreview(context, url.getUrl(), lp -> Util.runOnMain(() -> {
|
||||||
|
int c = count[0];
|
||||||
|
c = c + 1;
|
||||||
|
count[0] = c;
|
||||||
|
if (lp.isPresent()) {
|
||||||
|
mediaMessage.getLinkPreviews().add(lp.get());
|
||||||
|
}
|
||||||
|
if (c == urlCount) {
|
||||||
|
try {
|
||||||
|
handleMediaMessage(content, mediaMessage, smsMessageId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Optional<InsertResult> insertResult = database.insertMessageInbox(textMessage);
|
||||||
|
|
||||||
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
|
if (insertResult.isPresent()) threadId = insertResult.get().getThreadId();
|
||||||
|
else threadId = null;
|
||||||
|
|
||||||
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
if (smsMessageId.isPresent()) database.deleteMessage(smsMessageId.get());
|
||||||
long messageID = insertResult.get().getMessageId();
|
|
||||||
long messageServerID = messageServerIDOrNull.get();
|
if (insertResult.isPresent() && messageServerIDOrNull.isPresent()) {
|
||||||
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
|
long messageID = insertResult.get().getMessageId();
|
||||||
|
long messageServerID = messageServerIDOrNull.get();
|
||||||
|
DatabaseFactory.getLokiMessageDatabase(context).setServerID(messageID, messageServerID);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (threadId != null) {
|
||||||
|
MessageNotifier.updateNotification(context, threadId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (threadId != null) {
|
|
||||||
MessageNotifier.updateNotification(context, threadId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void acceptFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) {
|
private void acceptFriendRequestIfNeeded(@NonNull SignalServiceEnvelope envelope, @NonNull SignalServiceContent content) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user