mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 16:08:27 +00:00
Merge pull request #473 from Brice-W/data-extraction
Adding DataExtractionNotification type
This commit is contained in:
commit
2072e34e44
@ -0,0 +1,4 @@
|
|||||||
|
package org.thoughtcrime.securesms.sskenvironment
|
||||||
|
|
||||||
|
class DataExtractionNotificationManager {
|
||||||
|
}
|
@ -55,7 +55,7 @@ class ClosedGroupControlMessage() : ControlMessage() {
|
|||||||
class MemberLeft() : Kind()
|
class MemberLeft() : Kind()
|
||||||
class EncryptionKeyPairRequest(): Kind()
|
class EncryptionKeyPairRequest(): Kind()
|
||||||
|
|
||||||
val description: String = run {
|
val description: String =
|
||||||
when(this) {
|
when(this) {
|
||||||
is New -> "new"
|
is New -> "new"
|
||||||
is Update -> "update"
|
is Update -> "update"
|
||||||
@ -67,7 +67,6 @@ class ClosedGroupControlMessage() : ControlMessage() {
|
|||||||
is EncryptionKeyPairRequest -> "encryptionKeyPairRequest"
|
is EncryptionKeyPairRequest -> "encryptionKeyPairRequest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "ClosedGroupControlMessage"
|
const val TAG = "ClosedGroupControlMessage"
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
package org.session.libsession.messaging.messages.control
|
||||||
|
|
||||||
|
import com.google.protobuf.ByteString
|
||||||
|
import org.session.libsignal.libsignal.ecc.ECKeyPair
|
||||||
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
|
import org.session.libsignal.utilities.logging.Log
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
|
class DataExtractionNotification(): ControlMessage() {
|
||||||
|
var kind: Kind? = null
|
||||||
|
|
||||||
|
// Kind enum
|
||||||
|
sealed class Kind {
|
||||||
|
class Screenshot() : Kind()
|
||||||
|
class MediaSaved(val timestanp: Long) : Kind()
|
||||||
|
|
||||||
|
val description: String =
|
||||||
|
when(this) {
|
||||||
|
is Screenshot -> "screenshot"
|
||||||
|
is MediaSaved -> "mediaSaved"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "DataExtractionNotification"
|
||||||
|
|
||||||
|
fun fromProto(proto: SignalServiceProtos.Content): DataExtractionNotification? {
|
||||||
|
val dataExtractionNotification = proto.dataExtractionNotification ?: return null
|
||||||
|
val kind: Kind = when(dataExtractionNotification.type) {
|
||||||
|
SignalServiceProtos.DataExtractionNotification.Type.SCREENSHOT -> Kind.Screenshot()
|
||||||
|
SignalServiceProtos.DataExtractionNotification.Type.MEDIA_SAVED -> {
|
||||||
|
val timestamp = if (dataExtractionNotification.hasTimestamp()) dataExtractionNotification.timestamp else return null
|
||||||
|
Kind.MediaSaved(timestamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return DataExtractionNotification(kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//constructor
|
||||||
|
internal constructor(kind: Kind) : this() {
|
||||||
|
this.kind = kind
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Validation
|
||||||
|
override fun isValid(): Boolean {
|
||||||
|
if (!super.isValid()) return false
|
||||||
|
val kind = kind ?: return false
|
||||||
|
return when(kind) {
|
||||||
|
is Kind.Screenshot -> true
|
||||||
|
is Kind.MediaSaved -> kind.timestanp > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
|
val kind = kind
|
||||||
|
if (kind == null) {
|
||||||
|
Log.w(TAG, "Couldn't construct data extraction notification proto from: $this")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val dataExtractionNotification = SignalServiceProtos.DataExtractionNotification.newBuilder()
|
||||||
|
when(kind) {
|
||||||
|
is Kind.Screenshot -> dataExtractionNotification.type = SignalServiceProtos.DataExtractionNotification.Type.SCREENSHOT
|
||||||
|
is Kind.MediaSaved -> {
|
||||||
|
dataExtractionNotification.type = SignalServiceProtos.DataExtractionNotification.Type.MEDIA_SAVED
|
||||||
|
dataExtractionNotification.timestamp = kind.timestanp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val contentProto = SignalServiceProtos.Content.newBuilder()
|
||||||
|
contentProto.dataExtractionNotification = dataExtractionNotification.build()
|
||||||
|
return contentProto.build()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Couldn't construct data extraction notification proto from: $this")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -35,7 +35,7 @@ class ReadReceipt() : ControlMessage() {
|
|||||||
override fun toProto(): SignalServiceProtos.Content? {
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
val timestamps = timestamps
|
val timestamps = timestamps
|
||||||
if (timestamps == null) {
|
if (timestamps == null) {
|
||||||
Log.w(ExpirationTimerUpdate.TAG, "Couldn't construct read receipt proto from: $this")
|
Log.w(TAG, "Couldn't construct read receipt proto from: $this")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val receiptProto = SignalServiceProtos.ReceiptMessage.newBuilder()
|
val receiptProto = SignalServiceProtos.ReceiptMessage.newBuilder()
|
||||||
@ -46,7 +46,7 @@ class ReadReceipt() : ControlMessage() {
|
|||||||
contentProto.receiptMessage = receiptProto.build()
|
contentProto.receiptMessage = receiptProto.build()
|
||||||
return contentProto.build()
|
return contentProto.build()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.w(ExpirationTimerUpdate.TAG, "Couldn't construct read receipt proto from: $this")
|
Log.w(TAG, "Couldn't construct read receipt proto from: $this")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,7 @@ object MessageReceiver {
|
|||||||
val message: Message = ReadReceipt.fromProto(proto) ?:
|
val message: Message = ReadReceipt.fromProto(proto) ?:
|
||||||
TypingIndicator.fromProto(proto) ?:
|
TypingIndicator.fromProto(proto) ?:
|
||||||
ClosedGroupControlMessage.fromProto(proto) ?:
|
ClosedGroupControlMessage.fromProto(proto) ?:
|
||||||
|
DataExtractionNotification.fromProto(proto) ?:
|
||||||
ExpirationTimerUpdate.fromProto(proto) ?:
|
ExpirationTimerUpdate.fromProto(proto) ?:
|
||||||
ConfigurationMessage.fromProto(proto) ?:
|
ConfigurationMessage.fromProto(proto) ?:
|
||||||
VisibleMessage.fromProto(proto) ?: throw Error.UnknownMessage
|
VisibleMessage.fromProto(proto) ?: throw Error.UnknownMessage
|
||||||
|
@ -40,6 +40,7 @@ message Content {
|
|||||||
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 = 82;
|
||||||
}
|
}
|
||||||
|
|
||||||
message ClosedGroupCiphertextMessageWrapper {
|
message ClosedGroupCiphertextMessageWrapper {
|
||||||
@ -56,6 +57,18 @@ message KeyPair {
|
|||||||
required bytes privateKey = 2;
|
required bytes privateKey = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message DataExtractionNotification {
|
||||||
|
|
||||||
|
enum Type {
|
||||||
|
SCREENSHOT = 1;
|
||||||
|
MEDIA_SAVED = 2; // timestamp
|
||||||
|
}
|
||||||
|
|
||||||
|
// @required
|
||||||
|
required Type type = 1;
|
||||||
|
optional uint64 timestamp = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message DataMessage {
|
message DataMessage {
|
||||||
|
|
||||||
enum Flags {
|
enum Flags {
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user