From 71a3ce9e05ee1b3e64c30b79256de3022562e90c Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Mon, 26 Jun 2023 11:15:36 +1000 Subject: [PATCH] fix: closed group creation sets thread date to formation timestamp --- .../securesms/database/Storage.kt | 6 +++ .../securesms/database/ThreadDatabase.java | 8 ++++ gradle.properties | 48 ++++++++++++------- .../libsession/database/StorageProtocol.kt | 1 + .../ReceivedMessageHandler.kt | 4 +- .../sending_receiving/pollers/Poller.kt | 12 +++-- 6 files changed, 55 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt index cb81991ddd..9a47f362c5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt @@ -595,6 +595,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, group.sessionId, localUserPublicKey) // Notify the user val threadID = getOrCreateThreadIdFor(Address.fromSerialized(groupId)) + threadDb.setDate(threadID, formationTimestamp) insertOutgoingInfoMessage(context, groupId, SignalServiceGroup.Type.CREATION, title, members.map { it.serialize() }, admins.map { it.serialize() }, threadID, formationTimestamp) // Don't create config group here, it's from a config update // Start polling @@ -1278,6 +1279,11 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co return threadDB.isPinned(threadID) } + override fun setThreadDate(threadId: Long, newDate: Long) { + val threadDb = DatabaseComponent.get(context).threadDatabase() + threadDb.setDate(threadId, newDate) + } + override fun deleteConversation(threadID: Long) { val recipient = getRecipientForThread(threadID) val threadDB = DatabaseComponent.get(context).threadDatabase() diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java index 68b496fb5e..3737f52a46 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -366,6 +366,14 @@ public class ThreadDatabase extends Database { notifyConversationListListeners(); } + public void setDate(long threadId, long date) { + ContentValues contentValues = new ContentValues(1); + contentValues.put(DATE, date); + SQLiteDatabase db = databaseHelper.getWritableDatabase(); + int updated = db.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {threadId+""}); + if (updated > 0) notifyConversationListListeners(); + } + public int getDistributionType(long threadId) { SQLiteDatabase db = databaseHelper.getReadableDatabase(); Cursor cursor = db.query(TABLE_NAME, new String[]{TYPE}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null); diff --git a/gradle.properties b/gradle.properties index 2f7c70b81f..d8551a8c04 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,26 +1,38 @@ -android.useAndroidX=true +## For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx1024m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +# +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +#Mon Jun 26 09:56:43 AEST 2023 android.enableJetifier=true -org.gradle.jvmargs=-Xmx4g - -gradlePluginVersion=7.3.1 -googleServicesVersion=4.3.12 -kotlinVersion=1.6.21 +android.useAndroidX=true +appcompatVersion=1.6.1 +coreVersion=1.8.0 coroutinesVersion=1.6.4 -kotlinxJsonVersion=1.3.3 -lifecycleVersion=2.5.1 +curve25519Version=0.6.0 daggerVersion=2.40.1 glideVersion=4.11.0 -kovenantVersion=3.3.0 -curve25519Version=0.6.0 -protobufVersion=2.5.0 -okhttpVersion=3.12.1 +googleServicesVersion=4.3.12 +gradlePluginVersion=7.3.1 jacksonDatabindVersion=2.9.8 -appcompatVersion=1.6.1 -materialVersion=1.8.0 -preferenceVersion=1.2.0 -coreVersion=1.8.0 - junitVersion=4.13.2 +kotlinVersion=1.6.21 +kotlinxJsonVersion=1.3.3 +kovenantVersion=3.3.0 +lifecycleVersion=2.5.1 +materialVersion=1.8.0 mockitoKotlinVersion=4.1.0 +okhttpVersion=3.12.1 +org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" +org.gradle.unsafe.configuration-cache=true +pagingVersion=3.0.0 +preferenceVersion=1.2.0 +protobufVersion=2.5.0 testCoreVersion=1.5.0 -pagingVersion=3.0.0 \ No newline at end of file diff --git a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt index aad6bc5674..8e2a05dc81 100644 --- a/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt +++ b/libsession/src/main/java/org/session/libsession/database/StorageProtocol.kt @@ -174,6 +174,7 @@ interface StorageProtocol { fun setPinned(threadID: Long, isPinned: Boolean) fun isPinned(threadID: Long): Boolean fun deleteConversation(threadID: Long) + fun setThreadDate(threadId: Long, newDate: Long) // Contacts fun getContactWithSessionID(sessionID: String): Contact? 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 76563a986b..19278aadde 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 @@ -6,7 +6,6 @@ import org.session.libsession.avatars.AvatarHelper import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.jobs.BackgroundGroupAddJob import org.session.libsession.messaging.jobs.JobQueue -import org.session.libsession.messaging.jobs.RetrieveProfileAvatarJob import org.session.libsession.messaging.messages.Message import org.session.libsession.messaging.messages.control.CallMessage import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage @@ -559,7 +558,8 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli // Notify the PN server PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey) // Create thread - storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID)) + val threadId = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID)) + storage.setThreadDate(threadId, formationTimestamp) // Start polling ClosedGroupPollerV2.shared.startPolling(groupPublicKey) } diff --git a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt index 41145992cb..f0b20436fc 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/sending_receiving/pollers/Poller.kt @@ -1,10 +1,8 @@ package org.session.libsession.messaging.sending_receiving.pollers import android.util.SparseArray -import androidx.core.util.keyIterator import androidx.core.util.valueIterator import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job import kotlinx.coroutines.runBlocking import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.Contacts @@ -27,7 +25,6 @@ import org.session.libsession.snode.RawResponse import org.session.libsession.snode.SnodeAPI import org.session.libsession.snode.SnodeModule import org.session.libsession.utilities.ConfigFactoryProtocol -import org.session.libsession.utilities.WindowDebouncer import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Namespace import org.session.libsignal.utilities.Snode @@ -214,7 +211,14 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti // in case we had null configs, the array won't be fully populated // index of the sparse array key iterator should be the request index, with the key being the namespace // TODO: add in specific ordering of config namespaces for processing - requestSparseArray.keyIterator().withIndex().forEach { (requestIndex, key) -> + listOfNotNull( + configFactory.user?.configNamespace(), + configFactory.contacts?.configNamespace(), + configFactory.userGroups?.configNamespace(), + configFactory.convoVolatile?.configNamespace() + ).map { + it to requestSparseArray.indexOfKey(it) + }.filter { (_, i) -> i >= 0 }.forEach { (key, requestIndex) -> responseList.getOrNull(requestIndex)?.let { rawResponse -> if (rawResponse["code"] as? Int != 200) { Log.e("Loki", "Batch sub-request had non-200 response code, returned code ${(rawResponse["code"] as? Int) ?: "[unknown]"}")