From 8703da83f552250d98305ea5b1bb77b7638e34d4 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 4 Mar 2021 21:45:17 +0100 Subject: [PATCH] comment in more detail about DC_DESIRED_TEXT_LEN and use old limit that had worked for some while okayish --- src/constants.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 5b11081ed..c14a08960 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -168,12 +168,30 @@ pub const DC_MSG_ID_LAST_SPECIAL: u32 = 9; /// string that indicates sth. is left out or truncated pub const DC_ELLIPSE: &str = "[...]"; -/// to keep bubbles and chat flow usable, we limit the text length to DC_DESIRED_TEXT_LEN. +/// to keep bubbles and chat flow usable, +/// and to avoid problems with controls using very long texts, +/// we limit the text length to DC_DESIRED_TEXT_LEN. /// if the text is longer, the full text can be retrieved usind has_html()/get_html(). -pub const DC_DESIRED_TEXT_LEN: usize = 20000; +/// +/// we are using a bit less than DC_MAX_GET_TEXT_LEN to avoid cutting twice +/// (a bit less as truncation may not be exact and ellipses may be added). +/// +/// note, that DC_DESIRED_TEXT_LEN and DC_MAX_GET_TEXT_LEN +/// define max. number of bytes, _not_ unicode graphemes. +/// in general, that seems to be okay for such an upper limit, +/// esp. as calculating the number of graphemes is not simple +/// (one graphemes may be a sequence of code points which is a sequence of bytes). +/// also even if we have the exact number of graphemes, +/// that would not always help on getting an idea about the screen space used +/// (to keep bubbles and chat flow usable). +/// +/// therefore, the number of bytes is only a very rough estimation, +/// however, the ~30K seems to work okayish for a while, +/// if it turns out, it is too few for some alphabet, we can still increase. +pub const DC_DESIRED_TEXT_LEN: usize = 29_000; -/// approx. max. length returned by dc_msg_get_text() -pub const DC_MAX_GET_TEXT_LEN: usize = 30000; +/// approx. max. length (number of bytes) returned by dc_msg_get_text() +pub const DC_MAX_GET_TEXT_LEN: usize = 30_000; /// approx. max. length returned by dc_get_msg_info() pub const DC_MAX_GET_INFO_LEN: usize = 100_000;