Merge pull request #311 from RyanRory/open-group-missing-messages

Fix Missing Messages in Open Groups
This commit is contained in:
Niels Andriesse 2020-09-02 16:13:15 +10:00 committed by GitHub
commit 2866bdd0f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

View File

@ -834,6 +834,8 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
public long handleSynchronizeSentMediaMessage(@NonNull SentTranscriptMessage message) public long handleSynchronizeSentMediaMessage(@NonNull SentTranscriptMessage message)
throws MmsException throws MmsException
{ {
if (SessionMetaProtocol.shouldIgnoreMessage(message.getTimestamp())) { return -1; }
MmsDatabase database = DatabaseFactory.getMmsDatabase(context); MmsDatabase database = DatabaseFactory.getMmsDatabase(context);
Recipient recipients = getSyncMessageMasterDestination(message); Recipient recipients = getSyncMessageMasterDestination(message);
Optional<QuoteModel> quote = getValidatedQuote(message.getMessage().getQuote()); Optional<QuoteModel> quote = getValidatedQuote(message.getMessage().getQuote());
@ -1002,6 +1004,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
public long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message) public long handleSynchronizeSentTextMessage(@NonNull SentTranscriptMessage message)
throws MmsException throws MmsException
{ {
if (SessionMetaProtocol.shouldIgnoreMessage(message.getTimestamp())) { return -1; }
Recipient recipient = getSyncMessageMasterDestination(message); Recipient recipient = getSyncMessageMasterDestination(message);
String body = message.getMessage().getBody().or(""); String body = message.getMessage().getBody().or("");
@ -1459,7 +1462,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
return true; return true;
} }
if (SessionMetaProtocol.shouldIgnoreMessage(content)) { if (SessionMetaProtocol.shouldIgnoreMessage(content.getTimestamp())) {
Log.d("Loki", "Ignoring duplicate message."); Log.d("Loki", "Ignoring duplicate message.");
return true; return true;
} }

View File

@ -34,6 +34,7 @@ import java.util.*
class PublicChatPoller(private val context: Context, private val group: PublicChat) { class PublicChatPoller(private val context: Context, private val group: PublicChat) {
private val handler = Handler() private val handler = Handler()
private var hasStarted = false private var hasStarted = false
private var isPolling = false
public var isCaughtUp = false public var isCaughtUp = false
// region Convenience // region Convenience
@ -186,12 +187,10 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
} }
fun processOutgoingMessage(message: PublicChatMessage) { fun processOutgoingMessage(message: PublicChatMessage) {
val messageServerID = message.serverID ?: return 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 } if (message.body.isEmpty() && message.attachments.isEmpty() && message.quote == null) { return }
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context) val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
val dataMessage = getDataMessage(message) 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)) val transcript = SentTranscriptMessage(userHexEncodedPublicKey, message.serverTimestamp, dataMessage, dataMessage.expiresInSeconds.toLong(), Collections.singletonMap(userHexEncodedPublicKey, false))
transcript.messageServerID = messageServerID transcript.messageServerID = messageServerID
if (dataMessage.quote.isPresent || (dataMessage.attachments.isPresent && dataMessage.attachments.get().size > 0) || dataMessage.previews.isPresent) { if (dataMessage.quote.isPresent || (dataMessage.attachments.isPresent && dataMessage.attachments.get().size > 0) || dataMessage.previews.isPresent) {
@ -212,6 +211,8 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
} }
} }
} }
if (isPolling) { return }
isPolling = true
val userDevices = MultiDeviceProtocol.shared.getAllLinkedDevices(userHexEncodedPublicKey) val userDevices = MultiDeviceProtocol.shared.getAllLinkedDevices(userHexEncodedPublicKey)
var uniqueDevices = setOf<String>() var uniqueDevices = setOf<String>()
val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize() val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize()
@ -249,8 +250,10 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
} }
} }
isCaughtUp = true isCaughtUp = true
isPolling = false
}.fail { }.fail {
Log.d("Loki", "Failed to get messages for group chat with ID: ${group.channel} on server: ${group.server}.") Log.d("Loki", "Failed to get messages for group chat with ID: ${group.channel} on server: ${group.server}.")
isPolling = false
} }
} }

View File

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