mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-07 13:34:29 +00:00
Refactor
This commit is contained in:
parent
1f7edadc59
commit
140877f4e3
@ -23,6 +23,7 @@ import org.session.libsession.messaging.messages.signal.OutgoingGroupMediaMessag
|
|||||||
import org.session.libsession.messaging.messages.signal.OutgoingMediaMessage
|
import org.session.libsession.messaging.messages.signal.OutgoingMediaMessage
|
||||||
import org.session.libsession.messaging.messages.signal.OutgoingTextMessage
|
import org.session.libsession.messaging.messages.signal.OutgoingTextMessage
|
||||||
import org.session.libsession.messaging.messages.visible.Attachment
|
import org.session.libsession.messaging.messages.visible.Attachment
|
||||||
|
import org.session.libsession.messaging.messages.visible.Profile
|
||||||
import org.session.libsession.messaging.messages.visible.Reaction
|
import org.session.libsession.messaging.messages.visible.Reaction
|
||||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||||
import org.session.libsession.messaging.open_groups.GroupMember
|
import org.session.libsession.messaging.open_groups.GroupMember
|
||||||
@ -69,16 +70,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
return DatabaseComponent.get(context).lokiAPIDatabase().getUserX25519KeyPair()
|
return DatabaseComponent.get(context).lokiAPIDatabase().getUserX25519KeyPair()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getUserDisplayName(): String? {
|
override fun getUserProfile(): Profile {
|
||||||
return TextSecurePreferences.getProfileName(context)
|
val displayName = TextSecurePreferences.getProfileName(context)!!
|
||||||
}
|
val profileKey = ProfileKeyUtil.getProfileKey(context)
|
||||||
|
val profilePictureUrl = TextSecurePreferences.getProfilePictureURL(context)
|
||||||
override fun getUserProfileKey(): ByteArray? {
|
return Profile(displayName, profileKey, profilePictureUrl)
|
||||||
return ProfileKeyUtil.getProfileKey(context)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getUserProfilePictureURL(): String? {
|
|
||||||
return TextSecurePreferences.getProfilePictureURL(context)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setUserProfilePictureURL(newValue: String) {
|
override fun setUserProfilePictureURL(newValue: String) {
|
||||||
|
@ -12,6 +12,7 @@ import org.session.libsession.messaging.messages.Message
|
|||||||
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
||||||
import org.session.libsession.messaging.messages.control.MessageRequestResponse
|
import org.session.libsession.messaging.messages.control.MessageRequestResponse
|
||||||
import org.session.libsession.messaging.messages.visible.Attachment
|
import org.session.libsession.messaging.messages.visible.Attachment
|
||||||
|
import org.session.libsession.messaging.messages.visible.Profile
|
||||||
import org.session.libsession.messaging.messages.visible.Reaction
|
import org.session.libsession.messaging.messages.visible.Reaction
|
||||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||||
import org.session.libsession.messaging.open_groups.GroupMember
|
import org.session.libsession.messaging.open_groups.GroupMember
|
||||||
@ -34,9 +35,7 @@ interface StorageProtocol {
|
|||||||
// General
|
// General
|
||||||
fun getUserPublicKey(): String?
|
fun getUserPublicKey(): String?
|
||||||
fun getUserX25519KeyPair(): ECKeyPair
|
fun getUserX25519KeyPair(): ECKeyPair
|
||||||
fun getUserDisplayName(): String?
|
fun getUserProfile(): Profile
|
||||||
fun getUserProfileKey(): ByteArray?
|
|
||||||
fun getUserProfilePictureURL(): String?
|
|
||||||
fun setUserProfilePictureURL(newProfilePicture: String)
|
fun setUserProfilePictureURL(newProfilePicture: String)
|
||||||
// Signal
|
// Signal
|
||||||
fun getOrGenerateRegistrationID(): Int
|
fun getOrGenerateRegistrationID(): Int
|
||||||
|
@ -5,7 +5,7 @@ import org.session.libsession.messaging.messages.visible.Profile
|
|||||||
import org.session.libsignal.protos.SignalServiceProtos
|
import org.session.libsignal.protos.SignalServiceProtos
|
||||||
import org.session.libsignal.utilities.Log
|
import org.session.libsignal.utilities.Log
|
||||||
|
|
||||||
class MessageRequestResponse(val isApproved: Boolean, val profile: Profile? = null) : ControlMessage() {
|
class MessageRequestResponse(val isApproved: Boolean, var profile: Profile? = null) : ControlMessage() {
|
||||||
|
|
||||||
override val isSelfSendValid: Boolean = true
|
override val isSelfSendValid: Boolean = true
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class Profile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal constructor(displayName: String, profileKey: ByteArray? = null, profilePictureURL: String? = null) : this() {
|
constructor(displayName: String, profileKey: ByteArray? = null, profilePictureURL: String? = null) : this() {
|
||||||
this.displayName = displayName
|
this.displayName = displayName
|
||||||
this.profileKey = profileKey
|
this.profileKey = profileKey
|
||||||
this.profilePictureURL = profilePictureURL
|
this.profilePictureURL = profilePictureURL
|
||||||
|
@ -12,9 +12,9 @@ import org.session.libsession.messaging.messages.control.CallMessage
|
|||||||
import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
|
import org.session.libsession.messaging.messages.control.ClosedGroupControlMessage
|
||||||
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
import org.session.libsession.messaging.messages.control.ConfigurationMessage
|
||||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||||
|
import org.session.libsession.messaging.messages.control.MessageRequestResponse
|
||||||
import org.session.libsession.messaging.messages.control.UnsendRequest
|
import org.session.libsession.messaging.messages.control.UnsendRequest
|
||||||
import org.session.libsession.messaging.messages.visible.LinkPreview
|
import org.session.libsession.messaging.messages.visible.LinkPreview
|
||||||
import org.session.libsession.messaging.messages.visible.Profile
|
|
||||||
import org.session.libsession.messaging.messages.visible.Quote
|
import org.session.libsession.messaging.messages.visible.Quote
|
||||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||||
import org.session.libsession.messaging.open_groups.OpenGroupApi
|
import org.session.libsession.messaging.open_groups.OpenGroupApi
|
||||||
@ -118,14 +118,10 @@ object MessageSender {
|
|||||||
}
|
}
|
||||||
// Attach the user's profile if needed
|
// Attach the user's profile if needed
|
||||||
if (message is VisibleMessage) {
|
if (message is VisibleMessage) {
|
||||||
val displayName = storage.getUserDisplayName()!!
|
message.profile = storage.getUserProfile()
|
||||||
val profileKey = storage.getUserProfileKey()
|
}
|
||||||
val profilePictureUrl = storage.getUserProfilePictureURL()
|
if (message is MessageRequestResponse) {
|
||||||
if (profileKey != null && profilePictureUrl != null) {
|
message.profile = storage.getUserProfile()
|
||||||
message.profile = Profile(displayName, profileKey, profilePictureUrl)
|
|
||||||
} else {
|
|
||||||
message.profile = Profile(displayName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Convert it to protobuf
|
// Convert it to protobuf
|
||||||
val proto = message.toProto() ?: throw Error.ProtoConversionFailed
|
val proto = message.toProto() ?: throw Error.ProtoConversionFailed
|
||||||
@ -257,14 +253,7 @@ object MessageSender {
|
|||||||
try {
|
try {
|
||||||
// Attach the user's profile if needed
|
// Attach the user's profile if needed
|
||||||
if (message is VisibleMessage) {
|
if (message is VisibleMessage) {
|
||||||
val displayName = storage.getUserDisplayName()!!
|
message.profile = storage.getUserProfile()
|
||||||
val profileKey = storage.getUserProfileKey()
|
|
||||||
val profilePictureUrl = storage.getUserProfilePictureURL()
|
|
||||||
if (profileKey != null && profilePictureUrl != null) {
|
|
||||||
message.profile = Profile(displayName, profileKey, profilePictureUrl)
|
|
||||||
} else {
|
|
||||||
message.profile = Profile(displayName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
when (destination) {
|
when (destination) {
|
||||||
is Destination.OpenGroup -> {
|
is Destination.OpenGroup -> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user