@@ -725,7 +725,7 @@ unsafe fn prepare_msg_raw(
725725 timestamp,
726726 ( * msg) . type_0,
727727 ( * msg) . state,
728- if ! ( * msg) . text. is_null ( ) { Some ( as_str ( ( * msg ) . text ) ) } else { None } ,
728+ ( * msg) . text,
729729 ( * msg) . param. to_string( ) ,
730730 ( * msg) . hidden,
731731 to_string( new_in_reply_to) ,
@@ -950,7 +950,7 @@ pub unsafe fn dc_send_msg<'a>(
950950pub unsafe fn dc_send_text_msg (
951951 context : & Context ,
952952 chat_id : uint32_t ,
953- text_to_send : * const libc :: c_char ,
953+ text_to_send : String ,
954954) -> uint32_t {
955955 if chat_id <= 9 {
956956 warn ! (
@@ -960,18 +960,8 @@ pub unsafe fn dc_send_text_msg(
960960 return 0 ;
961961 }
962962
963- if text_to_send. is_null ( ) {
964- warn ! ( context, 0 , "dc_send_text_msg: text_to_send is emtpy" ) ;
965- return 0 ;
966- }
967-
968- if let Err ( err) = as_str_safe ( text_to_send) {
969- warn ! ( context, 0 , "{}" , err) ;
970- return 0 ;
971- }
972-
973963 let mut msg = dc_msg_new ( context, Viewtype :: Text ) ;
974- ( * msg) . text = dc_strdup ( text_to_send) ;
964+ ( * msg) . text = Some ( text_to_send) ;
975965 let ret = dc_send_msg ( context, chat_id, msg) ;
976966 dc_msg_unref ( msg) ;
977967 ret
@@ -1001,8 +991,9 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
1001991 // save new draft
1002992 if !msg. is_null ( ) {
1003993 if ( * msg) . type_0 == Viewtype :: Text {
1004- if ( * msg) . text . is_null ( ) || * ( * msg) . text . offset ( 0isize ) as libc:: c_int == 0i32 {
1005- OK_TO_CONTINUE = false ;
994+ OK_TO_CONTINUE = match ( * msg) . text {
995+ None => false ,
996+ Some ( ref text) => !text. is_empty ( ) ,
1006997 }
1007998 } else if msgtype_has_file ( ( * msg) . type_0 ) {
1008999 let mut pathNfilename = ( * msg)
@@ -1036,11 +1027,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
10361027 time( ) ,
10371028 ( * msg) . type_0,
10381029 DC_STATE_OUT_DRAFT ,
1039- if !( * msg) . text. is_null( ) {
1040- as_str( ( * msg) . text)
1041- } else {
1042- ""
1043- } ,
1030+ ( * msg) . text,
10441031 ( * msg) . param. to_string( ) ,
10451032 1 ,
10461033 ] ,
@@ -1616,14 +1603,12 @@ pub unsafe fn dc_add_contact_to_chat_ex(
16161603 if OK_TO_CONTINUE {
16171604 if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
16181605 ( * msg) . type_0 = Viewtype :: Text ;
1619- ( * msg) . text = context
1620- . stock_system_msg (
1621- StockMessage :: MsgAddMember ,
1622- as_str ( ( * contact) . addr ) ,
1623- "" ,
1624- DC_CONTACT_ID_SELF as uint32_t ,
1625- )
1626- . strdup ( ) ;
1606+ ( * msg) . text = Some ( context. stock_system_msg (
1607+ StockMessage :: MsgAddMember ,
1608+ as_str ( ( * contact) . addr ) ,
1609+ "" ,
1610+ DC_CONTACT_ID_SELF as uint32_t ,
1611+ ) ) ;
16271612 ( * msg) . param . set_int ( Param :: Cmd , 4 ) ;
16281613 if !( * contact) . addr . is_null ( ) {
16291614 ( * msg) . param . set ( Param :: Arg , as_str ( ( * contact) . addr ) ) ;
@@ -1731,23 +1716,19 @@ pub unsafe fn dc_remove_contact_from_chat(
17311716 ( * msg) . type_0 = Viewtype :: Text ;
17321717 if ( * contact) . id == 1 as libc:: c_uint {
17331718 dc_set_group_explicitly_left ( context, ( * chat) . grpid ) ;
1734- ( * msg) . text = context
1735- . stock_system_msg (
1736- StockMessage :: MsgGroupLeft ,
1737- "" ,
1738- "" ,
1739- DC_CONTACT_ID_SELF as u32 ,
1740- )
1741- . strdup ( ) ;
1719+ ( * msg) . text = Some ( context. stock_system_msg (
1720+ StockMessage :: MsgGroupLeft ,
1721+ "" ,
1722+ "" ,
1723+ DC_CONTACT_ID_SELF as u32 ,
1724+ ) ) ;
17421725 } else {
1743- ( * msg) . text = context
1744- . stock_system_msg (
1745- StockMessage :: MsgDelMember ,
1746- as_str ( ( * contact) . addr ) ,
1747- "" ,
1748- DC_CONTACT_ID_SELF as u32 ,
1749- )
1750- . strdup ( ) ;
1726+ ( * msg) . text = Some ( context. stock_system_msg (
1727+ StockMessage :: MsgDelMember ,
1728+ as_str ( ( * contact) . addr ) ,
1729+ "" ,
1730+ DC_CONTACT_ID_SELF as u32 ,
1731+ ) ) ;
17511732 }
17521733 ( * msg) . param . set_int ( Param :: Cmd , 5 ) ;
17531734 if !( * contact) . addr . is_null ( ) {
@@ -1848,14 +1829,12 @@ pub unsafe fn dc_set_chat_name(
18481829 {
18491830 if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
18501831 ( * msg) . type_0 = Viewtype :: Text ;
1851- ( * msg) . text = context
1852- . stock_system_msg (
1853- StockMessage :: MsgGrpName ,
1854- as_str ( ( * chat) . name ) ,
1855- as_str ( new_name) ,
1856- DC_CONTACT_ID_SELF as u32 ,
1857- )
1858- . strdup ( ) ;
1832+ ( * msg) . text = Some ( context. stock_system_msg (
1833+ StockMessage :: MsgGrpName ,
1834+ as_str ( ( * chat) . name ) ,
1835+ as_str ( new_name) ,
1836+ DC_CONTACT_ID_SELF as u32 ,
1837+ ) ) ;
18591838 ( * msg) . param . set_int ( Param :: Cmd , 2 ) ;
18601839 if !( * chat) . name . is_null ( ) {
18611840 ( * msg) . param . set ( Param :: Arg , as_str ( ( * chat) . name ) ) ;
@@ -1922,18 +1901,16 @@ pub unsafe fn dc_set_chat_profile_image(
19221901 ( * msg) . param . set_int ( Param :: Cmd , 3 ) ;
19231902 ( * msg) . param . set ( Param :: Arg , as_str ( new_image_rel) ) ;
19241903 ( * msg) . type_0 = Viewtype :: Text ;
1925- ( * msg) . text = context
1926- . stock_system_msg (
1927- if !new_image_rel. is_null ( ) {
1928- StockMessage :: MsgGrpImgChanged
1929- } else {
1930- StockMessage :: MsgGrpImgDeleted
1931- } ,
1932- "" ,
1933- "" ,
1934- DC_CONTACT_ID_SELF as uint32_t ,
1935- )
1936- . strdup ( ) ;
1904+ ( * msg) . text = Some ( context. stock_system_msg (
1905+ if !new_image_rel. is_null ( ) {
1906+ StockMessage :: MsgGrpImgChanged
1907+ } else {
1908+ StockMessage :: MsgGrpImgDeleted
1909+ } ,
1910+ "" ,
1911+ "" ,
1912+ DC_CONTACT_ID_SELF as uint32_t ,
1913+ ) ) ;
19371914 ( * msg) . id = dc_send_msg ( context, chat_id, msg) ;
19381915 context. call_cb (
19391916 Event :: MSGS_CHANGED ,
0 commit comments