mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-09 05:50:15 +01:00
fix SQL handling of threads with null values + add test for it
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
43292943e7
commit
ae2d3d2a76
@ -174,6 +174,84 @@ class ChatBlocksDaoTest {
|
|||||||
assertEquals(5, results.first().size)
|
assertEquals(5, results.first().size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testGetConnectedChatBlocksWithThreadsScenario() =
|
||||||
|
runTest {
|
||||||
|
val user = createUserEntity("account1", "Account 1")
|
||||||
|
usersDao.saveUser(user)
|
||||||
|
val account1 = usersDao.getUserWithUserId("account1").blockingGet()
|
||||||
|
|
||||||
|
conversationsDao.upsertConversations(
|
||||||
|
listOf(
|
||||||
|
createConversationEntity(
|
||||||
|
accountId = account1.id,
|
||||||
|
"abc",
|
||||||
|
roomName = "Conversation One"
|
||||||
|
),
|
||||||
|
createConversationEntity(
|
||||||
|
accountId = account1.id,
|
||||||
|
"def",
|
||||||
|
roomName = "Conversation Two"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val conversation1 = conversationsDao.getConversationsForUser(account1.id).first()[0]
|
||||||
|
|
||||||
|
val searchedChatBlock = ChatBlockEntity(
|
||||||
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
|
threadId = 123,
|
||||||
|
oldestMessageId = 50,
|
||||||
|
newestMessageId = 60,
|
||||||
|
hasHistory = true
|
||||||
|
)
|
||||||
|
|
||||||
|
val chatBlockOverlap1 = ChatBlockEntity(
|
||||||
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
|
threadId = null,
|
||||||
|
oldestMessageId = 45,
|
||||||
|
newestMessageId = 55,
|
||||||
|
hasHistory = true
|
||||||
|
)
|
||||||
|
|
||||||
|
val chatBlockOverlap2 = ChatBlockEntity(
|
||||||
|
internalConversationId = conversation1.internalId,
|
||||||
|
accountId = conversation1.accountId,
|
||||||
|
token = conversation1.token,
|
||||||
|
threadId = 123,
|
||||||
|
oldestMessageId = 59,
|
||||||
|
newestMessageId = 70,
|
||||||
|
hasHistory = true
|
||||||
|
)
|
||||||
|
|
||||||
|
chatBlocksDao.upsertChatBlock(searchedChatBlock)
|
||||||
|
|
||||||
|
chatBlocksDao.upsertChatBlock(chatBlockOverlap1)
|
||||||
|
chatBlocksDao.upsertChatBlock(chatBlockOverlap2)
|
||||||
|
|
||||||
|
val resultsForThreadIdNull = chatBlocksDao.getConnectedChatBlocks(
|
||||||
|
internalConversationId = conversation1.internalId,
|
||||||
|
threadId = null,
|
||||||
|
oldestMessageId = searchedChatBlock.oldestMessageId,
|
||||||
|
newestMessageId = searchedChatBlock.newestMessageId
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(1, resultsForThreadIdNull.first().size)
|
||||||
|
|
||||||
|
val resultsForThreadId123 = chatBlocksDao.getConnectedChatBlocks(
|
||||||
|
internalConversationId = conversation1.internalId,
|
||||||
|
threadId = 123,
|
||||||
|
oldestMessageId = searchedChatBlock.oldestMessageId,
|
||||||
|
newestMessageId = searchedChatBlock.newestMessageId
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(2, resultsForThreadId123.first().size)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createUserEntity(userId: String, userName: String) =
|
private fun createUserEntity(userId: String, userName: String) =
|
||||||
UserEntity(
|
UserEntity(
|
||||||
userId = userId,
|
userId = userId,
|
||||||
|
@ -52,7 +52,7 @@ interface ChatBlocksDao {
|
|||||||
SELECT *
|
SELECT *
|
||||||
FROM ChatBlocks
|
FROM ChatBlocks
|
||||||
WHERE internalConversationId in (:internalConversationId)
|
WHERE internalConversationId in (:internalConversationId)
|
||||||
AND (:threadId IS NULL OR threadId = :threadId)
|
AND (threadId = :threadId OR (threadId IS NULL AND :threadId IS NULL))
|
||||||
AND oldestMessageId <= :messageId
|
AND oldestMessageId <= :messageId
|
||||||
AND newestMessageId >= :messageId
|
AND newestMessageId >= :messageId
|
||||||
ORDER BY newestMessageId ASC
|
ORDER BY newestMessageId ASC
|
||||||
@ -69,7 +69,7 @@ interface ChatBlocksDao {
|
|||||||
SELECT *
|
SELECT *
|
||||||
FROM ChatBlocks
|
FROM ChatBlocks
|
||||||
WHERE internalConversationId = :internalConversationId
|
WHERE internalConversationId = :internalConversationId
|
||||||
AND (:threadId IS NULL OR threadId = :threadId)
|
AND (threadId = :threadId OR (threadId IS NULL AND :threadId IS NULL))
|
||||||
AND(
|
AND(
|
||||||
(oldestMessageId <= :oldestMessageId AND newestMessageId >= :oldestMessageId)
|
(oldestMessageId <= :oldestMessageId AND newestMessageId >= :oldestMessageId)
|
||||||
OR
|
OR
|
||||||
@ -92,7 +92,7 @@ interface ChatBlocksDao {
|
|||||||
SELECT MAX(newestMessageId) as max_items
|
SELECT MAX(newestMessageId) as max_items
|
||||||
FROM ChatBlocks
|
FROM ChatBlocks
|
||||||
WHERE internalConversationId = :internalConversationId
|
WHERE internalConversationId = :internalConversationId
|
||||||
AND (:threadId IS NULL OR threadId = :threadId)
|
AND (threadId = :threadId OR (threadId IS NULL AND :threadId IS NULL))
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
fun getNewestMessageIdFromChatBlocks(internalConversationId: String, threadId: Long?): Long
|
fun getNewestMessageIdFromChatBlocks(internalConversationId: String, threadId: Long?): Long
|
||||||
|
Loading…
Reference in New Issue
Block a user