@@ -725,7 +725,7 @@ unsafe fn prepare_msg_raw(
725
725
timestamp,
726
726
( * msg) . type_0,
727
727
( * msg) . state,
728
- if ! ( * msg) . text. is_null ( ) { Some ( as_str ( ( * msg ) . text ) ) } else { None } ,
728
+ ( * msg) . text,
729
729
( * msg) . param. to_string( ) ,
730
730
( * msg) . hidden,
731
731
to_string( new_in_reply_to) ,
@@ -951,7 +951,7 @@ pub unsafe fn dc_send_msg<'a>(
951
951
pub unsafe fn dc_send_text_msg (
952
952
context : & Context ,
953
953
chat_id : uint32_t ,
954
- text_to_send : * const libc :: c_char ,
954
+ text_to_send : String ,
955
955
) -> uint32_t {
956
956
if chat_id <= 9 {
957
957
warn ! (
@@ -961,18 +961,8 @@ pub unsafe fn dc_send_text_msg(
961
961
return 0 ;
962
962
}
963
963
964
- if text_to_send. is_null ( ) {
965
- warn ! ( context, 0 , "dc_send_text_msg: text_to_send is emtpy" ) ;
966
- return 0 ;
967
- }
968
-
969
- if let Err ( err) = as_str_safe ( text_to_send) {
970
- warn ! ( context, 0 , "{}" , err) ;
971
- return 0 ;
972
- }
973
-
974
964
let mut msg = dc_msg_new ( context, Viewtype :: Text ) ;
975
- ( * msg) . text = dc_strdup ( text_to_send) ;
965
+ ( * msg) . text = Some ( text_to_send) ;
976
966
let ret = dc_send_msg ( context, chat_id, msg) ;
977
967
dc_msg_unref ( msg) ;
978
968
ret
@@ -1002,9 +992,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
1002
992
// save new draft
1003
993
if !msg. is_null ( ) {
1004
994
if ( * msg) . type_0 == Viewtype :: Text {
1005
- if ( * msg) . text . is_null ( ) || * ( * msg) . text . offset ( 0isize ) as libc:: c_int == 0i32 {
1006
- OK_TO_CONTINUE = false ;
1007
- }
995
+ OK_TO_CONTINUE = ( * msg) . text . as_ref ( ) . map_or ( false , |s| !s. is_empty ( ) ) ;
1008
996
} else if msgtype_has_file ( ( * msg) . type_0 ) {
1009
997
let mut pathNfilename = ( * msg)
1010
998
. param
@@ -1037,11 +1025,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
1037
1025
time( ) ,
1038
1026
( * msg) . type_0,
1039
1027
DC_STATE_OUT_DRAFT ,
1040
- if !( * msg) . text. is_null( ) {
1041
- as_str( ( * msg) . text)
1042
- } else {
1043
- ""
1044
- } ,
1028
+ ( * msg) . text. deref( ) . unwrap_or( "" ) ,
1045
1029
( * msg) . param. to_string( ) ,
1046
1030
1 ,
1047
1031
] ,
@@ -1617,14 +1601,12 @@ pub unsafe fn dc_add_contact_to_chat_ex(
1617
1601
if OK_TO_CONTINUE {
1618
1602
if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
1619
1603
( * msg) . type_0 = Viewtype :: Text ;
1620
- ( * msg) . text = context
1621
- . stock_system_msg (
1622
- StockMessage :: MsgAddMember ,
1623
- as_str ( ( * contact) . addr ) ,
1624
- "" ,
1625
- DC_CONTACT_ID_SELF as uint32_t ,
1626
- )
1627
- . strdup ( ) ;
1604
+ ( * msg) . text = Some ( context. stock_system_msg (
1605
+ StockMessage :: MsgAddMember ,
1606
+ as_str ( ( * contact) . addr ) ,
1607
+ "" ,
1608
+ DC_CONTACT_ID_SELF as uint32_t ,
1609
+ ) ) ;
1628
1610
( * msg) . param . set_int ( Param :: Cmd , 4 ) ;
1629
1611
if !( * contact) . addr . is_null ( ) {
1630
1612
( * msg) . param . set ( Param :: Arg , as_str ( ( * contact) . addr ) ) ;
@@ -1732,23 +1714,19 @@ pub unsafe fn dc_remove_contact_from_chat(
1732
1714
( * msg) . type_0 = Viewtype :: Text ;
1733
1715
if ( * contact) . id == 1 as libc:: c_uint {
1734
1716
dc_set_group_explicitly_left ( context, ( * chat) . grpid ) ;
1735
- ( * msg) . text = context
1736
- . stock_system_msg (
1737
- StockMessage :: MsgGroupLeft ,
1738
- "" ,
1739
- "" ,
1740
- DC_CONTACT_ID_SELF as u32 ,
1741
- )
1742
- . strdup ( ) ;
1717
+ ( * msg) . text = Some ( context. stock_system_msg (
1718
+ StockMessage :: MsgGroupLeft ,
1719
+ "" ,
1720
+ "" ,
1721
+ DC_CONTACT_ID_SELF as u32 ,
1722
+ ) ) ;
1743
1723
} else {
1744
- ( * msg) . text = context
1745
- . stock_system_msg (
1746
- StockMessage :: MsgDelMember ,
1747
- as_str ( ( * contact) . addr ) ,
1748
- "" ,
1749
- DC_CONTACT_ID_SELF as u32 ,
1750
- )
1751
- . strdup ( ) ;
1724
+ ( * msg) . text = Some ( context. stock_system_msg (
1725
+ StockMessage :: MsgDelMember ,
1726
+ as_str ( ( * contact) . addr ) ,
1727
+ "" ,
1728
+ DC_CONTACT_ID_SELF as u32 ,
1729
+ ) ) ;
1752
1730
}
1753
1731
( * msg) . param . set_int ( Param :: Cmd , 5 ) ;
1754
1732
if !( * contact) . addr . is_null ( ) {
@@ -1849,14 +1827,12 @@ pub unsafe fn dc_set_chat_name(
1849
1827
{
1850
1828
if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
1851
1829
( * msg) . type_0 = Viewtype :: Text ;
1852
- ( * msg) . text = context
1853
- . stock_system_msg (
1854
- StockMessage :: MsgGrpName ,
1855
- as_str ( ( * chat) . name ) ,
1856
- as_str ( new_name) ,
1857
- DC_CONTACT_ID_SELF as u32 ,
1858
- )
1859
- . strdup ( ) ;
1830
+ ( * msg) . text = Some ( context. stock_system_msg (
1831
+ StockMessage :: MsgGrpName ,
1832
+ as_str ( ( * chat) . name ) ,
1833
+ as_str ( new_name) ,
1834
+ DC_CONTACT_ID_SELF as u32 ,
1835
+ ) ) ;
1860
1836
( * msg) . param . set_int ( Param :: Cmd , 2 ) ;
1861
1837
if !( * chat) . name . is_null ( ) {
1862
1838
( * msg) . param . set ( Param :: Arg , as_str ( ( * chat) . name ) ) ;
@@ -1923,18 +1899,16 @@ pub unsafe fn dc_set_chat_profile_image(
1923
1899
( * msg) . param . set_int ( Param :: Cmd , 3 ) ;
1924
1900
( * msg) . param . set ( Param :: Arg , as_str ( new_image_rel) ) ;
1925
1901
( * msg) . type_0 = Viewtype :: Text ;
1926
- ( * msg) . text = context
1927
- . stock_system_msg (
1928
- if !new_image_rel. is_null ( ) {
1929
- StockMessage :: MsgGrpImgChanged
1930
- } else {
1931
- StockMessage :: MsgGrpImgDeleted
1932
- } ,
1933
- "" ,
1934
- "" ,
1935
- DC_CONTACT_ID_SELF as uint32_t ,
1936
- )
1937
- . strdup ( ) ;
1902
+ ( * msg) . text = Some ( context. stock_system_msg (
1903
+ if !new_image_rel. is_null ( ) {
1904
+ StockMessage :: MsgGrpImgChanged
1905
+ } else {
1906
+ StockMessage :: MsgGrpImgDeleted
1907
+ } ,
1908
+ "" ,
1909
+ "" ,
1910
+ DC_CONTACT_ID_SELF as uint32_t ,
1911
+ ) ) ;
1938
1912
( * msg) . id = dc_send_msg ( context, chat_id, msg) ;
1939
1913
context. call_cb (
1940
1914
Event :: MSGS_CHANGED ,
0 commit comments