@@ -1929,9 +1929,26 @@ pub fn get_chat_id_by_grpid(context: &Context, grpid: impl AsRef<str>) -> (u32,
1929
1929
}
1930
1930
1931
1931
pub fn add_device_msg ( context : & Context , msg : & mut Message ) -> Result < MsgId , Error > {
1932
+ let label = format ! ( "info-{}" , dc_create_id( ) ) ;
1933
+ add_device_msg_once ( context, & label, msg)
1934
+ }
1935
+
1936
+ pub fn add_device_msg_once (
1937
+ context : & Context ,
1938
+ label : & str ,
1939
+ msg : & mut Message ,
1940
+ ) -> Result < MsgId , Error > {
1932
1941
let ( chat_id, _blocked) =
1933
1942
create_or_lookup_by_contact_id ( context, DC_CONTACT_ID_DEVICE , Blocked :: Not ) ?;
1934
- let rfc724_mid = dc_create_outgoing_rfc724_mid ( None , "@device" ) ;
1943
+ let rfc724_mid = format ! ( "{}@device" , label) ;
1944
+
1945
+ if let Ok ( ( _, _, msg_id) ) = message:: rfc724_mid_exists ( context, & rfc724_mid) {
1946
+ info ! (
1947
+ context,
1948
+ "device-message {} already exist as {}" , label, msg_id
1949
+ ) ;
1950
+ return Ok ( msg_id) ;
1951
+ }
1935
1952
1936
1953
prepare_msg_blob ( context, msg) ?;
1937
1954
unarchive ( context, chat_id) ?;
@@ -1955,6 +1972,7 @@ pub fn add_device_msg(context: &Context, msg: &mut Message) -> Result<MsgId, Err
1955
1972
let row_id = sql:: get_rowid ( context, & context. sql , "msgs" , "rfc724_mid" , & rfc724_mid) ;
1956
1973
let msg_id = MsgId :: new ( row_id) ;
1957
1974
context. call_cb ( Event :: IncomingMsg { chat_id, msg_id } ) ;
1975
+ info ! ( context, "device-message {} added as {}" , label, msg_id) ;
1958
1976
1959
1977
Ok ( msg_id)
1960
1978
}
0 commit comments