mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 11:38:26 +00:00
feat: add image handling across device self-send. close an unclosed resource. remove unnecessary checks and SmsDatabase way of checking for existing message from ourselves
This commit is contained in:
parent
7c2b124ebc
commit
77eb460ba7
@ -158,8 +158,8 @@ dependencies {
|
|||||||
testImplementation 'org.robolectric:shadows-multidex:4.2'
|
testImplementation 'org.robolectric:shadows-multidex:4.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
def canonicalVersionCode = 121
|
def canonicalVersionCode = 135
|
||||||
def canonicalVersionName = "1.6.4"
|
def canonicalVersionName = "1.6.12"
|
||||||
|
|
||||||
def postFixSize = 10
|
def postFixSize = 10
|
||||||
def abiPostFix = ['armeabi-v7a' : 1,
|
def abiPostFix = ['armeabi-v7a' : 1,
|
||||||
|
@ -902,6 +902,17 @@ public class MmsDatabase extends MessagingDatabase {
|
|||||||
return insertMessageInbox(retrieved, contentLocation, threadId, type, 0);
|
return insertMessageInbox(retrieved, contentLocation, threadId, type, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<InsertResult> insertSecureDecryptedMessageOutbox(OutgoingMediaMessage retrieved, long threadId, long serverTimestamp)
|
||||||
|
throws MmsException
|
||||||
|
{
|
||||||
|
long messageId = insertMessageOutbox(retrieved, threadId, false, null, serverTimestamp);
|
||||||
|
if (messageId == -1) {
|
||||||
|
return Optional.absent();
|
||||||
|
}
|
||||||
|
markAsSent(messageId, true);
|
||||||
|
return Optional.fromNullable(new InsertResult(messageId, threadId));
|
||||||
|
}
|
||||||
|
|
||||||
public Optional<InsertResult> insertSecureDecryptedMessageInbox(IncomingMediaMessage retrieved, long threadId, long serverTimestamp)
|
public Optional<InsertResult> insertSecureDecryptedMessageInbox(IncomingMediaMessage retrieved, long threadId, long serverTimestamp)
|
||||||
throws MmsException
|
throws MmsException
|
||||||
{
|
{
|
||||||
|
@ -725,15 +725,6 @@ public class SmsDatabase extends MessagingDatabase {
|
|||||||
contentValues.put(DELIVERY_RECEIPT_COUNT, Stream.of(earlyDeliveryReceipts.values()).mapToLong(Long::longValue).sum());
|
contentValues.put(DELIVERY_RECEIPT_COUNT, Stream.of(earlyDeliveryReceipts.values()).mapToLong(Long::longValue).sum());
|
||||||
contentValues.put(READ_RECEIPT_COUNT, Stream.of(earlyReadReceipts.values()).mapToLong(Long::longValue).sum());
|
contentValues.put(READ_RECEIPT_COUNT, Stream.of(earlyReadReceipts.values()).mapToLong(Long::longValue).sum());
|
||||||
|
|
||||||
SQLiteDatabase readDb = databaseHelper.getReadableDatabase();
|
|
||||||
Cursor existingRecord = readDb.query(TABLE_NAME, null, String.format("%s = ? AND %s = ? AND %s = ?",ADDRESS, THREAD_ID, DATE_SENT),
|
|
||||||
new String[] { address.serialize(), Long.toString(threadId), Long.toString(date) }, null, null, null);
|
|
||||||
int existingRecordCount = existingRecord.getCount();
|
|
||||||
if (existingRecordCount > 0) {
|
|
||||||
// return -1 because record exists from Address to ThreadID with the same date sent (probably sent from us)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||||
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
|
long messageId = db.insert(TABLE_NAME, ADDRESS, contentValues);
|
||||||
if (insertListener != null) {
|
if (insertListener != null) {
|
||||||
|
@ -83,6 +83,7 @@ import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocolV2;
|
|||||||
import org.thoughtcrime.securesms.loki.protocol.SessionManagementProtocol;
|
import org.thoughtcrime.securesms.loki.protocol.SessionManagementProtocol;
|
||||||
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
|
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol;
|
||||||
import org.thoughtcrime.securesms.loki.protocol.SessionResetImplementation;
|
import org.thoughtcrime.securesms.loki.protocol.SessionResetImplementation;
|
||||||
|
import org.thoughtcrime.securesms.loki.utilities.DatabaseUtilitiesKt;
|
||||||
import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities;
|
import org.thoughtcrime.securesms.loki.utilities.MentionManagerUtilities;
|
||||||
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
import org.thoughtcrime.securesms.mms.IncomingMediaMessage;
|
||||||
import org.thoughtcrime.securesms.mms.MmsException;
|
import org.thoughtcrime.securesms.mms.MmsException;
|
||||||
@ -584,9 +585,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
masterAddress = getMessageMasterDestination(content.getSender()).getAddress();
|
masterAddress = getMessageMasterDestination(content.getSender()).getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle sync message from ourselves
|
||||||
if (syncTarget != null && !syncTarget.isEmpty()) {
|
if (syncTarget != null && !syncTarget.isEmpty()) {
|
||||||
List<Attachment> attachments = PointerAttachment.forPointers(message.getAttachments());
|
List<Attachment> attachments = PointerAttachment.forPointers(message.getAttachments());
|
||||||
|
|
||||||
|
Address targetAddress = Address.fromSerialized(syncTarget);
|
||||||
|
|
||||||
OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(masterRecipient, message.getBody().orNull(),
|
OutgoingMediaMessage mediaMessage = new OutgoingMediaMessage(masterRecipient, message.getBody().orNull(),
|
||||||
attachments,
|
attachments,
|
||||||
message.getTimestamp(), -1,
|
message.getTimestamp(), -1,
|
||||||
@ -596,6 +600,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
linkPreviews.or(Collections.emptyList()),
|
linkPreviews.or(Collections.emptyList()),
|
||||||
Collections.emptyList(), Collections.emptyList());
|
Collections.emptyList(), Collections.emptyList());
|
||||||
|
|
||||||
|
if (DatabaseFactory.getMmsSmsDatabase(context).getMessageFor(message.getTimestamp(), targetAddress) != null) {
|
||||||
|
Log.d("Loki","Message already exists, don't insert again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
||||||
database.beginTransaction();
|
database.beginTransaction();
|
||||||
|
|
||||||
@ -607,11 +616,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
Optional<InsertResult> insertResult;
|
Optional<InsertResult> insertResult;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (message.isGroupMessage()) {
|
|
||||||
insertResult = database.insertSecureDecryptedMessageOutbox(mediaMessage, -1, content.getTimestamp());
|
// Check if we have the thread already
|
||||||
} else {
|
long threadID = DatabaseFactory.getLokiThreadDatabase(context).getThreadID(syncTarget);
|
||||||
insertResult = database.insertSecureDecryptedMessageOutbox(mediaMessage, -1);
|
|
||||||
}
|
insertResult = database.insertSecureDecryptedMessageOutbox(mediaMessage, threadID, content.getTimestamp());
|
||||||
|
|
||||||
if (insertResult.isPresent()) {
|
if (insertResult.isPresent()) {
|
||||||
List<DatabaseAttachment> allAttachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
|
List<DatabaseAttachment> allAttachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());
|
||||||
@ -837,6 +846,11 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
|||||||
} else if (syncTarget != null && !syncTarget.isEmpty()) {
|
} else if (syncTarget != null && !syncTarget.isEmpty()) {
|
||||||
Address targetAddress = Address.fromSerialized(syncTarget);
|
Address targetAddress = Address.fromSerialized(syncTarget);
|
||||||
|
|
||||||
|
if (DatabaseFactory.getMmsSmsDatabase(context).getMessageFor(message.getTimestamp(), targetAddress) != null) {
|
||||||
|
Log.d("Loki","Message already exists, don't insert again");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
OutgoingTextMessage tm = new OutgoingTextMessage(Recipient.from(context, targetAddress, false),
|
OutgoingTextMessage tm = new OutgoingTextMessage(Recipient.from(context, targetAddress, false),
|
||||||
body, message.getExpiresInSeconds(), -1);
|
body, message.getExpiresInSeconds(), -1);
|
||||||
|
|
||||||
|
@ -326,7 +326,7 @@ public class SingleRecipientNotificationBuilder extends AbstractNotificationBuil
|
|||||||
|
|
||||||
private static Drawable getPlaceholderDrawable(Context context, Recipient recipient) {
|
private static Drawable getPlaceholderDrawable(Context context, Recipient recipient) {
|
||||||
String publicKey = recipient.getAddress().serialize();
|
String publicKey = recipient.getAddress().serialize();
|
||||||
String hepk = (recipient.isLocalNumber() && publicKey != null)
|
String hepk = (recipient.isLocalNumber() && publicKey == null)
|
||||||
? TextSecurePreferences.getMasterHexEncodedPublicKey(context)
|
? TextSecurePreferences.getMasterHexEncodedPublicKey(context)
|
||||||
: publicKey;
|
: publicKey;
|
||||||
String displayName = recipient.getName();
|
String displayName = recipient.getName();
|
||||||
|
@ -65,19 +65,20 @@ object DownloadUtilities {
|
|||||||
Log.d("Loki", "Attachment size limit exceeded.")
|
Log.d("Loki", "Attachment size limit exceeded.")
|
||||||
throw PushNetworkException("Max response size exceeded.")
|
throw PushNetworkException("Max response size exceeded.")
|
||||||
}
|
}
|
||||||
val input = body.inputStream()
|
body.inputStream().use { input ->
|
||||||
val buffer = ByteArray(32768)
|
val buffer = ByteArray(32768)
|
||||||
var count = 0
|
var count = 0
|
||||||
var bytes = input.read(buffer)
|
var bytes = input.read(buffer)
|
||||||
while (bytes >= 0) {
|
while (bytes >= 0) {
|
||||||
outputStream.write(buffer, 0, bytes)
|
outputStream.write(buffer, 0, bytes)
|
||||||
count += bytes
|
count += bytes
|
||||||
if (count > maxSize) {
|
if (count > maxSize) {
|
||||||
Log.d("Loki", "Attachment size limit exceeded.")
|
Log.d("Loki", "Attachment size limit exceeded.")
|
||||||
throw PushNetworkException("Max response size exceeded.")
|
throw PushNetworkException("Max response size exceeded.")
|
||||||
|
}
|
||||||
|
listener?.onAttachmentProgress(body.size.toLong(), count.toLong())
|
||||||
|
bytes = input.read(buffer)
|
||||||
}
|
}
|
||||||
listener?.onAttachmentProgress(body.size.toLong(), count.toLong())
|
|
||||||
bytes = input.read(buffer)
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.d("Loki", "Couldn't download attachment due to error: $e.")
|
Log.d("Loki", "Couldn't download attachment due to error: $e.")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user