Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Merge branch 'molly-7.21'
Browse files Browse the repository at this point in the history
  • Loading branch information
valldrac committed Oct 23, 2024
2 parents f9de755 + a2e744b commit cb04785
Show file tree
Hide file tree
Showing 217 changed files with 18,422 additions and 3,130 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ apply {
from("fix-profm.gradle")
}

val canonicalVersionCode = 1470
val canonicalVersionName = "7.20.2"
val currentHotfixVersion = 1
val canonicalVersionCode = 1476
val canonicalVersionName = "7.21.5"
val currentHotfixVersion = 0
val maxHotfixVersions = 100
val mollyRevision = 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.signal.core.util.Base64
import org.signal.core.util.SqlUtil
import org.signal.core.util.logging.Log
import org.signal.core.util.readFully
import org.signal.libsignal.messagebackup.ComparableBackup
import org.signal.libsignal.messagebackup.MessageBackup
import org.signal.libsignal.zkgroup.profiles.ProfileKey
import org.thoughtcrime.securesms.backup.v2.proto.Frame
import org.thoughtcrime.securesms.backup.v2.stream.PlainTextBackupReader
import org.thoughtcrime.securesms.database.DistributionListTables
import org.thoughtcrime.securesms.database.KeyValueDatabase
import org.thoughtcrime.securesms.database.SignalDatabase
import org.thoughtcrime.securesms.dependencies.AppDependencies
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.recipients.RecipientId
import org.whispersystems.signalservice.api.kbs.MasterKey
import org.whispersystems.signalservice.api.push.ServiceId
import java.io.ByteArrayInputStream
Expand Down Expand Up @@ -263,21 +259,7 @@ class ArchiveImportExportTests {
}

