mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
[SES-567] Fixed a couple of issues where the Group poller would be stopped during creation
This commit is contained in:
parent
9b7fb3dd86
commit
2b7bd7417e
@ -738,6 +738,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
return mmsSmsDb.getConversationCount(threadID)
|
return mmsSmsDb.getConversationCount(threadID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun deleteConversation(threadId: Long) {
|
||||||
|
val threadDB = DatabaseComponent.get(context).threadDatabase()
|
||||||
|
threadDB.deleteConversation(threadId)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun getAttachmentDataUri(attachmentId: AttachmentId): Uri {
|
override fun getAttachmentDataUri(attachmentId: AttachmentId): Uri {
|
||||||
|
@ -159,6 +159,7 @@ interface StorageProtocol {
|
|||||||
fun trimThread(threadID: Long, threadLimit: Int)
|
fun trimThread(threadID: Long, threadLimit: Int)
|
||||||
fun trimThreadBefore(threadID: Long, timestamp: Long)
|
fun trimThreadBefore(threadID: Long, timestamp: Long)
|
||||||
fun getMessageCount(threadID: Long): Long
|
fun getMessageCount(threadID: Long): Long
|
||||||
|
fun deleteConversation(threadId: Long)
|
||||||
|
|
||||||
// Contacts
|
// Contacts
|
||||||
fun getContactWithSessionID(sessionID: String): Contact?
|
fun getContactWithSessionID(sessionID: String): Contact?
|
||||||
|
@ -52,19 +52,10 @@ fun MessageSender.create(name: String, members: Collection<String>): Promise<Str
|
|||||||
storage.createGroup(groupID, name, LinkedList(members.map { Address.fromSerialized(it) }),
|
storage.createGroup(groupID, name, LinkedList(members.map { Address.fromSerialized(it) }),
|
||||||
null, null, LinkedList(admins.map { Address.fromSerialized(it) }), SnodeAPI.nowWithOffset)
|
null, null, LinkedList(admins.map { Address.fromSerialized(it) }), SnodeAPI.nowWithOffset)
|
||||||
storage.setProfileSharing(Address.fromSerialized(groupID), true)
|
storage.setProfileSharing(Address.fromSerialized(groupID), true)
|
||||||
|
|
||||||
// Send a closed group update message to all members individually
|
// Send a closed group update message to all members individually
|
||||||
val closedGroupUpdateKind = ClosedGroupControlMessage.Kind.New(ByteString.copyFrom(Hex.fromStringCondensed(groupPublicKey)), name, encryptionKeyPair, membersAsData, adminsAsData, 0)
|
val closedGroupUpdateKind = ClosedGroupControlMessage.Kind.New(ByteString.copyFrom(Hex.fromStringCondensed(groupPublicKey)), name, encryptionKeyPair, membersAsData, adminsAsData, 0)
|
||||||
val sentTime = SnodeAPI.nowWithOffset
|
val sentTime = SnodeAPI.nowWithOffset
|
||||||
for (member in members) {
|
|
||||||
val closedGroupControlMessage = ClosedGroupControlMessage(closedGroupUpdateKind)
|
|
||||||
closedGroupControlMessage.sentTimestamp = sentTime
|
|
||||||
try {
|
|
||||||
sendNonDurably(closedGroupControlMessage, Address.fromSerialized(member)).get()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
deferred.reject(e)
|
|
||||||
return@queue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the group to the user's set of public keys to poll for
|
// Add the group to the user's set of public keys to poll for
|
||||||
storage.addClosedGroupPublicKey(groupPublicKey)
|
storage.addClosedGroupPublicKey(groupPublicKey)
|
||||||
@ -73,6 +64,24 @@ fun MessageSender.create(name: String, members: Collection<String>): Promise<Str
|
|||||||
// Notify the user
|
// Notify the user
|
||||||
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
val threadID = storage.getOrCreateThreadIdFor(Address.fromSerialized(groupID))
|
||||||
storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, threadID, sentTime)
|
storage.insertOutgoingInfoMessage(context, groupID, SignalServiceGroup.Type.CREATION, name, members, admins, threadID, sentTime)
|
||||||
|
|
||||||
|
for (member in members) {
|
||||||
|
val closedGroupControlMessage = ClosedGroupControlMessage(closedGroupUpdateKind)
|
||||||
|
closedGroupControlMessage.sentTimestamp = sentTime
|
||||||
|
try {
|
||||||
|
sendNonDurably(closedGroupControlMessage, Address.fromSerialized(member)).get()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// We failed to properly create the group so delete it's associated data (in the past
|
||||||
|
// we didn't create this data until the messages successfully sent but this resulted
|
||||||
|
// in race conditions due to the `NEW` message sent to our own swarm)
|
||||||
|
storage.removeClosedGroupPublicKey(groupPublicKey)
|
||||||
|
storage.removeAllClosedGroupEncryptionKeyPairs(groupPublicKey)
|
||||||
|
storage.deleteConversation(threadID)
|
||||||
|
deferred.reject(e)
|
||||||
|
return@queue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Notify the PN server
|
// Notify the PN server
|
||||||
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey)
|
PushNotificationAPI.performOperation(PushNotificationAPI.ClosedGroupOperation.Subscribe, groupPublicKey, userPublicKey)
|
||||||
// Start polling
|
// Start polling
|
||||||
|
@ -79,7 +79,12 @@ class ClosedGroupPollerV2 {
|
|||||||
// reasonable fake time interval to use instead.
|
// reasonable fake time interval to use instead.
|
||||||
val storage = MessagingModuleConfiguration.shared.storage
|
val storage = MessagingModuleConfiguration.shared.storage
|
||||||
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
val groupID = GroupUtil.doubleEncodeGroupID(groupPublicKey)
|
||||||
val threadID = storage.getThreadId(groupID) ?: return
|
val threadID = storage.getThreadId(groupID)
|
||||||
|
if (threadID == null) {
|
||||||
|
Log.d("Loki", "Stopping group poller due to missing thread for closed group: $groupPublicKey.")
|
||||||
|
stopPolling(groupPublicKey)
|
||||||
|
return
|
||||||
|
}
|
||||||
val lastUpdated = storage.getLastUpdated(threadID)
|
val lastUpdated = storage.getLastUpdated(threadID)
|
||||||
val timeSinceLastMessage = if (lastUpdated != -1L) Date().time - lastUpdated else 5 * 60 * 1000
|
val timeSinceLastMessage = if (lastUpdated != -1L) Date().time - lastUpdated else 5 * 60 * 1000
|
||||||
val minPollInterval = Companion.minPollInterval
|
val minPollInterval = Companion.minPollInterval
|
||||||
|
Loading…
Reference in New Issue
Block a user