From 1a56b03614e5f2b930a60a565d9851cc7be606d9 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 27 Oct 2022 18:08:57 +0200 Subject: [PATCH] Move MessageAck enum to UDL --- .../lonami/talaria/data/DialogRepository.kt | 8 +------- .../dev/lonami/talaria/models/MessageAck.kt | 7 ------- .../lonami/talaria/models/MessagePreview.kt | 1 + .../lonami/talaria/ui/screens/DialogScreen.kt | 2 +- native/src/lib.rs | 19 +++++++++++++------ native/src/talaria.udl | 8 +++++++- 6 files changed, 23 insertions(+), 22 deletions(-) delete mode 100644 app/src/main/java/dev/lonami/talaria/models/MessageAck.kt 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 bdcdcd2..da1eb53 100644 --- a/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt +++ b/app/src/main/java/dev/lonami/talaria/data/DialogRepository.kt @@ -1,7 +1,6 @@ package dev.lonami.talaria.data import dev.lonami.talaria.models.Dialog -import dev.lonami.talaria.models.MessageAck import dev.lonami.talaria.models.MessagePreview import uniffi.talaria.* import java.time.LocalDateTime @@ -30,12 +29,7 @@ class NativeDialogRepository : DialogRepository { dialogTime(dialogPtr, i), DateTimeFormatter.ISO_OFFSET_DATE_TIME ), - ack = when (dialogAck(dialogPtr, i)) { - 0U -> MessageAck.RECEIVED - 1U -> MessageAck.SENT - 2U -> MessageAck.SEEN - else -> MessageAck.RECEIVED - } + ack = dialogAck(dialogPtr, i), ), pinned = dialogPin(dialogPtr, i) != 0U ) diff --git a/app/src/main/java/dev/lonami/talaria/models/MessageAck.kt b/app/src/main/java/dev/lonami/talaria/models/MessageAck.kt deleted file mode 100644 index fc1a7b8..0000000 --- a/app/src/main/java/dev/lonami/talaria/models/MessageAck.kt +++ /dev/null @@ -1,7 +0,0 @@ -package dev.lonami.talaria.models - -enum class MessageAck { - RECEIVED, - SENT, - SEEN, -} diff --git a/app/src/main/java/dev/lonami/talaria/models/MessagePreview.kt b/app/src/main/java/dev/lonami/talaria/models/MessagePreview.kt index 8cbe168..b4c53a0 100644 --- a/app/src/main/java/dev/lonami/talaria/models/MessagePreview.kt +++ b/app/src/main/java/dev/lonami/talaria/models/MessagePreview.kt @@ -1,5 +1,6 @@ package dev.lonami.talaria.models +import uniffi.talaria.MessageAck import java.time.LocalDateTime data class MessagePreview( diff --git a/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt b/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt index 4524ab7..b576c7d 100644 --- a/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt +++ b/app/src/main/java/dev/lonami/talaria/ui/screens/DialogScreen.kt @@ -24,9 +24,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel import dev.lonami.talaria.R import dev.lonami.talaria.data.MockDialogRepository import dev.lonami.talaria.models.Dialog -import dev.lonami.talaria.models.MessageAck import dev.lonami.talaria.ui.state.DialogViewModel import dev.lonami.talaria.ui.theme.TalariaTheme +import uniffi.talaria.MessageAck import java.time.format.DateTimeFormatter import java.time.format.FormatStyle diff --git a/native/src/lib.rs b/native/src/lib.rs index 42605d0..7e7c565 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -45,6 +45,13 @@ static RUNTIME: OnceCell = OnceCell::new(); static CLIENT: OnceCell = OnceCell::new(); static DATABASE: Mutex> = Mutex::new(None); +#[derive(Debug, Clone, Copy)] +pub enum MessageAck { + Received, + Seen, + Sent, +} + fn block_on(future: F) -> F::Output { if RUNTIME.get().is_none() { RUNTIME @@ -318,7 +325,7 @@ pub fn dialogTime(dialogsPtr: u64, index: u32) -> String { } } -pub fn dialogAck(dialogsPtr: u64, index: u32) -> u32 { +pub fn dialogAck(dialogsPtr: u64, index: u32) -> MessageAck { let dialogs = unsafe { &mut *(dialogsPtr as *mut Vec) }; let dialog = &dialogs[index as usize]; @@ -327,18 +334,18 @@ pub fn dialogAck(dialogsPtr: u64, index: u32) -> u32 { match &dialog.dialog { tl::enums::Dialog::Dialog(d) => { if msg.id() <= d.read_inbox_max_id { - 2 + MessageAck::Seen } else { - 1 + MessageAck::Sent } } - tl::enums::Dialog::Folder(_) => 0, + tl::enums::Dialog::Folder(_) => MessageAck::Received, } } else { - 0 + MessageAck::Received } } else { - 0 + MessageAck::Received } } diff --git a/native/src/talaria.udl b/native/src/talaria.udl index ae6144b..43eed21 100644 --- a/native/src/talaria.udl +++ b/native/src/talaria.udl @@ -1,3 +1,9 @@ +enum MessageAck { + "Received", + "Seen", + "Sent", +}; + namespace talaria { void initDatabase(string path); void initClient(); @@ -11,7 +17,7 @@ namespace talaria { string dialogSender(u64 dialogsPtr, u32 index); string dialogText(u64 dialogsPtr, u32 index); string dialogTime(u64 dialogsPtr, u32 index); - u32 dialogAck(u64 dialogsPtr, u32 index); + MessageAck dialogAck(u64 dialogsPtr, u32 index); u32 dialogPin(u64 dialogsPtr, u32 index); void freeDialogs(u64 dialogsPtr); void sendMessage(string packed, string text);