Fix duplicate message handling

This commit is contained in:
nielsandriesse 2020-05-19 14:21:29 +10:00
parent a907d78916
commit 92bf59b5a0
2 changed files with 6 additions and 1 deletions

View File

@ -151,6 +151,7 @@ object FriendRequestProtocol {
// Guard against invalid state transitions
if (threadFRStatus != LokiThreadFriendRequestStatus.REQUEST_SENDING && threadFRStatus != LokiThreadFriendRequestStatus.REQUEST_SENT
&& threadFRStatus != LokiThreadFriendRequestStatus.REQUEST_RECEIVED) { return }
Log.d("Loki", "Accepting friend request from $publicKey.")
lokiThreadDB.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS)
val lastMessageID = getLastMessageID(context, threadID)
if (lastMessageID != null) {
@ -208,6 +209,7 @@ object FriendRequestProtocol {
val lokiThreadDB = DatabaseFactory.getLokiThreadDatabase(context)
val threadFRStatus = lokiThreadDB.getFriendRequestStatus(threadID)
if (canFriendRequestBeAutoAccepted(context, publicKey)) {
Log.d("Loki", "Auto-accepting friend request from $publicKey.")
lokiThreadDB.setFriendRequestStatus(threadID, LokiThreadFriendRequestStatus.FRIENDS)
val lastMessageID = getLastMessageID(context, threadID)
if (lastMessageID != null) {
@ -217,6 +219,7 @@ object FriendRequestProtocol {
val ephemeralMessage = EphemeralMessage.create(publicKey)
ApplicationContext.getInstance(context).jobManager.add(PushEphemeralMessageSendJob(ephemeralMessage))
} else if (threadFRStatus != LokiThreadFriendRequestStatus.FRIENDS) {
Log.d("Loki", "Handling friend request from $publicKey.")
// Checking that the sender of the message isn't already a friend is necessary because otherwise
// the following situation can occur: Alice and Bob are friends. Bob loses his database and his
// friend request status is reset to NONE. Bob now sends Alice a friend request. Alice's thread's

View File

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