@@ -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. deref ( ) . unwrap_or ( "" ) ,
729
729
( * msg) . param. to_string( ) ,
730
730
( * msg) . hidden,
731
731
to_string( new_in_reply_to) ,
@@ -950,7 +950,7 @@ pub unsafe fn dc_send_msg<'a>(
950
950
pub unsafe fn dc_send_text_msg (
951
951
context : & Context ,
952
952
chat_id : uint32_t ,
953
- text_to_send : * const libc :: c_char ,
953
+ text_to_send : String ,
954
954
) -> uint32_t {
955
955
if chat_id <= 9 {
956
956
warn ! (
@@ -960,18 +960,8 @@ pub unsafe fn dc_send_text_msg(
960
960
return 0 ;
961
961
}
962
962
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
-
973
963
let mut msg = dc_msg_new ( context, Viewtype :: Text ) ;
974
- ( * msg) . text = dc_strdup ( text_to_send) ;
964
+ ( * msg) . text = Some ( text_to_send) ;
975
965
let ret = dc_send_msg ( context, chat_id, msg) ;
976
966
dc_msg_unref ( msg) ;
977
967
ret
@@ -1001,9 +991,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
1001
991
// save new draft
1002
992
if !msg. is_null ( ) {
1003
993
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 ;
1006
- }
994
+ OK_TO_CONTINUE = ( * msg) . text . as_ref ( ) . map_or ( false , |s| !s. is_empty ( ) ) ;
1007
995
} else if msgtype_has_file ( ( * msg) . type_0 ) {
1008
996
let mut pathNfilename = ( * msg)
1009
997
. param
@@ -1036,11 +1024,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
1036
1024
time( ) ,
1037
1025
( * msg) . type_0,
1038
1026
DC_STATE_OUT_DRAFT ,
1039
- if !( * msg) . text. is_null( ) {
1040
- as_str( ( * msg) . text)
1041
- } else {
1042
- ""
1043
- } ,
1027
+ ( * msg) . text. deref( ) . unwrap_or( "" ) ,
1044
1028
( * msg) . param. to_string( ) ,
1045
1029
1 ,
1046
1030
] ,
@@ -1616,14 +1600,12 @@ pub unsafe fn dc_add_contact_to_chat_ex(
1616
1600
if OK_TO_CONTINUE {
1617
1601
if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
1618
1602
( * 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 ( ) ;
1603
+ ( * msg) . text = Some ( context. stock_system_msg (
1604
+ StockMessage :: MsgAddMember ,
1605
+ as_str ( ( * contact) . addr ) ,
1606
+ "" ,
1607
+ DC_CONTACT_ID_SELF as uint32_t ,
1608
+ ) ) ;
1627
1609
( * msg) . param . set_int ( Param :: Cmd , 4 ) ;
1628
1610
if !( * contact) . addr . is_null ( ) {
1629
1611
( * msg) . param . set ( Param :: Arg , as_str ( ( * contact) . addr ) ) ;
@@ -1731,23 +1713,19 @@ pub unsafe fn dc_remove_contact_from_chat(
1731
1713
( * msg) . type_0 = Viewtype :: Text ;
1732
1714
if ( * contact) . id == 1 as libc:: c_uint {
1733
1715
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 ( ) ;
1716
+ ( * msg) . text = Some ( context. stock_system_msg (
1717
+ StockMessage :: MsgGroupLeft ,
1718
+ "" ,
1719
+ "" ,
1720
+ DC_CONTACT_ID_SELF as u32 ,
1721
+ ) ) ;
1742
1722
} 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 ( ) ;
1723
+ ( * msg) . text = Some ( context. stock_system_msg (
1724
+ StockMessage :: MsgDelMember ,
1725
+ as_str ( ( * contact) . addr ) ,
1726
+ "" ,
1727
+ DC_CONTACT_ID_SELF as u32 ,
1728
+ ) ) ;
1751
1729
}
1752
1730
( * msg) . param . set_int ( Param :: Cmd , 5 ) ;
1753
1731
if !( * contact) . addr . is_null ( ) {
@@ -1848,14 +1826,12 @@ pub unsafe fn dc_set_chat_name(
1848
1826
{
1849
1827
if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
1850
1828
( * 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 ( ) ;
1829
+ ( * msg) . text = Some ( context. stock_system_msg (
1830
+ StockMessage :: MsgGrpName ,
1831
+ as_str ( ( * chat) . name ) ,
1832
+ as_str ( new_name) ,
1833
+ DC_CONTACT_ID_SELF as u32 ,
1834
+ ) ) ;
1859
1835
( * msg) . param . set_int ( Param :: Cmd , 2 ) ;
1860
1836
if !( * chat) . name . is_null ( ) {
1861
1837
( * msg) . param . set ( Param :: Arg , as_str ( ( * chat) . name ) ) ;
@@ -1922,18 +1898,16 @@ pub unsafe fn dc_set_chat_profile_image(
1922
1898
( * msg) . param . set_int ( Param :: Cmd , 3 ) ;
1923
1899
( * msg) . param . set ( Param :: Arg , as_str ( new_image_rel) ) ;
1924
1900
( * 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 ( ) ;
1901
+ ( * msg) . text = Some ( context. stock_system_msg (
1902
+ if !new_image_rel. is_null ( ) {
1903
+ StockMessage :: MsgGrpImgChanged
1904
+ } else {
1905
+ StockMessage :: MsgGrpImgDeleted
1906
+ } ,
1907
+ "" ,
1908
+ "" ,
1909
+ DC_CONTACT_ID_SELF as uint32_t ,
1910
+ ) ) ;
1937
1911
( * msg) . id = dc_send_msg ( context, chat_id, msg) ;
1938
1912
context. call_cb (
1939
1913
Event :: MSGS_CHANGED ,
0 commit comments