add unsend request proto

This commit is contained in:
ryanzhao 2021-08-10 09:36:20 +10:00
parent 18c177971a
commit c0a5a61431
3 changed files with 1019 additions and 91 deletions

View File

@ -0,0 +1,55 @@
package org.session.libsession.messaging.messages.control
import org.session.libsignal.protos.SignalServiceProtos
import org.session.libsignal.utilities.Log
class UnsendRequest(): ControlMessage() {
var timestamp: Long? = null
var author: String? = null
override val isSelfSendValid: Boolean = true
// region Validation
override fun isValid(): Boolean {
if (!super.isValid()) return false
return timestamp != null && author != null
}
// endregion
companion object {
const val TAG = "UnsendRequest"
fun fromProto(proto: SignalServiceProtos.Content): UnsendRequest? {
val unsendRequestProto = if (proto.hasUnsendRequest()) proto.unsendRequest else return null
val timestamp = unsendRequestProto.timestamp
val author = unsendRequestProto.author
return UnsendRequest(timestamp, author)
}
}
constructor(timestamp: Long, author: String) : this() {
this.timestamp = timestamp
this.author = author
}
override fun toProto(): SignalServiceProtos.Content? {
val timestamp = timestamp
val author = author
if (timestamp == null || author == null) {
Log.w(TAG, "Couldn't construct unsend request proto from: $this")
return null
}
val unsendRequestProto = SignalServiceProtos.UnsendRequest.newBuilder()
unsendRequestProto.timestamp = timestamp
unsendRequestProto.author = author
val contentProto = SignalServiceProtos.Content.newBuilder()
try {
contentProto.unsendRequest = unsendRequestProto.build()
return contentProto.build()
} catch (e: Exception) {
Log.w(TAG, "Couldn't construct unsend request proto from: $this")
return null
}
}
}

View File

@ -35,12 +35,20 @@ message TypingMessage {
required Action action = 2; required Action action = 2;
} }
message UnsendRequest {
// @required
required uint64 timestamp = 1;
// @required
required string author = 2;
}
message Content { message Content {
optional DataMessage dataMessage = 1; optional DataMessage dataMessage = 1;
optional ReceiptMessage receiptMessage = 5; optional ReceiptMessage receiptMessage = 5;
optional TypingMessage typingMessage = 6; optional TypingMessage typingMessage = 6;
optional ConfigurationMessage configurationMessage = 7; optional ConfigurationMessage configurationMessage = 7;
optional DataExtractionNotification dataExtractionNotification = 8; optional DataExtractionNotification dataExtractionNotification = 8;
optional UnsendRequest unsendRequest = 9;
} }
message KeyPair { message KeyPair {