mirror of
https://github.com/chatmail/core.git
synced 2026-04-25 01:16:29 +03:00
implement ffi part
This commit is contained in:
@@ -1577,6 +1577,22 @@ int dc_set_chat_name (dc_context_t* context, uint32_t ch
|
||||
int dc_set_chat_profile_image (dc_context_t* context, uint32_t chat_id, const char* image);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set mute duration of a chat.
|
||||
*
|
||||
* This value can be checked by the ui upon recieving a new message to decide whether it should trigger an notification.
|
||||
*
|
||||
* Sends out #DC_EVENT_CHAT_MODIFIED.
|
||||
*
|
||||
* @memberof dc_context_t
|
||||
* @param chat_id The chat ID to set the mute duration.
|
||||
* @param duration The duration (0 for no mute, 1 for forever mute, >1 unix timestamp it until it should be unmuted again)
|
||||
* @param context The context as created by dc_context_new().
|
||||
* @return 1=success, 0=error
|
||||
*/
|
||||
int dc_set_chat_muted (dc_context_t* context, uint32_t chat_id, int64_t duration);
|
||||
|
||||
// handle messages
|
||||
|
||||
/**
|
||||
@@ -2919,6 +2935,26 @@ int dc_chat_is_verified (const dc_chat_t* chat);
|
||||
int dc_chat_is_sending_locations (const dc_chat_t* chat);
|
||||
|
||||
|
||||
/**
|
||||
* Check wether the chat is currently muted
|
||||
*
|
||||
* @memberof dc_chat_t
|
||||
* @param chat The chat object.
|
||||
* @return 1=muted, 0=not muted
|
||||
*/
|
||||
int dc_chat_is_muted (const dc_chat_t* chat);
|
||||
|
||||
|
||||
/**
|
||||
* Get the exact state of the mute of a chat
|
||||
*
|
||||
* @memberof dc_chat_t
|
||||
* @param chat The chat object.
|
||||
* @return 0=not muted, 1=muted, (x>1)=unix timestamp until mute is lifted
|
||||
*/
|
||||
int64_t dc_chat_get_mute_duration (const dc_chat_t* chat);
|
||||
|
||||
|
||||
/**
|
||||
* @class dc_msg_t
|
||||
*
|
||||
|
||||
@@ -1407,6 +1407,26 @@ pub unsafe extern "C" fn dc_set_chat_profile_image(
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_set_chat_muted(
|
||||
context: *mut dc_context_t,
|
||||
chat_id: u32,
|
||||
duration: i64,
|
||||
) -> libc::c_int {
|
||||
if context.is_null() || chat_id <= constants::DC_CHAT_ID_LAST_SPECIAL as u32 {
|
||||
eprintln!("ignoring careless call to dc_set_chat_muted()");
|
||||
return 0;
|
||||
}
|
||||
let ffi_context = &*context;
|
||||
ffi_context
|
||||
.with_inner(|ctx| {
|
||||
chat::set_muted(ctx, chat_id, chat::MuteDuration::deserialize(duration))
|
||||
.map(|_| 1)
|
||||
.unwrap_or_log_default(ctx, "Failed to set mute duration")
|
||||
})
|
||||
.unwrap_or(0)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_get_msg_info(
|
||||
context: *mut dc_context_t,
|
||||
@@ -2481,6 +2501,26 @@ pub unsafe extern "C" fn dc_chat_is_sending_locations(chat: *mut dc_chat_t) -> l
|
||||
ffi_chat.chat.is_sending_locations() as libc::c_int
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chat_is_muted(chat: *mut dc_chat_t) -> libc::c_int {
|
||||
if chat.is_null() {
|
||||
eprintln!("ignoring careless call to dc_chat_is_muted()");
|
||||
return 0;
|
||||
}
|
||||
let ffi_chat = &*chat;
|
||||
ffi_chat.chat.is_muted() as libc::c_int
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chat_get_mute_duration(chat: *mut dc_chat_t) -> i64 {
|
||||
if chat.is_null() {
|
||||
eprintln!("ignoring careless call to dc_chat_is_muted()");
|
||||
return 0;
|
||||
}
|
||||
let ffi_chat = &*chat;
|
||||
ffi_chat.chat.mute_duration.serialize() as i64
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_chat_get_info_json(
|
||||
context: *mut dc_context_t,
|
||||
|
||||
@@ -1926,7 +1926,7 @@ pub enum MuteDuration {
|
||||
|
||||
impl MuteDuration {
|
||||
// TODO use serde compatible functions?
|
||||
fn serialize(&self) -> i64 {
|
||||
pub fn serialize(&self) -> i64 {
|
||||
match &self {
|
||||
MuteDuration::NotMuted => 0,
|
||||
MuteDuration::Forever => 1,
|
||||
@@ -1934,7 +1934,7 @@ impl MuteDuration {
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize(value: i64) -> MuteDuration {
|
||||
pub fn deserialize(value: i64) -> MuteDuration {
|
||||
match value {
|
||||
0 => MuteDuration::NotMuted,
|
||||
1 => MuteDuration::Forever,
|
||||
@@ -2451,7 +2451,6 @@ pub fn add_info_msg(context: &Context, chat_id: ChatId, text: impl AsRef<str>) {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use crate::contact::Contact;
|
||||
use crate::test_utils::*;
|
||||
|
||||
Reference in New Issue
Block a user