mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
SessionRequest unfinished implementation
This commit is contained in:
parent
2c167b0cc0
commit
3f0e456002
@ -15,9 +15,9 @@ abstract class Message {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
val ttl = 2 * 24 * 60 * 60 * 1000
|
val ttl = 2 * 24 * 60 * 60 * 1000 //TODO not sure about that declaration
|
||||||
|
|
||||||
//fun fromProto(proto: SignalServiceProtos.Content): Message? {}
|
//TODO how to declare fromProto?
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun isValid(): Boolean {
|
open fun isValid(): Boolean {
|
||||||
@ -26,8 +26,6 @@ abstract class Message {
|
|||||||
return sender != null && recipient != null
|
return sender != null && recipient != null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
abstract fun toProto(): SignalServiceProtos.Content?
|
abstract fun toProto(): SignalServiceProtos.Content?
|
||||||
|
|
||||||
}
|
}
|
@ -8,6 +8,8 @@ class TypingIndicator() : ControlMessage() {
|
|||||||
companion object {
|
companion object {
|
||||||
const val TAG = "TypingIndicator"
|
const val TAG = "TypingIndicator"
|
||||||
|
|
||||||
|
//val ttl: 30 * 1000 //TODO
|
||||||
|
|
||||||
fun fromProto(proto: SignalServiceProtos.Content): TypingIndicator? {
|
fun fromProto(proto: SignalServiceProtos.Content): TypingIndicator? {
|
||||||
val typingIndicatorProto = proto.typingMessage ?: return null
|
val typingIndicatorProto = proto.typingMessage ?: return null
|
||||||
val kind = Kind.fromProto(typingIndicatorProto.action)
|
val kind = Kind.fromProto(typingIndicatorProto.action)
|
||||||
|
@ -1,18 +1,81 @@
|
|||||||
package org.session.libsession.messaging.messages.control.unused
|
package org.session.libsession.messaging.messages.control.unused
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString
|
||||||
import org.session.libsession.messaging.messages.control.ControlMessage
|
import org.session.libsession.messaging.messages.control.ControlMessage
|
||||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||||
|
import org.session.libsession.messaging.messages.control.TypingIndicator
|
||||||
|
import org.session.libsignal.libsignal.logging.Log
|
||||||
|
import org.session.libsignal.libsignal.state.PreKeyBundle
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
|
import java.security.SecureRandom
|
||||||
|
|
||||||
class SessionRequest() : ControlMessage() {
|
class SessionRequest() : ControlMessage() {
|
||||||
|
|
||||||
|
var preKeyBundle: PreKeyBundle? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val TAG = "SessionRequest"
|
||||||
|
|
||||||
fun fromProto(proto: SignalServiceProtos.Content): SessionRequest? {
|
fun fromProto(proto: SignalServiceProtos.Content): SessionRequest? {
|
||||||
TODO("Not yet implemented")
|
if (proto.nullMessage == null) return null
|
||||||
|
val preKeyBundleProto = proto.preKeyBundleMessage ?: return null
|
||||||
|
val registrationID: Int = 0
|
||||||
|
//TODO looks like database stuff here
|
||||||
|
/*iOS code: Configuration.shared.storage.with { transaction in
|
||||||
|
registrationID = Configuration.shared.storage.getOrGenerateRegistrationID(using: transaction)
|
||||||
|
}*/
|
||||||
|
val preKeyBundle = PreKeyBundle(
|
||||||
|
registrationID,
|
||||||
|
1,
|
||||||
|
preKeyBundleProto.preKeyId,
|
||||||
|
null, //TODO preKeyBundleProto.preKey,
|
||||||
|
0, //TODO preKeyBundleProto.signedKey,
|
||||||
|
null, //TODO preKeyBundleProto.signedKeyId,
|
||||||
|
preKeyBundleProto.signature.toByteArray(),
|
||||||
|
null, //TODO preKeyBundleProto.identityKey
|
||||||
|
) ?: return null
|
||||||
|
return SessionRequest(preKeyBundle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//constructor
|
||||||
|
internal constructor(preKeyBundle: PreKeyBundle) : this() {
|
||||||
|
this.preKeyBundle = preKeyBundle
|
||||||
|
}
|
||||||
|
|
||||||
|
// validation
|
||||||
|
override fun isValid(): Boolean {
|
||||||
|
if (!super.isValid()) return false
|
||||||
|
return preKeyBundle != null
|
||||||
|
}
|
||||||
|
|
||||||
override fun toProto(): SignalServiceProtos.Content? {
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
TODO("Not yet implemented")
|
val preKeyBundle = preKeyBundle
|
||||||
|
if (preKeyBundle == null) {
|
||||||
|
Log.w(TAG, "Couldn't construct session request proto from: $this")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val nullMessageProto = SignalServiceProtos.NullMessage.newBuilder()
|
||||||
|
val sr = SecureRandom()
|
||||||
|
val paddingSize = sr.nextInt(512)
|
||||||
|
val padding = ByteArray(paddingSize)
|
||||||
|
nullMessageProto.padding = ByteString.copyFrom(padding)
|
||||||
|
val preKeyBundleProto = SignalServiceProtos.PreKeyBundleMessage.newBuilder()
|
||||||
|
//TODO preKeyBundleProto.identityKey = preKeyBundle.identityKey
|
||||||
|
preKeyBundleProto.deviceId = preKeyBundle.deviceId
|
||||||
|
preKeyBundleProto.preKeyId = preKeyBundle.preKeyId
|
||||||
|
//TODO preKeyBundleProto.preKey = preKeyBundle.preKeyPublic
|
||||||
|
preKeyBundleProto.signedKeyId = preKeyBundle.signedPreKeyId
|
||||||
|
//TODO preKeyBundleProto.signedKey = preKeyBundle.signedPreKeyPublic
|
||||||
|
preKeyBundleProto.signature = ByteString.copyFrom(preKeyBundle.signedPreKeySignature)
|
||||||
|
val contentProto = SignalServiceProtos.Content.newBuilder()
|
||||||
|
try {
|
||||||
|
contentProto.nullMessage = nullMessageProto.build()
|
||||||
|
contentProto.preKeyBundleMessage = preKeyBundleProto.build()
|
||||||
|
return contentProto.build()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Couldn't construct session request proto from: $this")
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user