mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 00:59:49 +01:00
Add read support for binary service ids.
This commit is contained in:
committed by
jeffrey-signal
parent
bf4aa9cae9
commit
f16405fabf
@@ -104,12 +104,14 @@ import org.whispersystems.signalservice.api.payments.Money
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.api.util.Preconditions
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import org.whispersystems.signalservice.internal.push.BodyRange
|
||||
import org.whispersystems.signalservice.internal.push.Content
|
||||
import org.whispersystems.signalservice.internal.push.DataMessage
|
||||
import org.whispersystems.signalservice.internal.push.Envelope
|
||||
import org.whispersystems.signalservice.internal.push.GroupContextV2
|
||||
import org.whispersystems.signalservice.internal.push.Preview
|
||||
import org.whispersystems.signalservice.internal.util.Util
|
||||
import java.util.Optional
|
||||
import java.util.UUID
|
||||
import kotlin.time.Duration
|
||||
@@ -145,7 +147,7 @@ object DataMessageProcessor {
|
||||
groupV2 = message.groupV2!!,
|
||||
senderRecipient = senderRecipient,
|
||||
groupSecretParams = groupSecretParams,
|
||||
serverGuid = envelope.serverGuid
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary)
|
||||
)
|
||||
|
||||
if (groupProcessResult == MessageContentProcessor.Gv2PreProcessResult.IGNORE) {
|
||||
@@ -304,7 +306,7 @@ object DataMessageProcessor {
|
||||
serverTimeMillis = envelope.serverTimestamp!!,
|
||||
receivedTimeMillis = System.currentTimeMillis(),
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
type = MessageType.END_SESSION
|
||||
)
|
||||
|
||||
@@ -362,7 +364,7 @@ object DataMessageProcessor {
|
||||
receivedTimeMillis = receivedTime,
|
||||
expiresIn = expiresIn.inWholeMilliseconds,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary)
|
||||
)
|
||||
|
||||
val insertResult: InsertResult? = SignalDatabase.messages.insertMessageInbox(mediaMessage, -1).orNull()
|
||||
@@ -423,7 +425,7 @@ object DataMessageProcessor {
|
||||
return null
|
||||
}
|
||||
|
||||
val authorServiceId: ServiceId = ServiceId.parseOrThrow(storyContext.authorAci!!)
|
||||
val authorServiceId: ServiceId = ACI.parseOrThrow(storyContext.authorAci, storyContext.authorAciBinary)
|
||||
val sentTimestamp = storyContext.sentTimestamp!!
|
||||
|
||||
SignalDatabase.messages.beginTransaction()
|
||||
@@ -473,7 +475,7 @@ object DataMessageProcessor {
|
||||
body = emoji,
|
||||
groupId = groupId,
|
||||
quote = quoteModel,
|
||||
serverGuid = envelope.serverGuid
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary)
|
||||
)
|
||||
|
||||
val insertResult: InsertResult? = SignalDatabase.messages.insertMessageInbox(mediaMessage, -1).orNull()
|
||||
@@ -517,7 +519,7 @@ object DataMessageProcessor {
|
||||
|
||||
val emoji: String? = reaction.emoji
|
||||
val isRemove: Boolean = reaction.remove ?: false
|
||||
val targetAuthorServiceId: ServiceId = ServiceId.parseOrThrow(reaction.targetAuthorAci!!)
|
||||
val targetAuthorServiceId: ServiceId = ACI.parseOrThrow(reaction.targetAuthorAci, reaction.targetAuthorAciBinary)
|
||||
val targetSentTimestamp: Long = reaction.targetSentTimestamp!!
|
||||
|
||||
if (targetAuthorServiceId.isUnknown) {
|
||||
@@ -635,7 +637,7 @@ object DataMessageProcessor {
|
||||
receivedTimeMillis = receivedTime,
|
||||
expiresIn = message.expireTimerDuration.inWholeMilliseconds,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
type = if (isActivatePaymentsRequest) MessageType.ACTIVATE_PAYMENTS_REQUEST else MessageType.PAYMENTS_ACTIVATED
|
||||
)
|
||||
|
||||
@@ -686,7 +688,7 @@ object DataMessageProcessor {
|
||||
receivedTimeMillis = receivedTime,
|
||||
expiresIn = message.expireTimerDuration.inWholeMilliseconds,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
type = MessageType.PAYMENTS_NOTIFICATION
|
||||
)
|
||||
|
||||
@@ -726,7 +728,7 @@ object DataMessageProcessor {
|
||||
log(envelope.timestamp!!, "Story reply.")
|
||||
|
||||
val storyContext: DataMessage.StoryContext = message.storyContext!!
|
||||
val authorServiceId: ServiceId = ServiceId.parseOrThrow(storyContext.authorAci!!)
|
||||
val authorServiceId: ServiceId = ACI.parseOrThrow(storyContext.authorAci, storyContext.authorAciBinary)
|
||||
val sentTimestamp: Long = if (storyContext.sentTimestamp != null) {
|
||||
storyContext.sentTimestamp!!
|
||||
} else {
|
||||
@@ -786,7 +788,7 @@ object DataMessageProcessor {
|
||||
return null
|
||||
}
|
||||
|
||||
val bodyRanges: BodyRangeList? = message.bodyRanges.filter { it.mentionAci == null }.toList().toBodyRangeList()
|
||||
val bodyRanges: BodyRangeList? = message.bodyRanges.filter { Util.allAreNull(it.mentionAci, it.mentionAciBinary) }.toList().toBodyRangeList()
|
||||
|
||||
val mediaMessage = IncomingMessage(
|
||||
type = MessageType.NORMAL,
|
||||
@@ -801,7 +803,7 @@ object DataMessageProcessor {
|
||||
groupId = groupId,
|
||||
quote = quoteModel,
|
||||
mentions = getMentions(message.bodyRanges),
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
messageRanges = bodyRanges
|
||||
)
|
||||
|
||||
@@ -866,7 +868,7 @@ object DataMessageProcessor {
|
||||
expiresIn = message.expireTimerDuration.inWholeMilliseconds,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
body = Base64.encodeWithPadding(dbGiftBadge.encode()),
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
giftBadge = dbGiftBadge
|
||||
)
|
||||
|
||||
@@ -910,7 +912,7 @@ object DataMessageProcessor {
|
||||
val mentions: List<Mention> = getMentions(message.bodyRanges.take(BODY_RANGE_PROCESSING_LIMIT))
|
||||
val sticker: Attachment? = getStickerAttachment(envelope.timestamp!!, message)
|
||||
val attachments: List<Attachment> = message.attachments.toPointersWithinLimit()
|
||||
val messageRanges: BodyRangeList? = if (message.bodyRanges.isNotEmpty()) message.bodyRanges.asSequence().take(BODY_RANGE_PROCESSING_LIMIT).filter { it.mentionAci == null }.toList().toBodyRangeList() else null
|
||||
val messageRanges: BodyRangeList? = if (message.bodyRanges.isNotEmpty()) message.bodyRanges.asSequence().take(BODY_RANGE_PROCESSING_LIMIT).filter { Util.allAreNull(it.mentionAci, it.mentionAciBinary) }.toList().toBodyRangeList() else null
|
||||
|
||||
handlePossibleExpirationUpdate(envelope, metadata, senderRecipient, threadRecipient, groupId, message.expireTimerDuration, message.expireTimerVersion, receivedTime)
|
||||
|
||||
@@ -930,7 +932,7 @@ object DataMessageProcessor {
|
||||
sharedContacts = contacts,
|
||||
linkPreviews = linkPreviews,
|
||||
mentions = mentions,
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
messageRanges = messageRanges
|
||||
)
|
||||
|
||||
@@ -1006,7 +1008,7 @@ object DataMessageProcessor {
|
||||
groupId = groupId,
|
||||
expiresIn = message.expireTimerDuration.inWholeMilliseconds,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary)
|
||||
)
|
||||
|
||||
val insertResult: InsertResult? = SignalDatabase.messages.insertMessageInbox(textMessage).orNull()
|
||||
@@ -1086,7 +1088,7 @@ object DataMessageProcessor {
|
||||
groupId = groupId,
|
||||
expiresIn = message.expireTimerDuration.inWholeMilliseconds,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
poll = Poll(
|
||||
question = poll.question!!,
|
||||
allowMultipleVotes = poll.allowMultiple!!,
|
||||
@@ -1148,7 +1150,7 @@ object DataMessageProcessor {
|
||||
groupId = groupId,
|
||||
expiresIn = message.expireTimerDuration.inWholeMilliseconds,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
messageExtras = MessageExtras(pollTerminate = PollTerminate(poll.question, poll.messageId, targetSentTimestamp))
|
||||
)
|
||||
|
||||
@@ -1244,9 +1246,9 @@ object DataMessageProcessor {
|
||||
|
||||
fun getMentions(mentionBodyRanges: List<BodyRange>): List<Mention> {
|
||||
return mentionBodyRanges
|
||||
.filter { it.mentionAci != null && it.start != null && it.length != null }
|
||||
.filter { Util.anyNotNull(it.mentionAci, it.mentionAciBinary) && it.start != null && it.length != null }
|
||||
.mapNotNull {
|
||||
val aci = ACI.parseOrNull(it.mentionAci)
|
||||
val aci = ACI.parseOrNull(it.mentionAci, it.mentionAciBinary)
|
||||
|
||||
if (aci != null && !aci.isUnknown) {
|
||||
val id = Recipient.externalPush(aci).id
|
||||
@@ -1279,7 +1281,7 @@ object DataMessageProcessor {
|
||||
return null
|
||||
}
|
||||
|
||||
val authorId = Recipient.externalPush(ServiceId.parseOrThrow(quote.authorAci!!)).id
|
||||
val authorId = Recipient.externalPush(ACI.parseOrThrow(quote.authorAci, quote.authorAciBinary)).id
|
||||
var quotedMessage = SignalDatabase.messages.getMessageFor(quote.id!!, authorId) as? MmsMessageRecord
|
||||
|
||||
if (quotedMessage != null && isSenderValid(quotedMessage, timestamp, senderRecipient, threadRecipient) && !quotedMessage.isRemoteDelete) {
|
||||
|
||||
@@ -31,9 +31,11 @@ import org.thoughtcrime.securesms.util.MessageConstraintsUtil
|
||||
import org.thoughtcrime.securesms.util.hasAudio
|
||||
import org.thoughtcrime.securesms.util.hasSharedContact
|
||||
import org.whispersystems.signalservice.api.crypto.EnvelopeMetadata
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import org.whispersystems.signalservice.internal.push.Content
|
||||
import org.whispersystems.signalservice.internal.push.DataMessage
|
||||
import org.whispersystems.signalservice.internal.push.Envelope
|
||||
import org.whispersystems.signalservice.internal.util.Util
|
||||
|
||||
object EditMessageProcessor {
|
||||
fun process(
|
||||
@@ -120,7 +122,7 @@ object EditMessageProcessor {
|
||||
message: DataMessage,
|
||||
targetMessage: MmsMessageRecord
|
||||
): InsertResult? {
|
||||
val messageRanges: BodyRangeList? = message.bodyRanges.filter { it.mentionAci == null }.toList().toBodyRangeList()
|
||||
val messageRanges: BodyRangeList? = message.bodyRanges.filter { Util.allAreNull(it.mentionAci, it.mentionAciBinary) }.toList().toBodyRangeList()
|
||||
val targetQuote = targetMessage.quote
|
||||
val quote: QuoteModel? = if (targetQuote != null && (message.quote != null || (targetMessage.parentStoryId != null && message.storyContext != null))) {
|
||||
QuoteModel(
|
||||
@@ -156,7 +158,7 @@ object EditMessageProcessor {
|
||||
sharedContacts = emptyList(),
|
||||
linkPreviews = DataMessageProcessor.getLinkPreviews(message.preview, message.body ?: "", false),
|
||||
mentions = DataMessageProcessor.getMentions(message.bodyRanges),
|
||||
serverGuid = envelope.serverGuid,
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
messageRanges = messageRanges
|
||||
)
|
||||
|
||||
@@ -191,7 +193,7 @@ object EditMessageProcessor {
|
||||
parentStoryId = targetMessage.parentStoryId,
|
||||
expiresIn = targetMessage.expiresIn,
|
||||
isUnidentified = metadata.sealedSender,
|
||||
serverGuid = envelope.serverGuid
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary)
|
||||
)
|
||||
|
||||
return SignalDatabase.messages.insertEditMessageInbox(textMessage, targetMessage).orNull()
|
||||
|
||||
@@ -334,7 +334,7 @@ class IncomingMessageObserver(
|
||||
}
|
||||
|
||||
private fun processReceipt(envelope: Envelope) {
|
||||
val serviceId = ServiceId.parseOrNull(envelope.sourceServiceId)
|
||||
val serviceId = ServiceId.parseOrNull(envelope.sourceServiceId, envelope.sourceServiceIdBinary)
|
||||
if (serviceId == null) {
|
||||
Log.w(TAG, "Invalid envelope sourceServiceId!")
|
||||
return
|
||||
|
||||
@@ -659,7 +659,7 @@ open class MessageContentProcessor(private val context: Context) {
|
||||
private fun handleIndividualRetryReceipt(requester: Recipient, messageLogEntry: MessageLogEntry?, envelope: Envelope, metadata: EnvelopeMetadata, decryptionErrorMessage: DecryptionErrorMessage) {
|
||||
var archivedSession = false
|
||||
|
||||
if (ServiceId.parseOrNull(envelope.destinationServiceId) is ServiceId.PNI) {
|
||||
if (ServiceId.parseOrNull(envelope.destinationServiceId, envelope.destinationServiceIdBinary) is ServiceId.PNI) {
|
||||
warn(envelope.timestamp!!, "[RetryReceipt-I] Destination is our PNI. Ignoring.")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -67,9 +67,11 @@ import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.PNI
|
||||
import org.whispersystems.signalservice.api.push.SignalServiceAddress
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import org.whispersystems.signalservice.internal.push.Content
|
||||
import org.whispersystems.signalservice.internal.push.Envelope
|
||||
import org.whispersystems.signalservice.internal.push.PniSignatureMessage
|
||||
import org.whispersystems.signalservice.internal.util.Util
|
||||
import java.util.Optional
|
||||
import kotlin.time.Duration.Companion.nanoseconds
|
||||
import kotlin.time.DurationUnit
|
||||
@@ -100,7 +102,7 @@ object MessageDecryptor {
|
||||
val selfAci: ACI = SignalStore.account.requireAci()
|
||||
val selfPni: PNI = SignalStore.account.requirePni()
|
||||
|
||||
val destination: ServiceId? = ServiceId.parseOrNull(envelope.destinationServiceId)
|
||||
val destination: ServiceId? = ServiceId.parseOrNull(envelope.destinationServiceId, envelope.destinationServiceIdBinary)
|
||||
|
||||
if (destination == null) {
|
||||
Log.w(TAG, "${logPrefix(envelope)} Missing destination address! Invalid message, ignoring.")
|
||||
@@ -112,10 +114,10 @@ object MessageDecryptor {
|
||||
return Result.Ignore(envelope, serverDeliveredTimestamp, emptyList())
|
||||
}
|
||||
|
||||
if (destination == selfPni && envelope.sourceServiceId != null) {
|
||||
if (destination == selfPni && Util.anyNotNull(envelope.sourceServiceId, envelope.sourceServiceIdBinary)) {
|
||||
Log.i(TAG, "${logPrefix(envelope)} Received a message at our PNI. Marking as needing a PNI signature.")
|
||||
|
||||
val sourceServiceId = ServiceId.parseOrNull(envelope.sourceServiceId)
|
||||
val sourceServiceId = ServiceId.parseOrNull(envelope.sourceServiceId, envelope.sourceServiceIdBinary)
|
||||
|
||||
if (sourceServiceId != null) {
|
||||
val sender = RecipientId.from(sourceServiceId)
|
||||
@@ -125,7 +127,7 @@ object MessageDecryptor {
|
||||
}
|
||||
}
|
||||
|
||||
if (destination == selfPni && envelope.sourceServiceId == null) {
|
||||
if (destination == selfPni && Util.allAreNull(envelope.sourceServiceId, envelope.sourceServiceIdBinary)) {
|
||||
Log.w(TAG, "${logPrefix(envelope)} Got a sealed sender message to our PNI? Invalid message, ignoring.")
|
||||
return Result.Ignore(envelope, serverDeliveredTimestamp, emptyList())
|
||||
}
|
||||
@@ -164,7 +166,7 @@ object MessageDecryptor {
|
||||
return Result.Ignore(envelope, serverDeliveredTimestamp, followUpOperations.toUnmodifiableList())
|
||||
}
|
||||
|
||||
Log.d(TAG, "${logPrefix(envelope, cipherResult)} Successfully decrypted the envelope in ${(endTimeNanos - startTimeNanos).nanoseconds.toDouble(DurationUnit.MILLISECONDS).roundedString(2)} ms (GUID ${envelope.serverGuid}). Delivery latency: ${serverDeliveredTimestamp - envelope.serverTimestamp!!} ms, Urgent: ${envelope.urgent}")
|
||||
Log.d(TAG, "${logPrefix(envelope, cipherResult)} Successfully decrypted the envelope in ${(endTimeNanos - startTimeNanos).nanoseconds.toDouble(DurationUnit.MILLISECONDS).roundedString(2)} ms (GUID ${UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary)}). Delivery latency: ${serverDeliveredTimestamp - envelope.serverTimestamp!!} ms, Urgent: ${envelope.urgent}")
|
||||
|
||||
val validationResult: EnvelopeContentValidator.Result = EnvelopeContentValidator.validate(envelope, cipherResult.content, SignalStore.account.aci!!)
|
||||
|
||||
@@ -289,7 +291,7 @@ object MessageDecryptor {
|
||||
followUpOperations: MutableList<FollowUpOperation>,
|
||||
protocolException: ProtocolException
|
||||
): Result {
|
||||
if (ServiceId.parseOrNull(envelope.destinationServiceId) == SignalStore.account.pni) {
|
||||
if (ServiceId.parseOrNull(envelope.destinationServiceId, envelope.destinationServiceIdBinary) == SignalStore.account.pni) {
|
||||
Log.w(TAG, "${logPrefix(envelope)} Decryption error for message sent to our PNI! Ignoring.")
|
||||
return Result.Ignore(envelope, serverDeliveredTimestamp, followUpOperations)
|
||||
}
|
||||
@@ -475,7 +477,7 @@ object MessageDecryptor {
|
||||
}
|
||||
|
||||
private fun logPrefix(envelope: Envelope): String {
|
||||
return logPrefix(envelope.timestamp!!, ServiceId.parseOrNull(envelope.sourceServiceId)?.logString() ?: "<sealed>", envelope.sourceDevice)
|
||||
return logPrefix(envelope.timestamp!!, ServiceId.parseOrNull(envelope.sourceServiceId, envelope.sourceServiceIdBinary)?.logString() ?: "<sealed>", envelope.sourceDevice)
|
||||
}
|
||||
|
||||
private fun logPrefix(envelope: Envelope, sender: ServiceId?): String {
|
||||
@@ -494,7 +496,7 @@ object MessageDecryptor {
|
||||
return if (exception.sender != null) {
|
||||
logPrefix(envelope.timestamp!!, ServiceId.parseOrNull(exception.sender)?.logString() ?: "?", exception.senderDevice)
|
||||
} else {
|
||||
logPrefix(envelope.timestamp!!, envelope.sourceServiceId, envelope.sourceDevice)
|
||||
logPrefix(envelope.timestamp!!, ServiceId.parseOrNull(envelope.sourceServiceId, envelope.sourceServiceIdBinary).toString(), envelope.sourceDevice)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -145,14 +145,14 @@ object SignalServiceProtoUtil {
|
||||
}
|
||||
|
||||
fun Sent.isUnidentified(serviceId: ServiceId?): Boolean {
|
||||
return serviceId != null && unidentifiedStatus.firstOrNull { ServiceId.parseOrNull(it.destinationServiceId) == serviceId }?.unidentified ?: false
|
||||
return serviceId != null && unidentifiedStatus.firstOrNull { ServiceId.parseOrNull(it.destinationServiceId, it.destinationServiceIdBinary) == serviceId }?.unidentified ?: false
|
||||
}
|
||||
|
||||
val Sent.serviceIdsToUnidentifiedStatus: Map<ServiceId, Boolean>
|
||||
get() {
|
||||
return unidentifiedStatus
|
||||
.mapNotNull { status ->
|
||||
val serviceId = ServiceId.parseOrNull(status.destinationServiceId)
|
||||
val serviceId = ServiceId.parseOrNull(status.destinationServiceId, status.destinationServiceIdBinary)
|
||||
if (serviceId != null) {
|
||||
serviceId to (status.unidentified ?: false)
|
||||
} else {
|
||||
|
||||
@@ -21,10 +21,12 @@ import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.stories.Stories
|
||||
import org.thoughtcrime.securesms.util.RemoteConfig
|
||||
import org.whispersystems.signalservice.api.crypto.EnvelopeMetadata
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil
|
||||
import org.whispersystems.signalservice.internal.push.Content
|
||||
import org.whispersystems.signalservice.internal.push.Envelope
|
||||
import org.whispersystems.signalservice.internal.push.StoryMessage
|
||||
import org.whispersystems.signalservice.internal.push.TextAttachment
|
||||
import org.whispersystems.signalservice.internal.util.Util
|
||||
|
||||
object StoryMessageProcessor {
|
||||
|
||||
@@ -75,8 +77,8 @@ object StoryMessageProcessor {
|
||||
body = "",
|
||||
isStoryEmbed = true
|
||||
),
|
||||
serverGuid = envelope.serverGuid,
|
||||
messageRanges = storyMessage.bodyRanges.filter { it.mentionAci == null }.toBodyRangeList()
|
||||
serverGuid = UuidUtil.getStringUUID(envelope.serverGuid, envelope.serverGuidBinary),
|
||||
messageRanges = storyMessage.bodyRanges.filter { Util.allAreNull(it.mentionAci, it.mentionAciBinary) }.toBodyRangeList()
|
||||
)
|
||||
|
||||
insertResult = SignalDatabase.messages.insertMessageInbox(mediaMessage, -1).orNull()
|
||||
|
||||
@@ -143,6 +143,7 @@ import java.util.concurrent.TimeUnit
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.days
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
import org.whispersystems.signalservice.internal.util.Util as Utils
|
||||
|
||||
object SyncMessageProcessor {
|
||||
|
||||
@@ -287,7 +288,7 @@ object SyncMessageProcessor {
|
||||
continue
|
||||
}
|
||||
|
||||
val pni = PNI.parsePrefixedOrNull(status.destinationServiceId)
|
||||
val pni = PNI.parsePrefixedOrNull(status.destinationServiceId, status.destinationServiceIdBinary)
|
||||
if (pni == null) {
|
||||
continue
|
||||
}
|
||||
@@ -313,7 +314,7 @@ object SyncMessageProcessor {
|
||||
return if (message.message.hasGroupContext) {
|
||||
Recipient.externalPossiblyMigratedGroup(GroupId.v2(message.message!!.groupV2!!.groupMasterKey))
|
||||
} else {
|
||||
Recipient.externalPush(SignalServiceAddress(ServiceId.parseOrThrow(message.destinationServiceId!!), message.destinationE164))
|
||||
Recipient.externalPush(SignalServiceAddress(ServiceId.parseOrThrow(message.destinationServiceId, message.destinationServiceIdBinary), message.destinationE164))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -341,7 +342,7 @@ object SyncMessageProcessor {
|
||||
val toRecipient: Recipient = if (message.hasGroupContext) {
|
||||
Recipient.externalPossiblyMigratedGroup(GroupId.v2(message.groupV2!!.groupMasterKey))
|
||||
} else {
|
||||
Recipient.externalPush(ServiceId.parseOrThrow(sent.destinationServiceId!!))
|
||||
Recipient.externalPush(ServiceId.parseOrThrow(sent.destinationServiceId, sent.destinationServiceIdBinary))
|
||||
}
|
||||
|
||||
if (message.isMediaMessage) {
|
||||
@@ -364,7 +365,7 @@ object SyncMessageProcessor {
|
||||
log(envelopeTimestamp, "Synchronize sent edit text message for message: ${targetMessage.id}")
|
||||
|
||||
val body = message.body ?: ""
|
||||
val bodyRanges = message.bodyRanges.filter { it.mentionAci == null }.toBodyRangeList()
|
||||
val bodyRanges = message.bodyRanges.filter { Utils.allAreNull(it.mentionAci, it.mentionAciBinary) }.toBodyRangeList()
|
||||
|
||||
val threadId = SignalDatabase.threads.getOrCreateThreadIdFor(toRecipient)
|
||||
val isGroup = toRecipient.isGroup
|
||||
@@ -740,7 +741,7 @@ object SyncMessageProcessor {
|
||||
|
||||
val reaction: DataMessage.Reaction? = dataMessage.reaction
|
||||
val parentStoryId: ParentStoryId
|
||||
val authorServiceId: ServiceId = ServiceId.parseOrThrow(storyContext.authorAci!!)
|
||||
val authorServiceId: ServiceId = ACI.parseOrThrow(storyContext.authorAci, storyContext.authorAciBinary)
|
||||
val sentTimestamp: Long = storyContext.sentTimestamp!!
|
||||
val recipient: Recipient = getSyncMessageDestination(sent)
|
||||
var quoteModel: QuoteModel? = null
|
||||
@@ -903,7 +904,7 @@ object SyncMessageProcessor {
|
||||
val dataMessage: DataMessage = sent.message!!
|
||||
val body = dataMessage.body ?: ""
|
||||
val expiresInMillis = dataMessage.expireTimerDuration.inWholeMilliseconds
|
||||
val bodyRanges = dataMessage.bodyRanges.filter { it.mentionAci == null }.toBodyRangeList()
|
||||
val bodyRanges = dataMessage.bodyRanges.filter { Utils.allAreNull(it.mentionAci, it.mentionAciBinary) }.toBodyRangeList()
|
||||
|
||||
if (recipient.expiresInSeconds != dataMessage.expireTimerDuration.inWholeSeconds.toInt() || ((dataMessage.expireTimerVersion ?: -1) > recipient.expireTimerVersion)) {
|
||||
handleSynchronizeSentExpirationUpdate(sent, sideEffect = true)
|
||||
@@ -1017,7 +1018,7 @@ object SyncMessageProcessor {
|
||||
|
||||
val records = viewedMessages
|
||||
.mapNotNull { message ->
|
||||
val author = Recipient.externalPush(ServiceId.parseOrThrow(message.senderAci!!)).id
|
||||
val author = Recipient.externalPush(ACI.parseOrThrow(message.senderAci, message.senderAciBinary)).id
|
||||
if (message.timestamp != null) {
|
||||
SignalDatabase.messages.getMessageFor(message.timestamp!!, author)
|
||||
} else {
|
||||
@@ -1049,7 +1050,7 @@ object SyncMessageProcessor {
|
||||
private fun handleSynchronizeViewOnceOpenMessage(context: Context, openMessage: ViewOnceOpen, envelopeTimestamp: Long, earlyMessageCacheEntry: EarlyMessageCacheEntry?) {
|
||||
log(envelopeTimestamp, "Handling a view-once open for message: " + openMessage.timestamp)
|
||||
|
||||
val author: RecipientId = Recipient.externalPush(ServiceId.parseOrThrow(openMessage.senderAci!!)).id
|
||||
val author: RecipientId = Recipient.externalPush(ACI.parseOrThrow(openMessage.senderAci, openMessage.senderAciBinary)).id
|
||||
val timestamp: Long = if (openMessage.timestamp != null) {
|
||||
openMessage.timestamp!!
|
||||
} else {
|
||||
@@ -1122,7 +1123,7 @@ object SyncMessageProcessor {
|
||||
}
|
||||
|
||||
private fun handleSynchronizeBlockedListMessage(blockMessage: Blocked, envelopeTimestamp: Long) {
|
||||
val blockedAcis = blockMessage.acis.mapNotNull { ACI.parseOrNull(it) }
|
||||
val blockedAcis = if (blockMessage.acisBinary.isNotEmpty()) { blockMessage.acisBinary.mapNotNull { ACI.parseOrNull(it) } } else blockMessage.acis.mapNotNull { ACI.parseOrNull(it) }
|
||||
val blockedE164s = blockMessage.numbers
|
||||
val blockedGroupIds = blockMessage.groupIds.map { it.toByteArray() }
|
||||
log(envelopeTimestamp, "Synchronize block message. Counts: (ACI: ${blockedAcis.size}, E164: ${blockedE164s.size}, Group: ${blockedGroupIds.size})")
|
||||
@@ -1144,8 +1145,8 @@ object SyncMessageProcessor {
|
||||
private fun handleSynchronizeMessageRequestResponse(response: MessageRequestResponse, envelopeTimestamp: Long) {
|
||||
log(envelopeTimestamp, "Synchronize message request response.")
|
||||
|
||||
val recipient: Recipient = if (response.threadAci != null) {
|
||||
Recipient.externalPush(ServiceId.parseOrThrow(response.threadAci!!))
|
||||
val recipient: Recipient = if (Utils.anyNotNull(response.threadAci, response.threadAciBinary)) {
|
||||
Recipient.externalPush(ACI.parseOrThrow(response.threadAci, response.threadAciBinary))
|
||||
} else if (response.groupId != null) {
|
||||
val groupId: GroupId = GroupId.push(response.groupId!!)
|
||||
Recipient.externalPossiblyMigratedGroup(groupId)
|
||||
@@ -1858,6 +1859,7 @@ object SyncMessageProcessor {
|
||||
}
|
||||
|
||||
private fun ConversationIdentifier.toRecipientId(): RecipientId? {
|
||||
val threadServiceId = ServiceId.parseOrNull(this.threadServiceId, this.threadServiceIdBinary)
|
||||
return when {
|
||||
threadGroupId != null -> {
|
||||
try {
|
||||
@@ -1869,9 +1871,7 @@ object SyncMessageProcessor {
|
||||
}
|
||||
|
||||
threadServiceId != null -> {
|
||||
ServiceId.parseOrNull(threadServiceId)?.let {
|
||||
SignalDatabase.recipients.getOrInsertFromServiceId(it)
|
||||
}
|
||||
SignalDatabase.recipients.getOrInsertFromServiceId(threadServiceId)
|
||||
}
|
||||
|
||||
threadE164 != null -> {
|
||||
@@ -1885,8 +1885,8 @@ object SyncMessageProcessor {
|
||||
}
|
||||
|
||||
private fun AddressableMessage.toSyncMessageId(envelopeTimestamp: Long): MessageTable.SyncMessageId? {
|
||||
return if (this.sentTimestamp != null && (this.authorServiceId != null || this.authorE164 != null)) {
|
||||
val serviceId = ServiceId.parseOrNull(this.authorServiceId)
|
||||
return if (this.sentTimestamp != null && Utils.anyNotNull(this.authorServiceId, this.authorServiceIdBinary) || this.authorE164 != null) {
|
||||
val serviceId = ServiceId.parseOrNull(this.authorServiceId, this.authorServiceIdBinary)
|
||||
val id = if (serviceId != null) {
|
||||
SignalDatabase.recipients.getOrInsertFromServiceId(serviceId)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user