mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +00:00
Merge branch 'refactor' of https://github.com/RyanRory/loki-messenger-android into refactor
This commit is contained in:
commit
9afb32d3a2
@ -2,7 +2,7 @@ package org.session.libsession.messaging.messages
|
|||||||
|
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
|
|
||||||
abstract class Message {
|
abstract class Message<T: com.google.protobuf.MessageOrBuilder?> {
|
||||||
|
|
||||||
var id: String? = null
|
var id: String? = null
|
||||||
var threadID: String? = null
|
var threadID: String? = null
|
||||||
@ -21,6 +21,6 @@ abstract class Message {
|
|||||||
return sender != null && recipient != null
|
return sender != null && recipient != null
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun toProto(): SignalServiceProtos.Content?
|
abstract fun toProto(): T
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package org.session.libsession.messaging.messages.control
|
package org.session.libsession.messaging.messages.control
|
||||||
|
|
||||||
import org.session.libsession.messaging.messages.Message
|
import org.session.libsession.messaging.messages.Message
|
||||||
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
|
|
||||||
abstract class ControlMessage : Message() {
|
abstract class ControlMessage : Message<SignalServiceProtos.Content?>() {
|
||||||
}
|
}
|
@ -63,7 +63,7 @@ class Attachment : VisibleMessageProto<SignalServiceProtos.AttachmentPointer?>()
|
|||||||
return (contentType != null && kind != null && size != null && sizeInBytes != null && url != null)
|
return (contentType != null && kind != null && size != null && sizeInBytes != null && url != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toProto(transaction: String): SignalServiceProtos.AttachmentPointer? {
|
override fun toProto(): SignalServiceProtos.AttachmentPointer? {
|
||||||
TODO("Not implemented")
|
TODO("Not implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ class Contact : VisibleMessageProto<SignalServiceProtos.DataMessage.Contact?>()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Contact? {
|
override fun toProto(): SignalServiceProtos.DataMessage.Contact? {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,7 +33,7 @@ class LinkPreview() : VisibleMessageProto<SignalServiceProtos.DataMessage.Previe
|
|||||||
return (title != null && url != null && attachmentID != null)
|
return (title != null && url != null && attachmentID != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Preview? {
|
override fun toProto(): SignalServiceProtos.DataMessage.Preview? {
|
||||||
val url = url
|
val url = url
|
||||||
if (url == null) {
|
if (url == null) {
|
||||||
Log.w(TAG, "Couldn't construct link preview proto from: $this")
|
Log.w(TAG, "Couldn't construct link preview proto from: $this")
|
||||||
|
@ -35,11 +35,7 @@ class Profile() : VisibleMessageProto<SignalServiceProtos.DataMessage?>() {
|
|||||||
this.profilePictureURL = profilePictureURL
|
this.profilePictureURL = profilePictureURL
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toSSProto(): SignalServiceProtos.DataMessage? {
|
override fun toProto(): SignalServiceProtos.DataMessage? {
|
||||||
return this.toProto("")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toProto(transaction: String): SignalServiceProtos.DataMessage? {
|
|
||||||
val displayName = displayName
|
val displayName = displayName
|
||||||
if (displayName == null) {
|
if (displayName == null) {
|
||||||
Log.w(TAG, "Couldn't construct link preview proto from: $this")
|
Log.w(TAG, "Couldn't construct link preview proto from: $this")
|
||||||
|
@ -36,7 +36,7 @@ class Quote() : VisibleMessageProto<SignalServiceProtos.DataMessage.Quote?>() {
|
|||||||
return (timestamp != null && publicKey != null)
|
return (timestamp != null && publicKey != null)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toProto(transaction: String): SignalServiceProtos.DataMessage.Quote? {
|
override fun toProto(): SignalServiceProtos.DataMessage.Quote? {
|
||||||
val timestamp = timestamp
|
val timestamp = timestamp
|
||||||
val publicKey = publicKey
|
val publicKey = publicKey
|
||||||
if (timestamp == null || publicKey == null) {
|
if (timestamp == null || publicKey == null) {
|
||||||
@ -47,7 +47,7 @@ class Quote() : VisibleMessageProto<SignalServiceProtos.DataMessage.Quote?>() {
|
|||||||
quoteProto.id = timestamp
|
quoteProto.id = timestamp
|
||||||
quoteProto.author = publicKey
|
quoteProto.author = publicKey
|
||||||
text?.let { quoteProto.text = text }
|
text?.let { quoteProto.text = text }
|
||||||
addAttachmentsIfNeeded(quoteProto, transaction)
|
addAttachmentsIfNeeded(quoteProto)
|
||||||
// Build
|
// Build
|
||||||
try {
|
try {
|
||||||
return quoteProto.build()
|
return quoteProto.build()
|
||||||
@ -57,7 +57,7 @@ class Quote() : VisibleMessageProto<SignalServiceProtos.DataMessage.Quote?>() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder, transaction: String) {
|
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder) {
|
||||||
val attachmentID = attachmentID ?: return
|
val attachmentID = attachmentID ?: return
|
||||||
//TODO databas stuff
|
//TODO databas stuff
|
||||||
val quotedAttachmentProto = SignalServiceProtos.DataMessage.Quote.QuotedAttachment.newBuilder()
|
val quotedAttachmentProto = SignalServiceProtos.DataMessage.Quote.QuotedAttachment.newBuilder()
|
||||||
|
@ -46,13 +46,13 @@ class VisibleMessage() : VisibleMessageProto<SignalServiceProtos.Content?>() {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toProto(transaction: String): SignalServiceProtos.Content? {
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
val proto = SignalServiceProtos.Content.newBuilder()
|
val proto = SignalServiceProtos.Content.newBuilder()
|
||||||
var attachmentIDs = this.attachmentIDs
|
var attachmentIDs = this.attachmentIDs
|
||||||
val dataMessage: SignalServiceProtos.DataMessage.Builder
|
val dataMessage: SignalServiceProtos.DataMessage.Builder
|
||||||
// Profile
|
// Profile
|
||||||
val profile = profile
|
val profile = profile
|
||||||
val profileProto = profile?.toSSProto()
|
val profileProto = profile?.toProto()
|
||||||
if (profileProto != null) {
|
if (profileProto != null) {
|
||||||
dataMessage = profileProto.toBuilder()
|
dataMessage = profileProto.toBuilder()
|
||||||
} else {
|
} else {
|
||||||
@ -68,7 +68,7 @@ class VisibleMessage() : VisibleMessageProto<SignalServiceProtos.Content?>() {
|
|||||||
}
|
}
|
||||||
val quote = quote
|
val quote = quote
|
||||||
quote?.let {
|
quote?.let {
|
||||||
val quoteProto = quote.toProto(transaction)
|
val quoteProto = quote.toProto()
|
||||||
if (quoteProto != null) dataMessage.quote = quoteProto
|
if (quoteProto != null) dataMessage.quote = quoteProto
|
||||||
}
|
}
|
||||||
//Link preview
|
//Link preview
|
||||||
@ -79,7 +79,7 @@ class VisibleMessage() : VisibleMessageProto<SignalServiceProtos.Content?>() {
|
|||||||
}
|
}
|
||||||
val linkPreview = linkPreview
|
val linkPreview = linkPreview
|
||||||
linkPreview?.let {
|
linkPreview?.let {
|
||||||
val linkPreviewProto = linkPreview.toProto(transaction)
|
val linkPreviewProto = linkPreview.toProto()
|
||||||
linkPreviewProto?.let {
|
linkPreviewProto?.let {
|
||||||
dataMessage.addAllPreview(listOf(linkPreviewProto))
|
dataMessage.addAllPreview(listOf(linkPreviewProto))
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
package org.session.libsession.messaging.messages.visible
|
package org.session.libsession.messaging.messages.visible
|
||||||
|
|
||||||
import org.session.libsession.messaging.messages.Message
|
import org.session.libsession.messaging.messages.Message
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
|
||||||
|
|
||||||
abstract class VisibleMessageProto<out T: com.google.protobuf.MessageOrBuilder?> : Message() {
|
abstract class VisibleMessageProto<T: com.google.protobuf.MessageOrBuilder?> : Message<T>() {
|
||||||
|
|
||||||
abstract fun toProto(transaction: String): T
|
|
||||||
|
|
||||||
final override fun toProto(): SignalServiceProtos.Content? {
|
|
||||||
//we don't need to implement this method in subclasses
|
|
||||||
//TODO it just needs an equivalent to swift: preconditionFailure("Use toProto(using:) if that exists...
|
|
||||||
TODO("Not implemented")
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user