Incorrect timestamp

This commit is contained in:
SessionHero01 2024-10-04 11:08:05 +10:00
parent 02df41e848
commit 80344f0ffd
No known key found for this signature in database
4 changed files with 39 additions and 38 deletions

View File

@ -16,7 +16,6 @@ import network.loki.messenger.libsession_util.util.INVITE_STATUS_SENT
import network.loki.messenger.libsession_util.util.UserPic import network.loki.messenger.libsession_util.util.UserPic
import org.session.libsession.database.StorageProtocol import org.session.libsession.database.StorageProtocol
import org.session.libsession.database.userAuth import org.session.libsession.database.userAuth
import org.session.libsession.messaging.MessagingModuleConfiguration
import org.session.libsession.messaging.contacts.Contact import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.messaging.groups.GroupManagerV2 import org.session.libsession.messaging.groups.GroupManagerV2
import org.session.libsession.messaging.jobs.InviteContactsJob import org.session.libsession.messaging.jobs.InviteContactsJob
@ -282,7 +281,8 @@ class GroupManagerV2Impl @Inject constructor(
) )
.build() .build()
).apply { this.sentTimestamp = timestamp } ).apply { this.sentTimestamp = timestamp }
MessageSender.send(updatedMessage, Address.fromSerialized(group.hexString)) MessageSender.send(updatedMessage, Destination.ClosedGroup(group.hexString), false).await()
storage.insertGroupInfoChange(updatedMessage, group)
} }
override suspend fun removeMembers( override suspend fun removeMembers(
@ -461,11 +461,13 @@ class GroupManagerV2Impl @Inject constructor(
sentTimestamp = timestamp sentTimestamp = timestamp
} }
MessageSender.send(message, Address.fromSerialized(group.hexString)) MessageSender.send(message, Destination.ClosedGroup(group.hexString), false).await()
storage.insertGroupInfoChange(message, group)
} }
private suspend fun flagMembersForRemoval( private suspend fun flagMembersForRemoval(
group: AccountId, members: List<AccountId>, group: AccountId,
members: List<AccountId>,
alsoRemoveMembersMessage: Boolean, alsoRemoveMembersMessage: Boolean,
sendMemberChangeMessage: Boolean sendMemberChangeMessage: Boolean
) { ) {
@ -505,6 +507,7 @@ class GroupManagerV2Impl @Inject constructor(
).apply { sentTimestamp = timestamp } ).apply { sentTimestamp = timestamp }
MessageSender.send(message, Destination.ClosedGroup(group.hexString), false).await() MessageSender.send(message, Destination.ClosedGroup(group.hexString), false).await()
storage.insertGroupInfoChange(message, group)
} }
} }
@ -576,28 +579,21 @@ class GroupManagerV2Impl @Inject constructor(
groupName: String, groupName: String,
authData: ByteArray, authData: ByteArray,
inviter: AccountId, inviter: AccountId,
inviteMessageHash: String? inviteMessageHash: String,
) = withContext(dispatcher) { inviteMessageTimestamp: Long,
): Unit = withContext(dispatcher) {
handleInvitation( handleInvitation(
groupId = groupId, groupId = groupId,
groupName = groupName, groupName = groupName,
authDataOrAdminKey = authData, authDataOrAdminKey = authData,
fromPromotion = false, fromPromotion = false,
inviter = inviter inviter = inviter,
inviteMessageTimestamp = inviteMessageTimestamp,
) )
// Delete the invite message remotely // Once we are done, delete the invite message remotely
if (inviteMessageHash != null) {
val auth = requireNotNull(storage.userAuth) { "No current user available" } val auth = requireNotNull(storage.userAuth) { "No current user available" }
SnodeAPI.sendBatchRequest( SnodeAPI.deleteMessage(groupId.hexString, auth, listOf(inviteMessageHash))
snode = SnodeAPI.getSingleTargetSnode(groupId.hexString).await(),
publicKey = auth.accountId.hexString,
request = SnodeAPI.buildAuthenticatedDeleteBatchInfo(
auth,
listOf(inviteMessageHash)
),
)
}
} }
override suspend fun handlePromotion( override suspend fun handlePromotion(
@ -605,8 +601,9 @@ class GroupManagerV2Impl @Inject constructor(
groupName: String, groupName: String,
adminKey: ByteArray, adminKey: ByteArray,
promoter: AccountId, promoter: AccountId,
promoteMessageHash: String? promoteMessageHash: String,
) = withContext(dispatcher) { promoteMessageTimestamp: Long,
): Unit = withContext(dispatcher) {
val userAuth = requireNotNull(storage.userAuth) { "No current user available" } val userAuth = requireNotNull(storage.userAuth) { "No current user available" }
val group = configFactory.getClosedGroup(groupId) val group = configFactory.getClosedGroup(groupId)
@ -620,6 +617,7 @@ class GroupManagerV2Impl @Inject constructor(
authDataOrAdminKey = adminKey, authDataOrAdminKey = adminKey,
fromPromotion = true, fromPromotion = true,
inviter = promoter, inviter = promoter,
inviteMessageTimestamp = promoteMessageTimestamp,
) )
} else { } else {
// If we have the group in the config, we can just update the admin key // If we have the group in the config, we can just update the admin key
@ -639,13 +637,11 @@ class GroupManagerV2Impl @Inject constructor(
} }
// Delete the promotion message remotely // Delete the promotion message remotely
if (promoteMessageHash != null) {
SnodeAPI.deleteMessage( SnodeAPI.deleteMessage(
userAuth.accountId.hexString, userAuth.accountId.hexString,
userAuth, userAuth,
listOf(promoteMessageHash) listOf(promoteMessageHash)
).await() )
}
} }
/** /**
@ -664,6 +660,7 @@ class GroupManagerV2Impl @Inject constructor(
authDataOrAdminKey: ByteArray, authDataOrAdminKey: ByteArray,
fromPromotion: Boolean, fromPromotion: Boolean,
inviter: AccountId, inviter: AccountId,
inviteMessageTimestamp: Long
) { ) {
// If we have already received an invitation in the past, we should not process this one // If we have already received an invitation in the past, we should not process this one
if (configFactory.getClosedGroup(groupId)?.invited == true) { if (configFactory.getClosedGroup(groupId)?.invited == true) {
@ -697,7 +694,7 @@ class GroupManagerV2Impl @Inject constructor(
} else { } else {
lokiDatabase.addGroupInviteReferrer(groupThreadId, inviter.hexString) lokiDatabase.addGroupInviteReferrer(groupThreadId, inviter.hexString)
storage.insertGroupInviteControlMessage( storage.insertGroupInviteControlMessage(
clock.currentTimeMills(), inviteMessageTimestamp,
inviter.hexString, inviter.hexString,
groupId, groupId,
groupName groupName
@ -868,8 +865,7 @@ class GroupManagerV2Impl @Inject constructor(
sentTimestamp = timestamp sentTimestamp = timestamp
} }
val groupAddress = Address.fromSerialized(groupId.hexString) MessageSender.send(message, Destination.ClosedGroup(groupId.hexString), false).await()
MessageSender.sendNonDurably(message, groupAddress, false).await()
} }
override suspend fun handleDeleteMemberContent( override suspend fun handleDeleteMemberContent(

View File

@ -54,7 +54,8 @@ interface GroupManagerV2 {
groupName: String, groupName: String,
authData: ByteArray, authData: ByteArray,
inviter: AccountId, inviter: AccountId,
inviteMessageHash: String? inviteMessageHash: String,
inviteMessageTimestamp: Long,
) )
suspend fun handlePromotion( suspend fun handlePromotion(
@ -62,7 +63,8 @@ interface GroupManagerV2 {
groupName: String, groupName: String,
adminKey: ByteArray, adminKey: ByteArray,
promoter: AccountId, promoter: AccountId,
promoteMessageHash: String? promoteMessageHash: String,
promoteMessageTimestamp: Long,
) )
suspend fun respondToInvitation(groupId: AccountId, approved: Boolean): Unit? suspend fun respondToInvitation(groupId: AccountId, approved: Boolean): Unit?

View File

@ -229,8 +229,8 @@ object MessageSender {
if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend()) { if (destination is Destination.Contact && message is VisibleMessage && !isSelfSend()) {
SnodeModule.shared.broadcaster.broadcast("messageFailed", message.sentTimestamp!!) SnodeModule.shared.broadcaster.broadcast("messageFailed", message.sentTimestamp!!)
} }
throw error
} }
try { try {
val snodeMessage = buildWrappedMessageToSnode(destination, message, isSyncMessage) val snodeMessage = buildWrappedMessageToSnode(destination, message, isSyncMessage)
// TODO: this might change in future for config messages // TODO: this might change in future for config messages
@ -273,10 +273,10 @@ object MessageSender {
runCatching { it.await() } runCatching { it.await() }
} }
val firstSuccess = sendTaskResults.firstOrNull { it.isSuccess } val firstSuccess = sendTaskResults.firstOrNull { it.isSuccess }?.getOrNull()
if (firstSuccess != null) { if (firstSuccess != null) {
message.serverHash = firstSuccess.getOrThrow().hash message.serverHash = firstSuccess.hash
handleSuccessfulMessageSend(message, destination, isSyncMessage) handleSuccessfulMessageSend(message, destination, isSyncMessage)
} else { } else {
// If all tasks failed, throw the first exception // If all tasks failed, throw the first exception
@ -284,6 +284,7 @@ object MessageSender {
} }
} catch (exception: Exception) { } catch (exception: Exception) {
handleFailure(exception) handleFailure(exception)
throw exception
} }
} }

View File

@ -665,7 +665,8 @@ private fun handlePromotionMessage(message: GroupUpdated) {
groupName = promotion.name, groupName = promotion.name,
adminKey = keyPair.secretKey, adminKey = keyPair.secretKey,
promoter = adminId, promoter = adminId,
promoteMessageHash = message.serverHash promoteMessageHash = message.serverHash!!,
promoteMessageTimestamp = message.sentTimestamp!!,
) )
} catch (e: Exception) { } catch (e: Exception) {
Log.e("GroupUpdated", "Failed to handle promotion message", e) Log.e("GroupUpdated", "Failed to handle promotion message", e)
@ -708,7 +709,8 @@ private fun MessageReceiver.handleNewLibSessionClosedGroupMessage(message: Group
groupName = invite.name, groupName = invite.name,
authData = invite.memberAuthData.toByteArray(), authData = invite.memberAuthData.toByteArray(),
inviter = adminId, inviter = adminId,
inviteMessageHash = message.serverHash inviteMessageHash = message.serverHash!!,
inviteMessageTimestamp = message.sentTimestamp!!,
) )
} catch (e: Exception) { } catch (e: Exception) {
Log.e("GroupUpdated", "Failed to handle invite message", e) Log.e("GroupUpdated", "Failed to handle invite message", e)