# Conflicts:
#	res/values/strings.xml
This commit is contained in:
Anton Chekulaev
2020-09-02 23:47:31 +10:00
6 changed files with 34 additions and 7 deletions

View File

@@ -5,7 +5,6 @@ import android.os.Handler
import android.util.Log
import nl.komponents.kovenant.Promise
import nl.komponents.kovenant.functional.bind
import nl.komponents.kovenant.then
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
import org.thoughtcrime.securesms.database.Address
@@ -34,6 +33,7 @@ import java.util.*
class PublicChatPoller(private val context: Context, private val group: PublicChat) {
private val handler = Handler()
private var hasStarted = false
private var isPollOngoing = false
public var isCaughtUp = false
// region Convenience
@@ -186,12 +186,10 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
}
fun processOutgoingMessage(message: PublicChatMessage) {
val messageServerID = message.serverID ?: return
val isDuplicate = DatabaseFactory.getLokiMessageDatabase(context).getMessageID(messageServerID) != null
if (isDuplicate) { return }
if (message.body.isEmpty() && message.attachments.isEmpty() && message.quote == null) { return }
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
val dataMessage = getDataMessage(message)
SessionMetaProtocol.dropFromTimestampCacheIfNeeded(dataMessage.timestamp)
SessionMetaProtocol.dropFromTimestampCacheIfNeeded(message.serverTimestamp)
val transcript = SentTranscriptMessage(userHexEncodedPublicKey, message.serverTimestamp, dataMessage, dataMessage.expiresInSeconds.toLong(), Collections.singletonMap(userHexEncodedPublicKey, false))
transcript.messageServerID = messageServerID
if (dataMessage.quote.isPresent || (dataMessage.attachments.isPresent && dataMessage.attachments.get().size > 0) || dataMessage.previews.isPresent) {
@@ -212,6 +210,8 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
}
}
}
if (isPollOngoing) { return }
isPollOngoing = true
val userDevices = MultiDeviceProtocol.shared.getAllLinkedDevices(userHexEncodedPublicKey)
var uniqueDevices = setOf<String>()
val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize()
@@ -249,8 +249,10 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
}
}
isCaughtUp = true
isPollOngoing = false
}.fail {
Log.d("Loki", "Failed to get messages for group chat with ID: ${group.channel} on server: ${group.server}.")
isPollOngoing = false
}
}

View File

@@ -23,8 +23,7 @@ object SessionMetaProtocol {
}
@JvmStatic
fun shouldIgnoreMessage(content: SignalServiceContent): Boolean {
val timestamp = content.timestamp
fun shouldIgnoreMessage(timestamp: Long): Boolean {
val shouldIgnoreMessage = timestamps.contains(timestamp)
timestamps.add(timestamp)
return shouldIgnoreMessage