mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
Prevent SendJobs from sending already-sent messages.
This is to guard against behavior WorkManager has where it may re-enqueue a job that has already been completed (if, for instance, it was preempted). Fixes #8268
This commit is contained in:
parent
a7e15dc21e
commit
d93bfbf693
@ -1053,6 +1053,17 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSent(long messageId) {
|
||||
SQLiteDatabase database = databaseHelper.getReadableDatabase();
|
||||
try (Cursor cursor = database.query(TABLE_NAME, new String[] { MESSAGE_BOX }, ID + " = ?", new String[] { String.valueOf(messageId)}, null, null, null)) {
|
||||
if (cursor != null && cursor.moveToNext()) {
|
||||
long type = cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX));
|
||||
return Types.isSentType(type);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*package*/ void deleteThreads(Set<Long> threadIds) {
|
||||
SQLiteDatabase db = databaseHelper.getWritableDatabase();
|
||||
String where = "";
|
||||
|
@ -117,6 +117,10 @@ public interface MmsSmsColumns {
|
||||
(type & BASE_TYPE_MASK) == BASE_SENDING_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isSentType(long type) {
|
||||
return (type & BASE_TYPE_MASK) == BASE_SENT_TYPE;
|
||||
}
|
||||
|
||||
public static boolean isPendingSmsFallbackType(long type) {
|
||||
return (type & BASE_TYPE_MASK) == BASE_PENDING_INSECURE_SMS_FALLBACK ||
|
||||
(type & BASE_TYPE_MASK) == BASE_PENDING_SECURE_SMS_FALLBACK;
|
||||
|
@ -92,6 +92,11 @@ public class MmsSendJob extends SendJob {
|
||||
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
||||
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
||||
|
||||
if (database.isSent(messageId)) {
|
||||
Log.w(TAG, "Message " + messageId + " was already sent. Ignoring.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.i(TAG, "Sending message: " + messageId);
|
||||
|
||||
|
@ -114,6 +114,11 @@ public class PushGroupSendJob extends PushSendJob implements InjectableType {
|
||||
List<NetworkFailure> existingNetworkFailures = message.getNetworkFailures();
|
||||
List<IdentityKeyMismatch> existingIdentityMismatches = message.getIdentityKeyMismatches();
|
||||
|
||||
if (database.isSent(messageId)) {
|
||||
Log.w(TAG, "Message " + messageId + " was already sent. Ignoring.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.i(TAG, "Sending message: " + messageId);
|
||||
|
||||
|
@ -85,6 +85,11 @@ public class PushMediaSendJob extends PushSendJob implements InjectableType {
|
||||
MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
|
||||
OutgoingMediaMessage message = database.getOutgoingMessage(messageId);
|
||||
|
||||
if (database.isSent(messageId)) {
|
||||
Log.w(TAG, "Message " + messageId + " was already sent. Ignoring.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.i(TAG, "Sending message: " + messageId);
|
||||
|
||||
|
@ -78,6 +78,11 @@ public class PushTextSendJob extends PushSendJob implements InjectableType {
|
||||
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
||||
SmsMessageRecord record = database.getMessage(messageId);
|
||||
|
||||
if (!record.isPending() && !record.isFailed()) {
|
||||
Log.w(TAG, "Message " + messageId + " was already sent. Ignoring.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.i(TAG, "Sending message: " + messageId);
|
||||
|
||||
|
@ -90,6 +90,11 @@ public class SmsSendJob extends SendJob {
|
||||
SmsDatabase database = DatabaseFactory.getSmsDatabase(context);
|
||||
SmsMessageRecord record = database.getMessage(messageId);
|
||||
|
||||
if (!record.isPending() && !record.isFailed()) {
|
||||
Log.w(TAG, "Message " + messageId + " was already sent. Ignoring.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.i(TAG, "Sending message: " + messageId + " (attempt " + runAttempt + ")");
|
||||
deliver(record);
|
||||
|
Loading…
Reference in New Issue
Block a user