diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java index 53ab9de4ed..dae7408bb9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -546,7 +546,7 @@ public class ConversationFragment extends Fragment .deleteMessages(serverIDs, publicChat.getChannel(), publicChat.getServer(), isSentByUser) .success(l -> { for (MessageRecord messageRecord : messageRecords) { - Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id, !messageRecord.isMms()); + Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id, !messageRecord.isMms()); if (l.contains(serverID)) { if (messageRecord.isMms()) { DatabaseFactory.getMmsDatabase(getActivity()).delete(messageRecord.getId()); @@ -569,7 +569,7 @@ public class ConversationFragment extends Fragment .deleteMessage(serverId, openGroupChat.getRoom(), openGroupChat.getServer()) .success(l -> { for (MessageRecord messageRecord : messageRecords) { - Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id, !messageRecord.isMms()); + Long serverID = DatabaseFactory.getLokiMessageDatabase(getContext()).getServerID(messageRecord.id, !messageRecord.isMms()); if (serverID != null && serverID.equals(serverId)) { MessagingModuleConfiguration.shared.getMessageDataProvider().deleteMessage(messageRecord.id, !messageRecord.isMms()); break; diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiMessageDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiMessageDatabase.kt index 85a66b159c..83dc565117 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiMessageDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiMessageDatabase.kt @@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.loki.database import android.content.ContentValues import android.content.Context +import net.sqlcipher.database.SQLiteDatabase.CONFLICT_REPLACE import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper @@ -98,11 +99,11 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab override fun setServerID(messageID: Long, serverID: Long, isSms: Boolean) { val database = databaseHelper.writableDatabase - val contentValues = ContentValues(2) + val contentValues = ContentValues(3) contentValues.put(Companion.messageID, messageID) contentValues.put(Companion.serverID, serverID) contentValues.put(messageType, if (isSms) SMS_TYPE else MMS_TYPE) - database.insertOrUpdate(messageIDTable, contentValues, "${Companion.messageID} = ? AND ${Companion.serverID} = ?", arrayOf(messageID.toString(), serverID.toString())) + database.insertWithOnConflict(messageIDTable, null, contentValues, CONFLICT_REPLACE) } fun getOriginalThreadID(messageID: Long): Long { @@ -114,11 +115,11 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab fun setOriginalThreadID(messageID: Long, serverID: Long, threadID: Long) { val database = databaseHelper.writableDatabase - val contentValues = ContentValues(2) + val contentValues = ContentValues(3) contentValues.put(Companion.messageID, messageID) contentValues.put(Companion.serverID, serverID) contentValues.put(Companion.threadID, threadID) - database.insertOrUpdate(messageThreadMappingTable, contentValues, "${Companion.messageID} = ? AND ${Companion.serverID} = ?", arrayOf(messageID.toString(), serverID.toString())) + database.insertWithOnConflict(messageThreadMappingTable, null, contentValues, CONFLICT_REPLACE) } fun getErrorMessage(messageID: Long): String? { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt index cf8c747638..66d7263747 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt @@ -35,11 +35,10 @@ object OpenGroupUtilities { val groupInfo = OpenGroupAPIV2.getInfo(room,server).get() val application = ApplicationContext.getInstance(context) - val group = application.publicChatManager.addChat(server, room, groupInfo, publicKey) - val storage = MessagingModuleConfiguration.shared.storage storage.removeLastDeletionServerId(room, server) storage.removeLastMessageServerId(room, server) + val group = application.publicChatManager.addChat(server, room, groupInfo, publicKey) return group } diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt index a2f47556bc..1fdf100a3f 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/JobQueue.kt @@ -130,12 +130,7 @@ class JobQueue : JobDelegate { } // Message send jobs waiting for the attachment to upload if (job is MessageSendJob && error is MessageSendJob.AwaitingAttachmentUploadException) { - val retryInterval: Long = 1000 * 4 Log.i("Loki", "Message send job waiting for attachment upload to finish.") - timer.schedule(delay = retryInterval) { - Log.i("Loki", "Retrying ${job::class.simpleName}.") - queue.offer(job) - } return } // Regular job failure diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt index be331891b0..c295e4e323 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/ReceivedMessageHandler.kt @@ -238,7 +238,8 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalS } val openGroupServerID = message.openGroupServerMessageID if (openGroupServerID != null) { - storage.setOpenGroupServerMessageID(messageID, openGroupServerID, threadID, !message.isMediaMessage()) + val isSms = !(message.isMediaMessage() || attachments.isNotEmpty()) + storage.setOpenGroupServerMessageID(messageID, openGroupServerID, threadID, isSms) } // Cancel any typing indicators if needed cancelTypingIndicatorsIfNeeded(message.sender!!) diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupV2Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupV2Poller.kt index 311e213592..cbbd599507 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupV2Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/OpenGroupV2Poller.kt @@ -73,8 +73,8 @@ class OpenGroupV2Poller(private val openGroups: List, private val e return OpenGroupAPIV2.getCompactPoll(rooms = rooms, server).successBackground { results -> results.forEach { (room, results) -> val serverRoomId = "$server.$room" - handleDeletedMessages(serverRoomId,results.deletions) handleNewMessages(serverRoomId, results.messages.sortedBy { it.serverID }, isBackgroundPoll) + handleDeletedMessages(serverRoomId,results.deletions) } }.always { isPollOngoing = false @@ -120,7 +120,11 @@ class OpenGroupV2Poller(private val openGroups: List, private val e val threadId = messagingModule.storage.getThreadIdFor(Address.fromSerialized(address)) ?: return val deletedMessageIDs = deletedMessageServerIDs.mapNotNull { serverId -> - messagingModule.messageDataProvider.getMessageID(serverId, threadId) + val id = messagingModule.messageDataProvider.getMessageID(serverId, threadId) + if (id == null) { + Log.d("Loki", "Couldn't find server ID $serverId") + } + id } deletedMessageIDs.forEach { (messageId, isSms) -> MessagingModuleConfiguration.shared.messageDataProvider.deleteMessage(messageId, isSms)