[SES-2968] [SES-2929] - Fix up misc kicked and re-invited message syncing issues (#842)

* Misc changes to handle reinvited scenario

* Update app/src/main/java/org/thoughtcrime/securesms/groups/GroupManagerV2Impl.kt

Co-authored-by: AL-Session <160798022+AL-Session@users.noreply.github.com>

---------

Co-authored-by: AL-Session <160798022+AL-Session@users.noreply.github.com>
pull/1710/head
SessionHero01 5 months ago committed by GitHub
parent e4dbca1a80
commit ac4124d69d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -319,7 +319,7 @@ class ConfigToDatabaseSync @Inject constructor(
groupThreadsToKeep[closedGroup.groupAccountId] = threadId groupThreadsToKeep[closedGroup.groupAccountId] = threadId
storage.setPinned(threadId, closedGroup.priority == PRIORITY_PINNED) storage.setPinned(threadId, closedGroup.priority == PRIORITY_PINNED)
if (!closedGroup.invited) { if (!closedGroup.invited && !closedGroup.kicked) {
pollerFactory.pollerFor(closedGroup.groupAccountId)?.start() pollerFactory.pollerFor(closedGroup.groupAccountId)?.start()
} }

@ -271,7 +271,15 @@ class ConfigFactory @Inject constructor(
it.convoInfoVolatile.eraseClosedGroup(groupId.hexString) it.convoInfoVolatile.eraseClosedGroup(groupId.hexString)
} }
deleteGroupConfigs(groupId)
}
override fun deleteGroupConfigs(groupId: AccountId) {
configDatabase.deleteGroupConfigs(groupId) configDatabase.deleteGroupConfigs(groupId)
synchronized(groupConfigs) {
groupConfigs.remove(groupId)
}
} }
override fun decryptForUser( override fun decryptForUser(

@ -8,6 +8,7 @@ import org.session.libsession.database.StorageProtocol
import org.session.libsession.messaging.groups.GroupManagerV2 import org.session.libsession.messaging.groups.GroupManagerV2
import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPoller import org.session.libsession.messaging.sending_receiving.pollers.ClosedGroupPoller
import org.session.libsession.snode.SnodeClock import org.session.libsession.snode.SnodeClock
import org.session.libsession.utilities.getGroup
import org.session.libsignal.database.LokiAPIDatabaseProtocol import org.session.libsignal.database.LokiAPIDatabaseProtocol
import org.session.libsignal.utilities.AccountId import org.session.libsignal.utilities.AccountId
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@ -26,9 +27,7 @@ class PollerFactory(
fun pollerFor(sessionId: AccountId): ClosedGroupPoller? { fun pollerFor(sessionId: AccountId): ClosedGroupPoller? {
// Check if the group is currently in our config and approved, don't start if it isn't // Check if the group is currently in our config and approved, don't start if it isn't
val invited = configFactory.withUserConfigs { val invited = configFactory.getGroup(sessionId)?.invited
it.userGroups.getClosedGroup(sessionId.hexString)?.invited
}
if (invited != false) return null if (invited != false) return null

@ -62,6 +62,7 @@ import org.thoughtcrime.securesms.database.MmsSmsDatabase
import org.thoughtcrime.securesms.database.ThreadDatabase import org.thoughtcrime.securesms.database.ThreadDatabase
import org.thoughtcrime.securesms.dependencies.ConfigFactory import org.thoughtcrime.securesms.dependencies.ConfigFactory
import org.thoughtcrime.securesms.dependencies.PollerFactory import org.thoughtcrime.securesms.dependencies.PollerFactory
import org.thoughtcrime.securesms.util.SessionMetaProtocol
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -790,6 +791,10 @@ class GroupManagerV2Impl @Inject constructor(
approveGroupInvite(closedGroupInfo, inviteMessageHash) approveGroupInvite(closedGroupInfo, inviteMessageHash)
} else { } else {
lokiDatabase.addGroupInviteReferrer(groupThreadId, inviter.hexString, inviteMessageHash) lokiDatabase.addGroupInviteReferrer(groupThreadId, inviter.hexString, inviteMessageHash)
// Clear existing message in the thread whenever we receive an invitation that we can't
// auto approve
storage.clearMessages(groupThreadId)
// In most cases, when we receive invitation, the thread has just been created, // In most cases, when we receive invitation, the thread has just been created,
// and "has_sent" is set to false. But there are cases that we could be "re-invited" // and "has_sent" is set to false. But there are cases that we could be "re-invited"
// to a group, where we need to go through approval process again. // to a group, where we need to go through approval process again.
@ -865,6 +870,11 @@ class GroupManagerV2Impl @Inject constructor(
storage.clearMessages(threadId) storage.clearMessages(threadId)
} }
// Clear all polling states
lokiAPIDatabase.clearLastMessageHashes(groupId.hexString)
lokiAPIDatabase.clearReceivedMessageHashValues(groupId.hexString)
SessionMetaProtocol.clearReceivedMessages()
// Insert a message to indicate we were kicked // Insert a message to indicate we were kicked
storage.insertIncomingInfoMessage( storage.insertIncomingInfoMessage(
context = application, context = application,
@ -876,6 +886,8 @@ class GroupManagerV2Impl @Inject constructor(
admins = emptyList(), admins = emptyList(),
sentTimestamp = clock.currentTimeMills(), sentTimestamp = clock.currentTimeMills(),
) )
configFactory.deleteGroupConfigs(groupId)
} }
override suspend fun setName(groupId: AccountId, newName: String): Unit = override suspend fun setName(groupId: AccountId, newName: String): Unit =

@ -182,15 +182,19 @@ class ClosedGroupPoller(
} }
val groupMessageRetrieval = async { val groupMessageRetrieval = async {
val lastHash = lokiApiDatabase.getLastMessageHashValue(
snode,
closedGroupSessionId.hexString,
Namespace.CLOSED_GROUP_MESSAGES()
).orEmpty()
Log.d(TAG, "Retrieving group message since lastHash = $lastHash")
SnodeAPI.sendBatchRequest( SnodeAPI.sendBatchRequest(
snode = snode, snode = snode,
publicKey = closedGroupSessionId.hexString, publicKey = closedGroupSessionId.hexString,
request = SnodeAPI.buildAuthenticatedRetrieveBatchRequest( request = SnodeAPI.buildAuthenticatedRetrieveBatchRequest(
lastHash = lokiApiDatabase.getLastMessageHashValue( lastHash = lastHash,
snode,
closedGroupSessionId.hexString,
Namespace.CLOSED_GROUP_MESSAGES()
).orEmpty(),
auth = groupAuth, auth = groupAuth,
namespace = Namespace.CLOSED_GROUP_MESSAGES(), namespace = Namespace.CLOSED_GROUP_MESSAGES(),
maxSize = null, maxSize = null,

@ -75,6 +75,8 @@ interface ConfigFactoryProtocol {
keysPush: ConfigPushResult? keysPush: ConfigPushResult?
) )
fun deleteGroupConfigs(groupId: AccountId)
} }
class ConfigMessage( class ConfigMessage(

Loading…
Cancel
Save