diff --git a/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt b/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt index f482244..01cee71 100644 --- a/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt +++ b/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt @@ -16,31 +16,34 @@ class NativeDialogRepository : DialogRepository { val dialogs = mutableListOf() val dialogPtr = Native.getDialogs() - val dialogCount = Native.dialogCount(dialogPtr) - for (i in 0 until dialogCount) { - dialogs.add( - Dialog( - id = Native.dialogPacked(dialogPtr, i), - title = Native.dialogTitle(dialogPtr, i), - lastMessage = MessagePreview( - sender = Native.dialogSender(dialogPtr, i), - text = Native.dialogText(dialogPtr, i), - date = LocalDateTime.parse( - Native.dialogTime(dialogPtr, i), - DateTimeFormatter.ISO_OFFSET_DATE_TIME + try { + val dialogCount = Native.dialogCount(dialogPtr) + for (i in 0 until dialogCount) { + dialogs.add( + Dialog( + id = Native.dialogPacked(dialogPtr, i), + title = Native.dialogTitle(dialogPtr, i), + lastMessage = MessagePreview( + sender = Native.dialogSender(dialogPtr, i), + text = Native.dialogText(dialogPtr, i), + date = LocalDateTime.parse( + Native.dialogTime(dialogPtr, i), + DateTimeFormatter.ISO_OFFSET_DATE_TIME + ), + ack = when (Native.dialogAck(dialogPtr, i)) { + 0 -> MessageAck.RECEIVED + 1 -> MessageAck.SENT + 2 -> MessageAck.SEEN + else -> MessageAck.RECEIVED + } ), - ack = when (Native.dialogAck(dialogPtr, i)) { - 0 -> MessageAck.RECEIVED - 1 -> MessageAck.SENT - 2 -> MessageAck.SEEN - else -> MessageAck.RECEIVED - } - ), - pinned = Native.dialogPin(dialogPtr, i) != 0 + pinned = Native.dialogPin(dialogPtr, i) != 0 + ) ) - ) + } + } finally { + Native.freeDialogs(dialogPtr) } - Native.freeDialogs(dialogPtr) return dialogs }