mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
add API to opt out of truncating long messages
This commit is contained in:
@@ -23,8 +23,9 @@ use deltachat::ephemeral::Timer;
|
|||||||
use deltachat::imex;
|
use deltachat::imex;
|
||||||
use deltachat::location;
|
use deltachat::location;
|
||||||
use deltachat::message::{
|
use deltachat::message::{
|
||||||
self, delete_msgs_ex, get_existing_msg_ids, get_msg_read_receipt_count, get_msg_read_receipts,
|
self, delete_msgs_ex, dont_truncate_long_messages, get_existing_msg_ids,
|
||||||
markseen_msgs, Message, MessageState, MsgId, Viewtype,
|
get_msg_read_receipt_count, get_msg_read_receipts, markseen_msgs, Message, MessageState, MsgId,
|
||||||
|
Viewtype,
|
||||||
};
|
};
|
||||||
use deltachat::peer_channels::{
|
use deltachat::peer_channels::{
|
||||||
leave_webxdc_realtime, send_webxdc_realtime_advertisement, send_webxdc_realtime_data,
|
leave_webxdc_realtime, send_webxdc_realtime_advertisement, send_webxdc_realtime_data,
|
||||||
@@ -1434,6 +1435,15 @@ impl CommandApi {
|
|||||||
MsgId::new(message_id).get_html(&ctx).await
|
MsgId::new(message_id).get_html(&ctx).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Opt out of truncating long messages when loading.
|
||||||
|
///
|
||||||
|
/// Should be used by the UIs that can handle long text messages.
|
||||||
|
async fn dont_truncate_long_messages(&self, account_id: u32) -> Result<()> {
|
||||||
|
let ctx = self.get_context(account_id).await?;
|
||||||
|
dont_truncate_long_messages(&ctx);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// get multiple messages in one call,
|
/// get multiple messages in one call,
|
||||||
/// if loading one message fails the error is stored in the result object in it's place.
|
/// if loading one message fails the error is stored in the result object in it's place.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -227,7 +227,18 @@ impl WeakContext {
|
|||||||
pub struct InnerContext {
|
pub struct InnerContext {
|
||||||
/// Blob directory path
|
/// Blob directory path
|
||||||
pub(crate) blobdir: PathBuf,
|
pub(crate) blobdir: PathBuf,
|
||||||
|
|
||||||
pub(crate) sql: Sql,
|
pub(crate) sql: Sql,
|
||||||
|
|
||||||
|
/// True if long text messages should be truncated
|
||||||
|
/// and full message HTML added.
|
||||||
|
///
|
||||||
|
/// This should be set by the UIs that cannot handle
|
||||||
|
/// long messages but can display HTML messages.
|
||||||
|
///
|
||||||
|
/// Ignored for bots, bots never get truncated messages.
|
||||||
|
pub(crate) truncate_long_messages: AtomicBool,
|
||||||
|
|
||||||
pub(crate) smeared_timestamp: SmearedTimestamp,
|
pub(crate) smeared_timestamp: SmearedTimestamp,
|
||||||
/// The global "ongoing" process state.
|
/// The global "ongoing" process state.
|
||||||
///
|
///
|
||||||
@@ -491,6 +502,7 @@ impl Context {
|
|||||||
blobdir,
|
blobdir,
|
||||||
running_state: RwLock::new(Default::default()),
|
running_state: RwLock::new(Default::default()),
|
||||||
sql: Sql::new(dbfile),
|
sql: Sql::new(dbfile),
|
||||||
|
truncate_long_messages: AtomicBool::new(true),
|
||||||
smeared_timestamp: SmearedTimestamp::new(),
|
smeared_timestamp: SmearedTimestamp::new(),
|
||||||
oauth2_mutex: Mutex::new(()),
|
oauth2_mutex: Mutex::new(()),
|
||||||
wrong_pw_warning_mutex: Mutex::new(()),
|
wrong_pw_warning_mutex: Mutex::new(()),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use std::collections::BTreeSet;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
|
|
||||||
use anyhow::{Context as _, Result, ensure, format_err};
|
use anyhow::{Context as _, Result, ensure, format_err};
|
||||||
use deltachat_contact_tools::{VcardContact, parse_vcard};
|
use deltachat_contact_tools::{VcardContact, parse_vcard};
|
||||||
@@ -2398,5 +2399,22 @@ impl Viewtype {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Opt out of truncating long messages.
|
||||||
|
///
|
||||||
|
/// After calling this function, long messages
|
||||||
|
/// will not be truncated during loading.
|
||||||
|
///
|
||||||
|
/// UIs should call this function if they
|
||||||
|
/// can handle long messages by cutting them
|
||||||
|
/// and displaying "Show full message" option.
|
||||||
|
///
|
||||||
|
/// Has no effect for bots which never
|
||||||
|
/// truncate messages when loading.
|
||||||
|
pub fn dont_truncate_long_messages(context: &Context) {
|
||||||
|
context
|
||||||
|
.truncate_long_messages
|
||||||
|
.store(false, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod message_tests;
|
mod message_tests;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use std::mem;
|
|||||||
use std::ops::{AddAssign, Deref};
|
use std::ops::{AddAssign, Deref};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str::from_utf8;
|
use std::str::from_utf8;
|
||||||
|
use std::sync::atomic::Ordering;
|
||||||
// If a time value doesn't need to be sent to another host, saved to the db or otherwise used across
|
// If a time value doesn't need to be sent to another host, saved to the db or otherwise used across
|
||||||
// program restarts, a monotonically nondecreasing clock (`Instant`) should be used. But as
|
// program restarts, a monotonically nondecreasing clock (`Instant`) should be used. But as
|
||||||
// `Instant` may use `libc::clock_gettime(CLOCK_MONOTONIC)`, e.g. on Android, and does not advance
|
// `Instant` may use `libc::clock_gettime(CLOCK_MONOTONIC)`, e.g. on Android, and does not advance
|
||||||
@@ -139,7 +140,9 @@ pub(crate) fn truncate_by_lines(
|
|||||||
///
|
///
|
||||||
/// Returns the resulting text and a bool telling whether a truncation was done.
|
/// Returns the resulting text and a bool telling whether a truncation was done.
|
||||||
pub(crate) async fn truncate_msg_text(context: &Context, text: String) -> Result<(String, bool)> {
|
pub(crate) async fn truncate_msg_text(context: &Context, text: String) -> Result<(String, bool)> {
|
||||||
if context.get_config_bool(Config::Bot).await? {
|
if !context.truncate_long_messages.load(Ordering::Relaxed)
|
||||||
|
|| context.get_config_bool(Config::Bot).await?
|
||||||
|
{
|
||||||
return Ok((text, false));
|
return Ok((text, false));
|
||||||
}
|
}
|
||||||
// Truncate text if it has too many lines
|
// Truncate text if it has too many lines
|
||||||
|
|||||||
Reference in New Issue
Block a user