Talaria/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt

76 lines
2.5 KiB
Kotlin

package dev.lonami.talaria.data
import dev.lonami.talaria.bindings.Native
import dev.lonami.talaria.models.Dialog
import dev.lonami.talaria.models.MessageAck
import dev.lonami.talaria.models.MessagePreview
import java.time.LocalDateTime
interface DialogRepository {
fun loadDialogs(): List<Dialog>;
}
class NativeDialogRepository : DialogRepository {
override fun loadDialogs(): List<Dialog> {
val dialogs = mutableListOf<Dialog>()
val dialogPtr = Native.getDialogs()
val dialogCount = Native.dialogCount(dialogPtr)
for (i in 0 until dialogCount) {
dialogs.add(
Dialog(
title = Native.dialogTitle(dialogPtr, i),
lastMessage = MessagePreview(
sender = "",
text = Native.dialogPacked(dialogPtr, i),
date = LocalDateTime.now(),
ack = MessageAck.RECEIVED
),
pinned = false
)
)
}
Native.freeDialogs(dialogPtr)
return dialogs
}
}
class MockDialogRepository : DialogRepository {
override fun loadDialogs(): List<Dialog> {
val dialogs = mutableListOf<Dialog>()
for (i in 0 until 10) {
dialogs.add(
Dialog(
title = "Sample Dialog $i",
lastMessage = if (i % 4 == 3) {
null
} else {
MessagePreview(
sender = if (i % 2 == 0) {
"Sender A"
} else {
"Sender B"
},
text = if (i % 3 == 2) {
"Very Long Sample Message $i, with a Lot of Text, which makes it hard to Preview"
} else {
"Sample Message $i"
},
date = LocalDateTime.now(),
ack = when (i % 3) {
0 -> MessageAck.RECEIVED
1 -> MessageAck.SENT
2 -> MessageAck.SEEN
else -> throw RuntimeException()
}
)
},
pinned = i < 4
)
)
}
return dialogs
}
}