private fun resetAllData() {
// Need to delete these first to prevent foreign key crash
SignalDatabase.rawDatabase.execSQL("DELETE FROM ${DistributionListTables.ListTable.TABLE_NAME}")
SignalDatabase.rawDatabase.execSQL("DELETE FROM ${DistributionListTables.MembershipTable.TABLE_NAME}")

SqlUtil.getAllTables(SignalDatabase.rawDatabase)
.filterNot { it.contains("sqlite") || it.contains("fts") || it.startsWith("emoji_search_") } // If we delete these we'll corrupt the DB
.sorted()
.forEach { table ->
SignalDatabase.rawDatabase.execSQL("DELETE FROM $table")
SqlUtil.resetAutoIncrementValue(SignalDatabase.rawDatabase, table)
}

AppDependencies.recipientCache.clear()
AppDependencies.recipientCache.clearSelf()
RecipientId.clearCache()
// All the main database stuff is reset as a normal part of importing

KeyValueDatabase.getInstance(AppDependencies.application).clear()
SignalStore.resetCache()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright 2024 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/

package org.thoughtcrime.securesms.database

import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.signal.core.util.deleteAll
import org.thoughtcrime.securesms.components.settings.app.chats.folders.ChatFolderRecord
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.recipients.RecipientId
import org.thoughtcrime.securesms.testing.SignalActivityRule

@RunWith(AndroidJUnit4::class)
class ChatFolderTablesTest {

@get:Rule
val harness = SignalActivityRule()

private lateinit var alice: RecipientId
private lateinit var bob: RecipientId
private lateinit var charlie: RecipientId

private lateinit var folder1: ChatFolderRecord
private lateinit var folder2: ChatFolderRecord
private lateinit var folder3: ChatFolderRecord

private var aliceThread: Long = 0
private var bobThread: Long = 0
private var charlieThread: Long = 0

@Before
fun setUp() {
alice = harness.others[1]
bob = harness.others[2]
charlie = harness.others[3]

aliceThread = SignalDatabase.threads.getOrCreateThreadIdFor(Recipient.resolved(alice))
bobThread = SignalDatabase.threads.getOrCreateThreadIdFor(Recipient.resolved(bob))
charlieThread = SignalDatabase.threads.getOrCreateThreadIdFor(Recipient.resolved(charlie))

folder1 = ChatFolderRecord(
id = 2,
name = "folder1",
position = 1,
includedChats = listOf(aliceThread, bobThread),
excludedChats = listOf(charlieThread),
showUnread = true,
showMutedChats = true,
showIndividualChats = true,
folderType = ChatFolderRecord.FolderType.CUSTOM
)

folder2 = ChatFolderRecord(
name = "folder2",
includedChats = listOf(bobThread),
showUnread = true,
showMutedChats = true,
showIndividualChats = true,
folderType = ChatFolderRecord.FolderType.INDIVIDUAL
)

folder3 = ChatFolderRecord(
name = "folder3",
includedChats = listOf(bobThread),
excludedChats = listOf(aliceThread, charlieThread),
showUnread = true,
showMutedChats = true,
showGroupChats = true,
isMuted = true,
folderType = ChatFolderRecord.FolderType.GROUP
)

SignalDatabase.chatFolders.writableDatabase.deleteAll(ChatFolderTables.ChatFolderTable.TABLE_NAME)
SignalDatabase.chatFolders.writableDatabase.deleteAll(ChatFolderTables.ChatFolderMembershipTable.TABLE_NAME)
}

@Test
fun givenChatFolder_whenIGetFolder_thenIExpectFolderWithChats() {
SignalDatabase.chatFolders.createFolder(folder1)
val actualFolders = SignalDatabase.chatFolders.getChatFolders()

assertEquals(listOf(folder1), actualFolders)
}

@Test
fun givenChatFolder_whenIUpdateFolder_thenIExpectUpdatedFolderWithChats() {
SignalDatabase.chatFolders.createFolder(folder2)
val folder = SignalDatabase.chatFolders.getChatFolders().first()
val updatedFolder = folder.copy(
name = "updatedFolder2",
position = 1,
isMuted = true,
includedChats = listOf(aliceThread, charlieThread),
excludedChats = listOf(bobThread)
)
SignalDatabase.chatFolders.updateFolder(updatedFolder)

val actualFolder = SignalDatabase.chatFolders.getChatFolders().first()

assertEquals(updatedFolder, actualFolder)
}

@Test
fun givenADeletedChatFolder_whenIGetFolders_thenIExpectAListWithoutThatFolder() {
SignalDatabase.chatFolders.createFolder(folder1)
SignalDatabase.chatFolders.createFolder(folder2)
val folders = SignalDatabase.chatFolders.getChatFolders()
SignalDatabase.chatFolders.deleteChatFolder(folders.last())

val actualFolders = SignalDatabase.chatFolders.getChatFolders()

assertEquals(listOf(folder1), actualFolders)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@
package org.thoughtcrime.securesms.database

import androidx.test.platform.app.InstrumentationRegistry
import io.mockk.every
import io.mockk.mockkStatic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.thoughtcrime.securesms.components.settings.app.chats.folders.ChatFolderRecord
import org.thoughtcrime.securesms.conversationlist.model.ConversationFilter
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.testing.SignalDatabaseRule
import org.thoughtcrime.securesms.util.RemoteConfig
import org.whispersystems.signalservice.api.push.ServiceId.ACI
import java.util.UUID

Expand All @@ -25,9 +29,14 @@ class ThreadTableTest_active {
val databaseRule = SignalDatabaseRule()

private lateinit var recipient: Recipient
private val allChats: ChatFolderRecord = ChatFolderRecord(folderType = ChatFolderRecord.FolderType.ALL)

@Before
fun setUp() {
mockkStatic(RemoteConfig::class)

every { RemoteConfig.showChatFolders } returns true

recipient = Recipient.resolved(SignalDatabase.recipients.getOrInsertFromServiceId(ACI.from(UUID.randomUUID())))
}

Expand All @@ -41,7 +50,8 @@ class ThreadTableTest_active {
ConversationFilter.OFF,
false,
0,
10
10,
allChats
).use { threads ->
assertEquals(1, threads.count)

Expand All @@ -63,7 +73,8 @@ class ThreadTableTest_active {
ConversationFilter.OFF,
false,
0,
10
10,
allChats
).use { threads ->
assertEquals(0, threads.count)
}
Expand All @@ -83,7 +94,8 @@ class ThreadTableTest_active {
ConversationFilter.OFF,
false,
0,
10
10,
allChats
).use { threads ->
assertEquals(0, threads.count)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.thoughtcrime.securesms.database

import io.mockk.every
import io.mockk.mockkStatic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.signal.core.util.CursorUtil
import org.thoughtcrime.securesms.components.settings.app.chats.folders.ChatFolderRecord
import org.thoughtcrime.securesms.conversationlist.model.ConversationFilter
import org.thoughtcrime.securesms.recipients.Recipient
import org.thoughtcrime.securesms.testing.SignalDatabaseRule
import org.thoughtcrime.securesms.util.RemoteConfig
import org.whispersystems.signalservice.api.push.ServiceId.ACI
import java.util.UUID

Expand All @@ -20,9 +24,14 @@ class ThreadTableTest_pinned {
val databaseRule = SignalDatabaseRule()

private lateinit var recipient: Recipient
private val allChats: ChatFolderRecord = ChatFolderRecord(folderType = ChatFolderRecord.FolderType.ALL)

@Before
fun setUp() {
mockkStatic(RemoteConfig::class)

every { RemoteConfig.showChatFolders } returns true

recipient = Recipient.resolved(SignalDatabase.recipients.getOrInsertFromServiceId(ACI.from(UUID.randomUUID())))
}

Expand Down Expand Up @@ -52,7 +61,7 @@ class ThreadTableTest_pinned {
SignalDatabase.messages.deleteMessage(messageId)

// THEN
val unarchivedCount = SignalDatabase.threads.getUnarchivedConversationListCount(ConversationFilter.OFF)
val unarchivedCount = SignalDatabase.threads.getUnarchivedConversationListCount(ConversationFilter.OFF, allChats)
assertEquals(1, unarchivedCount)
}

Expand All @@ -67,7 +76,7 @@ class ThreadTableTest_pinned {
SignalDatabase.messages.deleteMessage(messageId)

// THEN
SignalDatabase.threads.getUnarchivedConversationList(ConversationFilter.OFF, true, 0, 1).use {
SignalDatabase.threads.getUnarchivedConversationList(ConversationFilter.OFF, true, 0, 1, allChats).use {
it.moveToFirst()
assertEquals(threadId, CursorUtil.requireLong(it, ThreadTable.ID))
}
Expand Down
Loading

0 comments on commit cb04785

Please sign in to comment.