mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 20:27:47 +00:00
Cleanup
This commit is contained in:
@@ -144,7 +144,6 @@ class BatchMessageReceiveJob(
|
||||
runBlocking(Dispatchers.IO) {
|
||||
|
||||
fun processMessages(threadId: Long, messages: List<ParsedMessage>) = async {
|
||||
Log.d(TAG, "processMessages() threadId = $threadId, messages = $messages")
|
||||
// The LinkedHashMap should preserve insertion order
|
||||
val messageIds = linkedMapOf<Long, Pair<Boolean, Boolean>>()
|
||||
val myLastSeen = storage.getLastSeen(threadId)
|
||||
|
@@ -6,7 +6,6 @@ import org.session.libsession.database.StorageProtocol
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.messages.control.ExpirationTimerUpdate
|
||||
import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.GroupUtil
|
||||
import org.session.libsignal.protos.SignalServiceProtos
|
||||
import org.session.libsignal.protos.SignalServiceProtos.Content.ExpirationType
|
||||
@@ -43,13 +42,11 @@ abstract class Message {
|
||||
}
|
||||
}
|
||||
|
||||
open fun isValid(): Boolean {
|
||||
val sentTimestamp = sentTimestamp
|
||||
if (sentTimestamp != null && sentTimestamp <= 0) { return false }
|
||||
val receivedTimestamp = receivedTimestamp
|
||||
if (receivedTimestamp != null && receivedTimestamp <= 0) { return false }
|
||||
return sender != null && recipient != null
|
||||
}
|
||||
open fun isValid(): Boolean =
|
||||
sentTimestamp?.let { it > 0 } == true
|
||||
&& receivedTimestamp?.let { it > 0 } == true
|
||||
&& sender != null
|
||||
&& recipient != null
|
||||
|
||||
abstract fun toProto(): SignalServiceProtos.Content?
|
||||
|
||||
@@ -60,18 +57,17 @@ abstract class Message {
|
||||
}.build()
|
||||
}
|
||||
|
||||
fun SignalServiceProtos.Content.Builder.applyExpiryMode(): SignalServiceProtos.Content.Builder {
|
||||
fun SignalServiceProtos.Content.Builder.applyExpiryMode() = apply {
|
||||
expirationTimer = expiryMode.expirySeconds.toInt()
|
||||
expirationType = when (expiryMode) {
|
||||
is ExpiryMode.AfterSend -> ExpirationType.DELETE_AFTER_SEND
|
||||
is ExpiryMode.AfterRead -> ExpirationType.DELETE_AFTER_READ
|
||||
else -> ExpirationType.UNKNOWN
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified M: Message> M.copyExpiration(proto: SignalServiceProtos.Content): M {
|
||||
inline fun <reified M: Message> M.copyExpiration(proto: SignalServiceProtos.Content): M = apply {
|
||||
(proto.takeIf { it.hasExpirationTimer() }?.expirationTimer ?: proto.dataMessage?.expireTimer)?.let { duration ->
|
||||
expiryMode = when (proto.expirationType.takeIf { duration > 0 }) {
|
||||
ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong())
|
||||
@@ -79,23 +75,21 @@ inline fun <reified M: Message> M.copyExpiration(proto: SignalServiceProtos.Cont
|
||||
else -> ExpiryMode.NONE
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
fun SignalServiceProtos.Content.expiryMode(): ExpiryMode =
|
||||
(takeIf { it.hasExpirationTimer() }?.expirationTimer ?: dataMessage?.expireTimer)?.let { duration ->
|
||||
when (expirationType.takeIf { duration > 0 }) {
|
||||
ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong())
|
||||
ExpirationType.DELETE_AFTER_READ -> ExpiryMode.AfterRead(duration.toLong())
|
||||
else -> ExpiryMode.NONE
|
||||
}
|
||||
} ?: ExpiryMode.NONE
|
||||
(takeIf { it.hasExpirationTimer() }?.expirationTimer ?: dataMessage?.expireTimer)?.let { duration ->
|
||||
when (expirationType.takeIf { duration > 0 }) {
|
||||
ExpirationType.DELETE_AFTER_SEND -> ExpiryMode.AfterSend(duration.toLong())
|
||||
ExpirationType.DELETE_AFTER_READ -> ExpiryMode.AfterRead(duration.toLong())
|
||||
else -> ExpiryMode.NONE
|
||||
}
|
||||
} ?: ExpiryMode.NONE
|
||||
|
||||
/**
|
||||
* Apply ExpiryMode from the current setting.
|
||||
*/
|
||||
inline fun <reified M: Message> M.applyExpiryMode(thread: Long): M {
|
||||
inline fun <reified M: Message> M.applyExpiryMode(thread: Long): M = apply {
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
expiryMode = storage.getExpirationConfiguration(thread)?.expiryMode?.coerceSendToRead(coerceDisappearAfterSendToRead) ?: ExpiryMode.NONE
|
||||
return this
|
||||
}
|
||||
|
@@ -4,9 +4,7 @@ import org.session.libsession.messaging.messages.copyExpiration
|
||||
import org.session.libsignal.protos.SignalServiceProtos
|
||||
import org.session.libsignal.utilities.Log
|
||||
|
||||
class UnsendRequest(): ControlMessage() {
|
||||
var timestamp: Long? = null
|
||||
var author: String? = null
|
||||
class UnsendRequest(var timestamp: Long? = null, var author: String? = null): ControlMessage() {
|
||||
|
||||
override val isSelfSendValid: Boolean = true
|
||||
|
||||
@@ -20,18 +18,8 @@ class UnsendRequest(): ControlMessage() {
|
||||
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)
|
||||
.copyExpiration(proto)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(timestamp: Long, author: String) : this() {
|
||||
this.timestamp = timestamp
|
||||
this.author = author
|
||||
fun fromProto(proto: SignalServiceProtos.Content): UnsendRequest? =
|
||||
proto.takeIf { it.hasUnsendRequest() }?.unsendRequest?.run { UnsendRequest(timestamp, author) }?.copyExpiration(proto)
|
||||
}
|
||||
|
||||
override fun toProto(): SignalServiceProtos.Content? {
|
||||
|
@@ -108,27 +108,23 @@ object GroupUtil {
|
||||
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
fun doubleDecodeGroupId(groupID: String): String {
|
||||
return Hex.toStringCondensed(getDecodedGroupIDAsData(getDecodedGroupID(groupID)))
|
||||
}
|
||||
fun doubleDecodeGroupId(groupID: String): String =
|
||||
Hex.toStringCondensed(getDecodedGroupIDAsData(getDecodedGroupID(groupID)))
|
||||
|
||||
@JvmStatic
|
||||
fun addressToGroupSessionId(address: Address): String {
|
||||
return doubleDecodeGroupId(address.toGroupString())
|
||||
}
|
||||
fun addressToGroupSessionId(address: Address): String =
|
||||
doubleDecodeGroupId(address.toGroupString())
|
||||
|
||||
fun createConfigMemberMap(
|
||||
members: Collection<String>,
|
||||
admins: Collection<String>
|
||||
): Map<String, Boolean> {
|
||||
// Start with admins
|
||||
val memberMap = admins.associate {
|
||||
it to true
|
||||
}.toMutableMap()
|
||||
val memberMap = admins.associateWith { true }.toMutableMap()
|
||||
|
||||
// Add the remaining members (there may be duplicates, so only add ones that aren't already in there from admins)
|
||||
for (member in members) {
|
||||
if (!memberMap.contains(member)) {
|
||||
if (member !in memberMap) {
|
||||
memberMap[member] = false
|
||||
}
|
||||
}
|
||||
|
@@ -46,8 +46,6 @@ class SSKEnvironment(
|
||||
fun startAnyExpiration(timestamp: Long, author: String, expireStartedAt: Long)
|
||||
|
||||
fun maybeStartExpiration(message: Message, startDisappearAfterRead: Boolean = false) {
|
||||
Log.d("MessageExpirationManagerProtocol", "maybeStartExpiration() called with: message = $message, startDisappearAfterRead = $startDisappearAfterRead")
|
||||
|
||||
if (message is ExpirationTimerUpdate && message.isGroup) return
|
||||
|
||||
maybeStartExpiration(
|
||||
@@ -59,8 +57,6 @@ class SSKEnvironment(
|
||||
}
|
||||
|
||||
fun startDisappearAfterRead(timestamp: Long, sender: String) {
|
||||
Log.d("MessageExpirationManagerProtocol", "startDisappearAfterRead() called with: timestamp = $timestamp, sender = $sender")
|
||||
|
||||
startAnyExpiration(
|
||||
timestamp,
|
||||
sender,
|
||||
@@ -69,8 +65,6 @@ class SSKEnvironment(
|
||||
}
|
||||
|
||||
fun maybeStartExpiration(timestamp: Long, sender: String, mode: ExpiryMode, startDisappearAfterRead: Boolean = false) {
|
||||
Log.d("MessageExpirationManagerProtocol", "maybeStartExpiration() called with: timestamp = $timestamp, sender = $sender, mode = $mode, startDisappearAfterRead = $startDisappearAfterRead")
|
||||
|
||||
val expireStartedAt = when (mode) {
|
||||
is ExpiryMode.AfterSend -> timestamp
|
||||
is ExpiryMode.AfterRead -> if (startDisappearAfterRead) nowWithOffset.coerceAtLeast(timestamp + 1) else return
|
||||
|
@@ -2,6 +2,8 @@ package org.session.libsession.utilities
|
||||
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
|
||||
@@ -14,3 +16,7 @@ fun Context.getColorFromAttr(
|
||||
theme.resolveAttribute(attrColor, typedValue, resolveRefs)
|
||||
return typedValue.data
|
||||
}
|
||||
|
||||
inline fun <reified LP: ViewGroup.LayoutParams> View.modifyLayoutParams(function: LP.() -> Unit) {
|
||||
layoutParams = (layoutParams as LP).apply { function() }
|
||||
}
|
||||
|
Reference in New Issue
Block a user