forked from Lonami/Talaria
Move MessageAck enum to UDL
This commit is contained in:
parent
812597f027
commit
1a56b03614
|
@ -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
|
||||
)
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package dev.lonami.talaria.models
|
||||
|
||||
enum class MessageAck {
|
||||
RECEIVED,
|
||||
SENT,
|
||||
SEEN,
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package dev.lonami.talaria.models
|
||||
|
||||
import uniffi.talaria.MessageAck
|
||||
import java.time.LocalDateTime
|
||||
|
||||
data class MessagePreview(
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -45,6 +45,13 @@ static RUNTIME: OnceCell<Runtime> = OnceCell::new();
|
|||
static CLIENT: OnceCell<Client> = OnceCell::new();
|
||||
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 {
|
||||
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<Dialog>) };
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue