Move MessageAck enum to UDL

This commit is contained in:
Lonami Exo 2022-10-27 18:08:57 +02:00
parent 812597f027
commit 1a56b03614
6 changed files with 23 additions and 22 deletions

View File

@ -1,7 +1,6 @@
package dev.lonami.talaria.data package dev.lonami.talaria.data
import dev.lonami.talaria.models.Dialog import dev.lonami.talaria.models.Dialog
import dev.lonami.talaria.models.MessageAck
import dev.lonami.talaria.models.MessagePreview import dev.lonami.talaria.models.MessagePreview
import uniffi.talaria.* import uniffi.talaria.*
import java.time.LocalDateTime import java.time.LocalDateTime
@ -30,12 +29,7 @@ class NativeDialogRepository : DialogRepository {
dialogTime(dialogPtr, i), dialogTime(dialogPtr, i),
DateTimeFormatter.ISO_OFFSET_DATE_TIME DateTimeFormatter.ISO_OFFSET_DATE_TIME
), ),
ack = when (dialogAck(dialogPtr, i)) { ack = dialogAck(dialogPtr, i),
0U -> MessageAck.RECEIVED
1U -> MessageAck.SENT
2U -> MessageAck.SEEN
else -> MessageAck.RECEIVED
}
), ),
pinned = dialogPin(dialogPtr, i) != 0U pinned = dialogPin(dialogPtr, i) != 0U
) )

View File

@ -1,7 +0,0 @@
package dev.lonami.talaria.models
enum class MessageAck {
RECEIVED,
SENT,
SEEN,
}

View File

@ -1,5 +1,6 @@
package dev.lonami.talaria.models package dev.lonami.talaria.models
import uniffi.talaria.MessageAck
import java.time.LocalDateTime import java.time.LocalDateTime
data class MessagePreview( data class MessagePreview(

View File

@ -24,9 +24,9 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import dev.lonami.talaria.R import dev.lonami.talaria.R
import dev.lonami.talaria.data.MockDialogRepository import dev.lonami.talaria.data.MockDialogRepository
import dev.lonami.talaria.models.Dialog import dev.lonami.talaria.models.Dialog
import dev.lonami.talaria.models.MessageAck
import dev.lonami.talaria.ui.state.DialogViewModel import dev.lonami.talaria.ui.state.DialogViewModel
import dev.lonami.talaria.ui.theme.TalariaTheme import dev.lonami.talaria.ui.theme.TalariaTheme
import uniffi.talaria.MessageAck
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle import java.time.format.FormatStyle

View File

@ -45,6 +45,13 @@ static RUNTIME: OnceCell<Runtime> = OnceCell::new();
static CLIENT: OnceCell<Client> = OnceCell::new(); static CLIENT: OnceCell<Client> = OnceCell::new();
static DATABASE: Mutex<Option<sqlite::Connection>> = Mutex::new(None); static DATABASE: Mutex<Option<sqlite::Connection>> = Mutex::new(None);
#[derive(Debug, Clone, Copy)]
pub enum MessageAck {
Received,
Seen,
Sent,
}
fn block_on<F: Future>(future: F) -> F::Output { fn block_on<F: Future>(future: F) -> F::Output {
if RUNTIME.get().is_none() { if RUNTIME.get().is_none() {
RUNTIME 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<Dialog>) }; let dialogs = unsafe { &mut *(dialogsPtr as *mut Vec<Dialog>) };
let dialog = &dialogs[index as usize]; let dialog = &dialogs[index as usize];
@ -327,18 +334,18 @@ pub fn dialogAck(dialogsPtr: u64, index: u32) -> u32 {
match &dialog.dialog { match &dialog.dialog {
tl::enums::Dialog::Dialog(d) => { tl::enums::Dialog::Dialog(d) => {
if msg.id() <= d.read_inbox_max_id { if msg.id() <= d.read_inbox_max_id {
2 MessageAck::Seen
} else { } else {
1 MessageAck::Sent
} }
} }
tl::enums::Dialog::Folder(_) => 0, tl::enums::Dialog::Folder(_) => MessageAck::Received,
} }
} else { } else {
0 MessageAck::Received
} }
} else { } else {
0 MessageAck::Received
} }
} }

View File

@ -1,3 +1,9 @@
enum MessageAck {
"Received",
"Seen",
"Sent",
};
namespace talaria { namespace talaria {
void initDatabase(string path); void initDatabase(string path);
void initClient(); void initClient();
@ -11,7 +17,7 @@ namespace talaria {
string dialogSender(u64 dialogsPtr, u32 index); string dialogSender(u64 dialogsPtr, u32 index);
string dialogText(u64 dialogsPtr, u32 index); string dialogText(u64 dialogsPtr, u32 index);
string dialogTime(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); u32 dialogPin(u64 dialogsPtr, u32 index);
void freeDialogs(u64 dialogsPtr); void freeDialogs(u64 dialogsPtr);
void sendMessage(string packed, string text); void sendMessage(string packed, string text);