@@ -1952,7 +1952,9 @@ async fn add_parts(
1952
1952
None ,
1953
1953
added_removed_id,
1954
1954
)
1955
- . await ?;
1955
+ . await
1956
+ . log_err ( context)
1957
+ . ok ( ) ;
1956
1958
}
1957
1959
1958
1960
if let Some ( node_addr) = mime_parser. get_header ( HeaderDef :: IrohNodeAddr ) {
@@ -1990,7 +1992,7 @@ async fn add_parts(
1990
1992
if part. is_reaction {
1991
1993
let reaction_str = simplify:: remove_footers ( part. msg . as_str ( ) ) ;
1992
1994
let is_incoming_fresh = mime_parser. incoming && !seen;
1993
- set_msg_reaction (
1995
+ if set_msg_reaction (
1994
1996
context,
1995
1997
mime_in_reply_to,
1996
1998
chat_id,
@@ -1999,16 +2001,23 @@ async fn add_parts(
1999
2001
Reaction :: from ( reaction_str. as_str ( ) ) ,
2000
2002
is_incoming_fresh,
2001
2003
)
2002
- . await ?;
2004
+ . await
2005
+ . log_err ( context)
2006
+ . is_err ( )
2007
+ {
2008
+ continue ;
2009
+ }
2003
2010
}
2004
2011
2005
2012
let mut param = part. param . clone ( ) ;
2006
2013
if is_system_message != SystemMessage :: Unknown {
2007
2014
param. set_int ( Param :: Cmd , is_system_message as i32 ) ;
2008
2015
}
2009
2016
2010
- if let Some ( replace_msg_id) = replace_msg_id {
2011
- let placeholder = Message :: load_from_db ( context, replace_msg_id) . await ?;
2017
+ if let Some ( placeholder) = match replace_msg_id {
2018
+ None => None ,
2019
+ Some ( replace_msg_id) => Message :: load_from_db_optional ( context, replace_msg_id) . await ?,
2020
+ } {
2012
2021
for key in [
2013
2022
Param :: WebxdcSummary ,
2014
2023
Param :: WebxdcSummaryTimestamp ,
@@ -2019,6 +2028,8 @@ async fn add_parts(
2019
2028
param. set ( key, value) ;
2020
2029
}
2021
2030
}
2031
+ } else {
2032
+ replace_msg_id = None ;
2022
2033
}
2023
2034
2024
2035
let ( msg, typ) : ( & str , Viewtype ) = if let Some ( better_msg) = & better_msg {
@@ -2156,13 +2167,19 @@ RETURNING id
2156
2167
if let Some ( topic) = mime_parser. get_header ( HeaderDef :: IrohGossipTopic ) {
2157
2168
// default encoding of topic ids is `hex`.
2158
2169
let mut topic_raw = [ 0u8 ; 32 ] ;
2159
- BASE32_NOPAD
2170
+ if BASE32_NOPAD
2160
2171
. decode_mut ( topic. to_ascii_uppercase ( ) . as_bytes ( ) , & mut topic_raw)
2161
2172
. map_err ( |e| e. error )
2162
- . context ( "Wrong gossip topic header" ) ?;
2163
-
2164
- let topic = TopicId :: from_bytes ( topic_raw) ;
2165
- insert_topic_stub ( context, * msg_id, topic) . await ?;
2173
+ . context ( "Wrong gossip topic header" )
2174
+ . log_err ( context)
2175
+ . is_ok ( )
2176
+ {
2177
+ let topic = TopicId :: from_bytes ( topic_raw) ;
2178
+ insert_topic_stub ( context, * msg_id, topic)
2179
+ . await
2180
+ . log_err ( context)
2181
+ . ok ( ) ;
2182
+ }
2166
2183
} else {
2167
2184
warn ! ( context, "webxdc doesn't have a gossip topic" )
2168
2185
}
@@ -2175,7 +2192,9 @@ RETURNING id
2175
2192
part. param . get ( Param :: Filename ) ,
2176
2193
* msg_id,
2177
2194
)
2178
- . await ?;
2195
+ . await
2196
+ . log_err ( context)
2197
+ . ok ( ) ;
2179
2198
}
2180
2199
2181
2200
if let Some ( replace_msg_id) = replace_msg_id {
@@ -3647,7 +3666,10 @@ async fn mark_recipients_as_verified(
3647
3666
}
3648
3667
3649
3668
mark_contact_id_as_verified ( context, to_id, from_id) . await ?;
3650
- ChatId :: set_protection_for_contact ( context, to_id, mimeparser. timestamp_sent ) . await ?;
3669
+ ChatId :: set_protection_for_contact ( context, to_id, mimeparser. timestamp_sent )
3670
+ . await
3671
+ . log_err ( context)
3672
+ . ok ( ) ;
3651
3673
}
3652
3674
3653
3675
Ok ( ( ) )
@@ -3709,21 +3731,24 @@ async fn add_or_lookup_contacts_by_address_list(
3709
3731
) -> Result < Vec < Option < ContactId > > > {
3710
3732
let mut contact_ids = Vec :: new ( ) ;
3711
3733
for info in address_list {
3734
+ contact_ids. push ( None ) ;
3712
3735
let addr = & info. addr ;
3713
3736
if !may_be_valid_addr ( addr) {
3714
- contact_ids. push ( None ) ;
3715
3737
continue ;
3716
3738
}
3717
3739
let display_name = info. display_name . as_deref ( ) ;
3718
- if let Ok ( addr) = ContactAddress :: new ( addr) {
3719
- let ( contact_id, _) =
3720
- Contact :: add_or_lookup ( context, display_name. unwrap_or_default ( ) , & addr, origin)
3721
- . await ?;
3722
- contact_ids. push ( Some ( contact_id) ) ;
3723
- } else {
3740
+ let Ok ( addr) = ContactAddress :: new ( addr) else {
3724
3741
warn ! ( context, "Contact with address {:?} cannot exist." , addr) ;
3725
- contact_ids. push ( None ) ;
3726
- }
3742
+ continue ;
3743
+ } ;
3744
+ let contact_id =
3745
+ Contact :: add_or_lookup ( context, display_name. unwrap_or_default ( ) , & addr, origin)
3746
+ . await
3747
+ . log_err ( context)
3748
+ . ok ( )
3749
+ . map ( |( id, _) | id) ;
3750
+ contact_ids. pop ( ) ;
3751
+ contact_ids. push ( contact_id) ;
3727
3752
}
3728
3753
3729
3754
Ok ( contact_ids)
@@ -3740,9 +3765,9 @@ async fn add_or_lookup_key_contacts_by_address_list(
3740
3765
let mut contact_ids = Vec :: new ( ) ;
3741
3766
let mut fingerprint_iter = fingerprints. iter ( ) ;
3742
3767
for info in address_list {
3768
+ contact_ids. push ( None ) ;
3743
3769
let addr = & info. addr ;
3744
3770
if !may_be_valid_addr ( addr) {
3745
- contact_ids. push ( None ) ;
3746
3771
continue ;
3747
3772
}
3748
3773
let fingerprint: String = if let Some ( fp) = fingerprint_iter. next ( ) {
@@ -3751,24 +3776,26 @@ async fn add_or_lookup_key_contacts_by_address_list(
3751
3776
} else if let Some ( key) = gossiped_keys. get ( addr) {
3752
3777
key. dc_fingerprint ( ) . hex ( )
3753
3778
} else {
3754
- contact_ids. push ( None ) ;
3755
3779
continue ;
3756
3780
} ;
3757
3781
let display_name = info. display_name . as_deref ( ) ;
3758
- if let Ok ( addr) = ContactAddress :: new ( addr) {
3759
- let ( contact_id, _) = Contact :: add_or_lookup_ex (
3760
- context,
3761
- display_name. unwrap_or_default ( ) ,
3762
- & addr,
3763
- & fingerprint,
3764
- origin,
3765
- )
3766
- . await ?;
3767
- contact_ids. push ( Some ( contact_id) ) ;
3768
- } else {
3782
+ let Ok ( addr) = ContactAddress :: new ( addr) else {
3769
3783
warn ! ( context, "Contact with address {:?} cannot exist." , addr) ;
3770
- contact_ids. push ( None ) ;
3771
- }
3784
+ continue ;
3785
+ } ;
3786
+ let contact_id = Contact :: add_or_lookup_ex (
3787
+ context,
3788
+ display_name. unwrap_or_default ( ) ,
3789
+ & addr,
3790
+ & fingerprint,
3791
+ origin,
3792
+ )
3793
+ . await
3794
+ . log_err ( context)
3795
+ . ok ( )
3796
+ . map ( |( id, _) | id) ;
3797
+ contact_ids. pop ( ) ;
3798
+ contact_ids. push ( contact_id) ;
3772
3799
}
3773
3800
3774
3801
ensure_and_debug_assert_eq ! ( contact_ids. len( ) , address_list. len( ) , ) ;
@@ -3899,35 +3926,41 @@ async fn lookup_key_contacts_by_address_list(
3899
3926
let mut contact_ids = Vec :: new ( ) ;
3900
3927
let mut fingerprint_iter = fingerprints. iter ( ) ;
3901
3928
for info in address_list {
3929
+ contact_ids. push ( None ) ;
3902
3930
let addr = & info. addr ;
3903
3931
if !may_be_valid_addr ( addr) {
3904
- contact_ids. push ( None ) ;
3905
3932
continue ;
3906
3933
}
3907
3934
3908
- if let Some ( fp) = fingerprint_iter. next ( ) {
3935
+ let contact_id = if let Some ( fp) = fingerprint_iter. next ( ) {
3909
3936
// Iterator has not ran out of fingerprints yet.
3910
3937
let display_name = info. display_name . as_deref ( ) ;
3911
3938
let fingerprint: String = fp. hex ( ) ;
3912
3939
3913
- if let Ok ( addr) = ContactAddress :: new ( addr) {
3914
- let ( contact_id, _) = Contact :: add_or_lookup_ex (
3915
- context,
3916
- display_name. unwrap_or_default ( ) ,
3917
- & addr,
3918
- & fingerprint,
3919
- Origin :: Hidden ,
3920
- )
3921
- . await ?;
3922
- contact_ids. push ( Some ( contact_id) ) ;
3923
- } else {
3940
+ let Ok ( addr) = ContactAddress :: new ( addr) else {
3924
3941
warn ! ( context, "Contact with address {:?} cannot exist." , addr) ;
3925
- contact_ids. push ( None ) ;
3926
- }
3942
+ continue ;
3943
+ } ;
3944
+ Contact :: add_or_lookup_ex (
3945
+ context,
3946
+ display_name. unwrap_or_default ( ) ,
3947
+ & addr,
3948
+ & fingerprint,
3949
+ Origin :: Hidden ,
3950
+ )
3951
+ . await
3952
+ . log_err ( context)
3953
+ . ok ( )
3954
+ . map ( |( id, _) | id)
3927
3955
} else {
3928
- let contact_id = lookup_key_contact_by_address ( context, addr, chat_id) . await ?;
3929
- contact_ids. push ( contact_id) ;
3930
- }
3956
+ lookup_key_contact_by_address ( context, addr, chat_id)
3957
+ . await
3958
+ . log_err ( context)
3959
+ . ok ( )
3960
+ . flatten ( )
3961
+ } ;
3962
+ contact_ids. pop ( ) ;
3963
+ contact_ids. push ( contact_id) ;
3931
3964
}
3932
3965
ensure_and_debug_assert_eq ! ( address_list. len( ) , contact_ids. len( ) , ) ;
3933
3966
Ok ( contact_ids)
0 commit comments