Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class JobQueue @Inject constructor(
for (job in channel) {
if (!isActive) break
val communityAddress = when (job) {
is OpenGroupDeleteJob -> job.address?.address
is TrimThreadJob -> job.communityAddress?.address
else -> null
}
Expand Down Expand Up @@ -131,9 +130,6 @@ class JobQueue @Inject constructor(
is AttachmentDownloadJob -> {
mediaQueue.send(job)
}
is OpenGroupDeleteJob -> {
openGroupQueue.send(job)
}
is TrimThreadJob -> {
if (job.communityAddress != null) {
openGroupQueue.send(job)
Expand Down Expand Up @@ -217,7 +213,6 @@ class JobQueue @Inject constructor(
AttachmentUploadJob.KEY,
AttachmentDownloadJob.KEY,
MessageSendJob.KEY,
OpenGroupDeleteJob.KEY,
InviteContactsJob.KEY,
)
allJobTypes.forEach { type ->
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class SessionJobManagerFactories @Inject constructor(
private val attachmentUploadJobFactory: AttachmentUploadJob.Factory,
private val trimThreadFactory: TrimThreadJob.Factory,
private val messageSendJobFactory: MessageSendJob.Factory,
private val deleteJobFactory: OpenGroupDeleteJob.Factory,
private val inviteContactsJobFactory: InviteContactsJob.Factory,
) {

Expand All @@ -17,7 +16,6 @@ class SessionJobManagerFactories @Inject constructor(
AttachmentUploadJob.KEY to attachmentUploadJobFactory,
MessageSendJob.KEY to messageSendJobFactory,
TrimThreadJob.KEY to trimThreadFactory,
OpenGroupDeleteJob.KEY to deleteJobFactory,
InviteContactsJob.KEY to inviteContactsJobFactory,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import kotlinx.coroutines.supervisorScope
import kotlinx.coroutines.sync.Semaphore
import kotlinx.coroutines.sync.withPermit
import kotlinx.serialization.json.Json
import org.session.libsession.database.MessageDataProvider
import org.session.libsession.database.StorageProtocol
import org.session.libsession.messaging.jobs.JobQueue
import org.session.libsession.messaging.jobs.OpenGroupDeleteJob
import org.session.libsession.messaging.jobs.TrimThreadJob
import org.session.libsession.messaging.open_groups.OpenGroupApi
import org.session.libsession.messaging.open_groups.OpenGroupApi.Capability
Expand Down Expand Up @@ -46,13 +46,13 @@ class OpenGroupPoller @AssistedInject constructor(
private val storage: StorageProtocol,
private val configFactory: ConfigFactoryProtocol,
private val trimThreadJobFactory: TrimThreadJob.Factory,
private val openGroupDeleteJobFactory: OpenGroupDeleteJob.Factory,
private val communityDatabase: CommunityDatabase,
private val receivedMessageProcessor: ReceivedMessageProcessor,
private val communityApiExecutor: CommunityApiExecutor,
private val getRoomMessagesFactory: GetRoomMessagesApi.Factory,
private val getDirectMessageFactory: GetDirectMessagesApi.Factory,
private val pollRoomInfoFactory: PollRoomApi.Factory,
private val messageDataProvider: MessageDataProvider,
private val getCapsApi: Provider<GetCapsApi>,
networkConnectivity: NetworkConnectivity,
appVisibilityManager: AppVisibilityManager,
Expand Down Expand Up @@ -254,12 +254,23 @@ class OpenGroupPoller @AssistedInject constructor(
}

if (deletions.isNotEmpty()) {
jobQueue.get().add(
openGroupDeleteJobFactory.create(
messageServerIds = LongArray(deletions.size) { i -> deletions[i].id },
threadId = threadId
)
)
try {
val (smsMessages, mmsMessages) = messageDataProvider.getMessageIDs(deletions.map { it.id }, threadId)

// Delete the SMS messages
if (smsMessages.isNotEmpty()) {
messageDataProvider.deleteMessages(smsMessages, true)
}

// Delete the MMS messages
if (mmsMessages.isNotEmpty()) {
messageDataProvider.deleteMessages(mmsMessages, false)
}
} catch (e: Exception) {
logE("Error deleting open group messages", e)
} finally {
storage.setLastMessageServerID(roomToken, server, deletions.maxOf { it.seqno })
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class LokiAPIDatabase(context: Context, helper: Provider<SQLCipherOpenHelper>) :
@JvmStatic val createOpenGroupAuthTokenTableCommand = "CREATE TABLE $openGroupAuthTokenTable ($server TEXT PRIMARY KEY, $token TEXT);"
// Last message server IDs
private const val lastMessageServerIDTable = "loki_api_last_message_server_id_cache"
private val lastMessageServerIDTableIndex = "loki_api_last_message_server_id_cache_index"
private const val lastMessageServerIDTableIndex = "loki_api_last_message_server_id_cache_index"
private const val lastMessageServerID = "last_message_server_id"
@JvmStatic val createLastMessageServerIDTableCommand = "CREATE TABLE $lastMessageServerIDTable ($lastMessageServerIDTableIndex STRING PRIMARY KEY, $lastMessageServerID INTEGER DEFAULT 0);"
// Last deletion server IDs
Expand Down Expand Up @@ -293,11 +293,17 @@ class LokiAPIDatabase(context: Context, helper: Provider<SQLCipherOpenHelper>) :
}?.toLong()
}

/**
* Attempts to set the last message server ID for the given room and server, but
* only if the new value is more recent than the previous value.
*/
override fun setLastMessageServerID(room: String, server: String, newValue: Long) {
val database = writableDatabase
val index = "$server.$room"
val row = wrap(mapOf( lastMessageServerIDTableIndex to index, lastMessageServerID to newValue.toString() ))
database.insertOrUpdate(lastMessageServerIDTable, row, "$lastMessageServerIDTableIndex = ?", wrap(index))
writableDatabase.execSQL("""
INSERT INTO $lastMessageServerIDTable ($lastMessageServerIDTableIndex, $lastMessageServerID)
VALUES (?1, ?2)
ON CONFLICT($lastMessageServerIDTableIndex) DO UPDATE SET $lastMessageServerID = EXCLUDED.$lastMessageServerID
WHERE EXCLUDED.$lastMessageServerID > $lastMessageServerID
""", arrayOf<Any>("$server.$room", newValue))
}

fun removeLastMessageServerID(room: String, server:String) {
Expand Down