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