mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
TypingIndicator implementation
This commit is contained in:
parent
746df2240a
commit
3a0ba29a72
@ -7,6 +7,16 @@ import org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSende
|
|||||||
|
|
||||||
class ClosedGroupUpdate() : ControlMessage() {
|
class ClosedGroupUpdate() : ControlMessage() {
|
||||||
|
|
||||||
|
// Kind enum
|
||||||
|
sealed class Kind {
|
||||||
|
class New(val groupPublicKey: ByteArray, val name: String, val groupPrivateKey: ByteArray, val senderKeys: Collection<org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey>, val members: Collection<ByteArray>, val admins: Collection<ByteArray>) : Kind()
|
||||||
|
class Info(val groupPublicKey: ByteArray, val name: String, val senderKeys: Collection<org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey>, val members: Collection<ByteArray>, val admins: Collection<ByteArray>) : Kind()
|
||||||
|
class SenderKeyRequest(val groupPublicKey: ByteArray) : Kind()
|
||||||
|
class SenderKey(val groupPublicKey: ByteArray, val senderKey: org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey) : Kind()
|
||||||
|
}
|
||||||
|
|
||||||
|
var kind: Kind? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "ClosedGroupUpdate"
|
const val TAG = "ClosedGroupUpdate"
|
||||||
|
|
||||||
@ -54,16 +64,6 @@ class ClosedGroupUpdate() : ControlMessage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kind enum
|
|
||||||
sealed class Kind {
|
|
||||||
class New(val groupPublicKey: ByteArray, val name: String, val groupPrivateKey: ByteArray, val senderKeys: Collection<org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey>, val members: Collection<ByteArray>, val admins: Collection<ByteArray>) : Kind()
|
|
||||||
class Info(val groupPublicKey: ByteArray, val name: String, val senderKeys: Collection<org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey>, val members: Collection<ByteArray>, val admins: Collection<ByteArray>) : Kind()
|
|
||||||
class SenderKeyRequest(val groupPublicKey: ByteArray) : Kind()
|
|
||||||
class SenderKey(val groupPublicKey: ByteArray, val senderKey: org.session.libsignal.service.loki.protocol.closedgroups.ClosedGroupSenderKey) : Kind()
|
|
||||||
}
|
|
||||||
|
|
||||||
var kind: Kind? = null
|
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
internal constructor(kind: Kind?) : this() {
|
internal constructor(kind: Kind?) : this() {
|
||||||
this.kind = kind
|
this.kind = kind
|
||||||
|
@ -33,7 +33,7 @@ class ReadReceipt() : ControlMessage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toProto(): SignalServiceProtos.Content? {
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
val timestamps = timestamps ?: return null
|
val timestamps = timestamps
|
||||||
if (timestamps == null) {
|
if (timestamps == null) {
|
||||||
Log.w(ExpirationTimerUpdate.TAG, "Couldn't construct read receipt proto from: $this")
|
Log.w(ExpirationTimerUpdate.TAG, "Couldn't construct read receipt proto from: $this")
|
||||||
return null
|
return null
|
||||||
|
@ -1,16 +1,73 @@
|
|||||||
package org.session.libsession.messaging.messages.control
|
package org.session.libsession.messaging.messages.control
|
||||||
|
|
||||||
|
import org.session.libsignal.libsignal.logging.Log
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
|
|
||||||
class TypingIndicator : ControlMessage() {
|
class TypingIndicator() : ControlMessage() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val TAG = "TypingIndicator"
|
||||||
|
|
||||||
fun fromProto(proto: SignalServiceProtos.Content): TypingIndicator? {
|
fun fromProto(proto: SignalServiceProtos.Content): TypingIndicator? {
|
||||||
TODO("Not yet implemented")
|
val typingIndicatorProto = proto.typingMessage ?: return null
|
||||||
|
val kind = Kind.fromProto(typingIndicatorProto.action)
|
||||||
|
return TypingIndicator(kind = kind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kind enum
|
||||||
|
enum class Kind {
|
||||||
|
STARTED,
|
||||||
|
STOPPED,
|
||||||
|
;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun fromProto(proto: SignalServiceProtos.TypingMessage.Action): Kind =
|
||||||
|
when (proto) {
|
||||||
|
SignalServiceProtos.TypingMessage.Action.STARTED -> STARTED
|
||||||
|
SignalServiceProtos.TypingMessage.Action.STOPPED -> STOPPED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toProto(): SignalServiceProtos.TypingMessage.Action {
|
||||||
|
when (this) {
|
||||||
|
STARTED -> return SignalServiceProtos.TypingMessage.Action.STARTED
|
||||||
|
STOPPED -> return SignalServiceProtos.TypingMessage.Action.STOPPED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var kind: Kind? = null
|
||||||
|
|
||||||
|
//constructor
|
||||||
|
internal constructor(kind: Kind) : this() {
|
||||||
|
this.kind = kind
|
||||||
|
}
|
||||||
|
|
||||||
|
// validation
|
||||||
|
override fun isValid(): Boolean {
|
||||||
|
if (!super.isValid()) return false
|
||||||
|
return kind != null
|
||||||
|
}
|
||||||
|
|
||||||
override fun toProto(): SignalServiceProtos.Content? {
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
TODO("Not yet implemented")
|
val timestamp = sentTimestamp
|
||||||
|
val kind = kind
|
||||||
|
if (timestamp == null || kind == null) {
|
||||||
|
Log.w(TAG, "Couldn't construct typing indicator proto from: $this")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
val typingIndicatorProto = SignalServiceProtos.TypingMessage.newBuilder()
|
||||||
|
typingIndicatorProto.timestamp = timestamp
|
||||||
|
typingIndicatorProto.action = kind.toProto()
|
||||||
|
val contentProto = SignalServiceProtos.Content.newBuilder()
|
||||||
|
try {
|
||||||
|
contentProto.typingMessage = typingIndicatorProto.build()
|
||||||
|
return contentProto.build()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Couldn't construct typing indicator proto from: $this")
|
||||||
|
return null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user