mirror of
https://github.com/chatmail/core.git
synced 2026-05-06 16:36:59 +03:00
do not truncate messages in contact requests
core-c has truncated messages in the contact requests. this is questionable in general, as - all messages, including contact requests, are already truncated, unquoted, simplified etc. - the ui should be capable of showing the full text anyway (when the contact request is accepted, the whole messase is shown) - also, all current ui show the contact requests by name only in the chatlist; the user often does not even come to the contact request view. - if the ui wants to show the contact request is a special way, it is probably better to leave this truncation up to the ui
This commit is contained in:
@@ -9,7 +9,7 @@ use std::time::SystemTime;
|
|||||||
use std::{fmt, fs, ptr};
|
use std::{fmt, fs, ptr};
|
||||||
|
|
||||||
use chrono::{Local, TimeZone};
|
use chrono::{Local, TimeZone};
|
||||||
use libc::{memcpy, strcpy, strlen, uintptr_t};
|
use libc::{memcpy, strlen};
|
||||||
use mmime::clist::*;
|
use mmime::clist::*;
|
||||||
use mmime::mailimf::types::*;
|
use mmime::mailimf::types::*;
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
@@ -149,66 +149,6 @@ pub(crate) fn dc_truncate(buf: &str, approx_chars: usize, do_unwrap: bool) -> Co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
pub(crate) unsafe fn dc_truncate_n_unwrap_str(
|
|
||||||
buf: *mut libc::c_char,
|
|
||||||
approx_characters: libc::c_int,
|
|
||||||
do_unwrap: libc::c_int,
|
|
||||||
) {
|
|
||||||
/* Function unwraps the given string and removes unnecessary whitespace.
|
|
||||||
Function stops processing after approx_characters are processed.
|
|
||||||
(as we're using UTF-8, for simplicity, we cut the string only at whitespaces). */
|
|
||||||
/* a single line is truncated `...` instead of `[...]` (the former is typically also used by the UI to fit strings in a rectangle) */
|
|
||||||
let ellipse_utf8: *const libc::c_char = if 0 != do_unwrap {
|
|
||||||
b" ...\x00" as *const u8 as *const libc::c_char
|
|
||||||
} else {
|
|
||||||
b" [...]\x00" as *const u8 as *const libc::c_char
|
|
||||||
};
|
|
||||||
let mut lastIsCharacter: libc::c_int = 0;
|
|
||||||
/* force unsigned - otherwise the `> ' '` comparison will fail */
|
|
||||||
let mut p1: *mut libc::c_uchar = buf as *mut libc::c_uchar;
|
|
||||||
while 0 != *p1 {
|
|
||||||
if *p1 as libc::c_int > ' ' as i32 {
|
|
||||||
lastIsCharacter = 1
|
|
||||||
} else if 0 != lastIsCharacter {
|
|
||||||
let used_bytes = (p1 as uintptr_t).wrapping_sub(buf as uintptr_t) as libc::size_t;
|
|
||||||
if dc_utf8_strnlen(buf, used_bytes) >= approx_characters as usize {
|
|
||||||
let buf_bytes = strlen(buf);
|
|
||||||
if buf_bytes.wrapping_sub(used_bytes) >= strlen(ellipse_utf8) {
|
|
||||||
strcpy(p1 as *mut libc::c_char, ellipse_utf8);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
lastIsCharacter = 0;
|
|
||||||
if 0 != do_unwrap {
|
|
||||||
*p1 = ' ' as i32 as libc::c_uchar
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if 0 != do_unwrap {
|
|
||||||
*p1 = '\r' as i32 as libc::c_uchar
|
|
||||||
}
|
|
||||||
p1 = p1.offset(1isize)
|
|
||||||
}
|
|
||||||
if 0 != do_unwrap {
|
|
||||||
dc_remove_cr_chars(buf);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn dc_utf8_strnlen(s: *const libc::c_char, n: libc::size_t) -> libc::size_t {
|
|
||||||
if s.is_null() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut j: libc::size_t = 0;
|
|
||||||
for i in 0..n {
|
|
||||||
if *s.add(i) as libc::c_int & 0xc0 != 0x80 {
|
|
||||||
j = j.wrapping_add(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
j
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) unsafe fn dc_str_from_clist(
|
pub(crate) unsafe fn dc_str_from_clist(
|
||||||
list: *const clist,
|
list: *const clist,
|
||||||
delimiter: *const libc::c_char,
|
delimiter: *const libc::c_char,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use deltachat_derive::{FromSql, ToSql};
|
use deltachat_derive::{FromSql, ToSql};
|
||||||
use libc::free;
|
|
||||||
|
|
||||||
use crate::chat::{self, Chat};
|
use crate::chat::{self, Chat};
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
@@ -108,18 +107,6 @@ impl Message {
|
|||||||
msg.hidden = row.get(18)?;
|
msg.hidden = row.get(18)?;
|
||||||
msg.location_id = row.get(19)?;
|
msg.location_id = row.get(19)?;
|
||||||
msg.chat_blocked = row.get::<_, Option<Blocked>>(20)?.unwrap_or_default();
|
msg.chat_blocked = row.get::<_, Option<Blocked>>(20)?.unwrap_or_default();
|
||||||
if msg.chat_blocked == Blocked::Deaddrop {
|
|
||||||
if let Some(ref text) = msg.text {
|
|
||||||
unsafe {
|
|
||||||
let ptr = text.strdup();
|
|
||||||
|
|
||||||
dc_truncate_n_unwrap_str(ptr, 256, 0);
|
|
||||||
|
|
||||||
msg.text = Some(to_string(ptr));
|
|
||||||
free(ptr.cast());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Ok(msg)
|
Ok(msg)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user