@@ -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,7 +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 {
994
+ if ( * msg) . text . is_none ( ) {
1005
995
OK_TO_CONTINUE = false ;
1006
996
}
1007
997
} else if msgtype_has_file ( ( * msg) . type_0 ) {
@@ -1036,11 +1026,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
1036
1026
time( ) ,
1037
1027
( * msg) . type_0,
1038
1028
DC_STATE_OUT_DRAFT ,
1039
- if !( * msg) . text. is_null( ) {
1040
- as_str( ( * msg) . text)
1041
- } else {
1042
- ""
1043
- } ,
1029
+ ( * msg) . text,
1044
1030
( * msg) . param. to_string( ) ,
1045
1031
1 ,
1046
1032
] ,
@@ -1616,14 +1602,12 @@ pub unsafe fn dc_add_contact_to_chat_ex(
1616
1602
if OK_TO_CONTINUE {
1617
1603
if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
1618
1604
( * msg) . type_0 = Viewtype :: Text ;
1619
- ( * msg) . text = context
1605
+ ( * msg) . text = Some ( context
1620
1606
. stock_system_msg (
1621
1607
StockMessage :: MsgAddMember ,
1622
1608
as_str ( ( * contact) . addr ) ,
1623
1609
"" ,
1624
- DC_CONTACT_ID_SELF as uint32_t ,
1625
- )
1626
- . strdup ( ) ;
1610
+ DC_CONTACT_ID_SELF as uint32_t ) ) ;
1627
1611
( * msg) . param . set_int ( Param :: Cmd , 4 ) ;
1628
1612
if !( * contact) . addr . is_null ( ) {
1629
1613
( * msg) . param . set ( Param :: Arg , as_str ( ( * contact) . addr ) ) ;
@@ -1731,23 +1715,21 @@ pub unsafe fn dc_remove_contact_from_chat(
1731
1715
( * msg) . type_0 = Viewtype :: Text ;
1732
1716
if ( * contact) . id == 1 as libc:: c_uint {
1733
1717
dc_set_group_explicitly_left ( context, ( * chat) . grpid ) ;
1734
- ( * msg) . text = context
1718
+ ( * msg) . text = Some ( context
1735
1719
. stock_system_msg (
1736
1720
StockMessage :: MsgGroupLeft ,
1737
1721
"" ,
1738
1722
"" ,
1739
1723
DC_CONTACT_ID_SELF as u32 ,
1740
- )
1741
- . strdup ( ) ;
1724
+ ) ) ;
1742
1725
} else {
1743
- ( * msg) . text = context
1726
+ ( * msg) . text = Some ( context
1744
1727
. stock_system_msg (
1745
1728
StockMessage :: MsgDelMember ,
1746
1729
as_str ( ( * contact) . addr ) ,
1747
1730
"" ,
1748
1731
DC_CONTACT_ID_SELF as u32 ,
1749
- )
1750
- . strdup ( ) ;
1732
+ ) ) ;
1751
1733
}
1752
1734
( * msg) . param . set_int ( Param :: Cmd , 5 ) ;
1753
1735
if !( * contact) . addr . is_null ( ) {
@@ -1848,14 +1830,13 @@ pub unsafe fn dc_set_chat_name(
1848
1830
{
1849
1831
if ( * chat) . param . get_int ( Param :: Unpromoted ) . unwrap_or_default ( ) == 0 {
1850
1832
( * msg) . type_0 = Viewtype :: Text ;
1851
- ( * msg) . text = context
1833
+ ( * msg) . text = Some ( context
1852
1834
. stock_system_msg (
1853
1835
StockMessage :: MsgGrpName ,
1854
1836
as_str ( ( * chat) . name ) ,
1855
1837
as_str ( new_name) ,
1856
1838
DC_CONTACT_ID_SELF as u32 ,
1857
- )
1858
- . strdup ( ) ;
1839
+ ) ) ;
1859
1840
( * msg) . param . set_int ( Param :: Cmd , 2 ) ;
1860
1841
if !( * chat) . name . is_null ( ) {
1861
1842
( * msg) . param . set ( Param :: Arg , as_str ( ( * chat) . name ) ) ;
@@ -1922,7 +1903,7 @@ pub unsafe fn dc_set_chat_profile_image(
1922
1903
( * msg) . param . set_int ( Param :: Cmd , 3 ) ;
1923
1904
( * msg) . param . set ( Param :: Arg , as_str ( new_image_rel) ) ;
1924
1905
( * msg) . type_0 = Viewtype :: Text ;
1925
- ( * msg) . text = context
1906
+ ( * msg) . text = Some ( context
1926
1907
. stock_system_msg (
1927
1908
if !new_image_rel. is_null ( ) {
1928
1909
StockMessage :: MsgGrpImgChanged
@@ -1932,8 +1913,7 @@ pub unsafe fn dc_set_chat_profile_image(
1932
1913
"" ,
1933
1914
"" ,
1934
1915
DC_CONTACT_ID_SELF as uint32_t ,
1935
- )
1936
- . strdup ( ) ;
1916
+ ) ) ;
1937
1917
( * msg) . id = dc_send_msg ( context, chat_id, msg) ;
1938
1918
context. call_cb (
1939
1919
Event :: MSGS_CHANGED ,
0 commit comments