fix: closed group creation sets thread date to formation timestamp

This commit is contained in:
0x330a 2023-06-26 11:15:36 +10:00
parent 6c70b38ab1
commit 71a3ce9e05
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
6 changed files with 55 additions and 24 deletions

View File

@ -595,6 +595,7 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, group.sessionId, localUserPublicKey) PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, group.sessionId, localUserPublicKey)
// Notify the user // Notify the user
val threadID = getOrCreateThreadIdFor(Address.fromSerialized(groupId)) 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) 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 // Don't create config group here, it's from a config update
// Start polling // Start polling
@ -1278,6 +1279,11 @@ open class Storage(context: Context, helper: SQLCipherOpenHelper, private val co
return threadDB.isPinned(threadID) 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) { override fun deleteConversation(threadID: Long) {
val recipient = getRecipientForThread(threadID) val recipient = getRecipientForThread(threadID)
val threadDB = DatabaseComponent.get(context).threadDatabase() val threadDB = DatabaseComponent.get(context).threadDatabase()

View File

@ -366,6 +366,14 @@ public class ThreadDatabase extends Database {
notifyConversationListListeners(); 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) { public int getDistributionType(long threadId) {
SQLiteDatabase db = databaseHelper.getReadableDatabase(); SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.query(TABLE_NAME, new String[]{TYPE}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null); Cursor cursor = db.query(TABLE_NAME, new String[]{TYPE}, ID_WHERE, new String[]{String.valueOf(threadId)}, null, null, null);

View File

@ -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 android.enableJetifier=true
org.gradle.jvmargs=-Xmx4g android.useAndroidX=true
appcompatVersion=1.6.1
gradlePluginVersion=7.3.1 coreVersion=1.8.0
googleServicesVersion=4.3.12
kotlinVersion=1.6.21
coroutinesVersion=1.6.4 coroutinesVersion=1.6.4
kotlinxJsonVersion=1.3.3 curve25519Version=0.6.0
lifecycleVersion=2.5.1
daggerVersion=2.40.1 daggerVersion=2.40.1
glideVersion=4.11.0 glideVersion=4.11.0
kovenantVersion=3.3.0 googleServicesVersion=4.3.12
curve25519Version=0.6.0 gradlePluginVersion=7.3.1
protobufVersion=2.5.0
okhttpVersion=3.12.1
jacksonDatabindVersion=2.9.8 jacksonDatabindVersion=2.9.8
appcompatVersion=1.6.1
materialVersion=1.8.0
preferenceVersion=1.2.0
coreVersion=1.8.0
junitVersion=4.13.2 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 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 testCoreVersion=1.5.0
pagingVersion=3.0.0

View File

@ -174,6 +174,7 @@ interface StorageProtocol {
fun setPinned(threadID: Long, isPinned: Boolean) fun setPinned(threadID: Long, isPinned: Boolean)
fun isPinned(threadID: Long): Boolean fun isPinned(threadID: Long): Boolean
fun deleteConversation(threadID: Long) fun deleteConversation(threadID: Long)
fun setThreadDate(threadId: Long, newDate: Long)
// Contacts // Contacts
fun getContactWithSessionID(sessionID: String): Contact? fun getContactWithSessionID(sessionID: String): Contact?

View File

@ -6,7 +6,6 @@ import org.session.libsession.avatars.AvatarHelper
import org.session.libsession.messaging.MessagingModuleConfiguration import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.jobs.BackgroundGroupAddJob import org.session.libsession.messaging.jobs.BackgroundGroupAddJob
import org.session.libsession.messaging.jobs.JobQueue 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.Message
import org.session.libsession.messaging.messages.control.CallMessage import org.session.libsession.messaging.messages.control.CallMessage
import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
@ -559,7 +558,8 @@ private fun handleNewClosedGroup(sender: String, sentTimestamp: Long, groupPubli
// Notify the PN server // Notify the PN server
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey) PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey)
// Create thread // Create thread
storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID)) val threadId = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
storage.setThreadDate(threadId, formationTimestamp)
// Start polling // Start polling
ClosedGroupPollerV2.shared.startPolling(groupPublicKey) ClosedGroupPollerV2.shared.startPolling(groupPublicKey)
} }

View File

@ -1,10 +1,8 @@
package org.session.libsession.messaging.sending_receiving.pollers package org.session.libsession.messaging.sending_receiving.pollers
import android.util.SparseArray import android.util.SparseArray
import androidx.core.util.keyIterator
import androidx.core.util.valueIterator import androidx.core.util.valueIterator
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import network.loki.messenger.libsession_util.ConfigBase import network.loki.messenger.libsession_util.ConfigBase
import network.loki.messenger.libsession_util.Contacts 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.SnodeAPI
import org.session.libsession.snode.SnodeModule import org.session.libsession.snode.SnodeModule
import org.session.libsession.utilities.ConfigFactoryProtocol import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.WindowDebouncer
import org.session.libsignal.utilities.Log import org.session.libsignal.utilities.Log
import org.session.libsignal.utilities.Namespace import org.session.libsignal.utilities.Namespace
import org.session.libsignal.utilities.Snode 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 // 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 // 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 // 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 -> responseList.getOrNull(requestIndex)?.let { rawResponse ->
if (rawResponse["code"] as? Int != 200) { if (rawResponse["code"] as? Int != 200) {
Log.e("Loki", "Batch sub-request had non-200 response code, returned code ${(rawResponse["code"] as? Int) ?: "[unknown]"}") Log.e("Loki", "Batch sub-request had non-200 response code, returned code ${(rawResponse["code"] as? Int) ?: "[unknown]"}")