@@ -14,7 +14,7 @@ use async_recursion::async_recursion;
1414use std:: io:: Seek ;
1515use rand:: RngCore ;
1616
17- use crate :: { aps:: get_message, ids:: { identity_manager:: { IDSSendMessage , MessageTarget , Raw } , CertifiedContext , IDSRecvMessage } , mmcs:: { self , put_authorize_body, AuthorizedOperation , MMCSReceipt , ReadContainer , WriteContainer } , util:: { base64_encode, bin_deserialize, bin_serialize, duration_since_epoch, plist_to_string, KeyedArchive , NSArray , NSArrayClass , NSDataClass , NSDictionary , NSDictionaryClass } , OSConfig } ;
17+ use crate :: { aps:: get_message, ids:: { identity_manager:: { IDSSendMessage , MessageTarget , Raw } , CertifiedContext , IDSRecvMessage } , mmcs:: { self , put_authorize_body, AuthorizedOperation , MMCSReceipt , ReadContainer , WriteContainer } , util:: { base64_decode , base64_encode, bin_deserialize, bin_serialize, duration_since_epoch, plist_to_string, KeyedArchive , NSArray , NSArrayClass , NSDataClass , NSDictionary , NSDictionaryClass } , OSConfig } ;
1818
1919use crate :: { aps:: APSConnectionResource , error:: PushError , mmcs:: { get_mmcs, prepare_put, put_mmcs, MMCSConfig , Container , DataCacher , PreparedPut } , mmcsp, util:: { decode_hex, encode_hex, gzip, plist_to_bin, ungzip} } ;
2020
@@ -1510,6 +1510,83 @@ pub struct UpdateProfileSharingMessage {
15101510 pub version : u64 ,
15111511}
15121512
1513+ #[ derive( Serialize , Deserialize , Clone ) ]
1514+ #[ serde( untagged) ]
1515+ pub enum SetTranscriptBackgroundMessage {
1516+ Remove {
1517+ #[ serde( rename = "traba" ) ]
1518+ aid : u32 ,
1519+ #[ serde( rename = "tbid" ) ]
1520+ bid : u32 , // sequence number
1521+ #[ serde( rename = "cid" ) ]
1522+ chat_id : Option < String > ,
1523+
1524+ #[ serde( rename = "trababr" ) ]
1525+ remove : bool ,
1526+ } ,
1527+ Set {
1528+ #[ serde( rename = "traba" ) ]
1529+ aid : u32 ,
1530+ #[ serde( rename = "tbid" ) ]
1531+ bid : u32 , // sequence number
1532+ #[ serde( rename = "cid" ) ]
1533+ chat_id : Option < String > ,
1534+
1535+ #[ serde( rename = "traboid" ) ]
1536+ object_id : String ,
1537+ #[ serde( rename = "trabapv" ) ]
1538+ payload_version : u32 ,
1539+ #[ serde( rename = "trabaid" ) ]
1540+ background_id : String ,
1541+ #[ serde( rename = "trabar" ) ]
1542+ url : String ,
1543+ #[ serde( rename = "trabas" ) ]
1544+ signature : String ,
1545+ #[ serde( rename = "trabak" ) ]
1546+ key : String ,
1547+ #[ serde( rename = "trabafs" ) ]
1548+ file_size : usize ,
1549+ }
1550+ }
1551+
1552+ impl SetTranscriptBackgroundMessage {
1553+ pub fn to_mmcs ( & self ) -> Option < MMCSFile > {
1554+ match self {
1555+ Self :: Remove { .. } => None ,
1556+ Self :: Set { object_id, url, signature, key, file_size, .. } => Some ( MMCSFile {
1557+ signature : base64_decode ( & signature) ,
1558+ object : object_id. to_string ( ) ,
1559+ url : url. to_string ( ) ,
1560+ key : base64_decode ( & key) [ 1 ..] . to_vec ( ) ,
1561+ size : * file_size, // not used?? better hope not
1562+ } )
1563+ }
1564+ }
1565+
1566+ pub fn from_mmcs ( file : Option < MMCSFile > , version : u32 , chat_id : Option < String > ) -> Self {
1567+ match file {
1568+ None => Self :: Remove {
1569+ aid : 1 ,
1570+ bid : version,
1571+ chat_id,
1572+ remove : true ,
1573+ } ,
1574+ Some ( file) => Self :: Set {
1575+ aid : 1 ,
1576+ bid : version,
1577+ chat_id,
1578+ object_id : file. object ,
1579+ payload_version : 1 ,
1580+ background_id : Uuid :: new_v4 ( ) . to_string ( ) . to_uppercase ( ) ,
1581+ url : file. url ,
1582+ signature : base64_encode ( & file. signature ) ,
1583+ key : base64_encode ( & [ vec ! [ 0x00 ] , file. key ] . concat ( ) ) ,
1584+ file_size : file. size ,
1585+ }
1586+ }
1587+ }
1588+ }
1589+
15131590#[ repr( C ) ]
15141591#[ derive( Clone ) ]
15151592pub enum Message {
@@ -1539,6 +1616,7 @@ pub enum Message {
15391616 UpdateProfileSharing ( UpdateProfileSharingMessage ) ,
15401617 ShareProfile ( ShareProfileMessage ) ,
15411618 NotifyAnyways ,
1619+ SetTranscriptBackground ( SetTranscriptBackgroundMessage ) ,
15421620}
15431621
15441622
@@ -1593,6 +1671,7 @@ impl Message {
15931671 Self :: UpdateProfileSharing ( _) => 180 ,
15941672 Self :: ShareProfile ( _) => 131 ,
15951673 Self :: NotifyAnyways => 113 ,
1674+ Self :: SetTranscriptBackground ( _) => 138 ,
15961675 }
15971676 }
15981677
@@ -1666,6 +1745,7 @@ impl Message {
16661745 Self :: ShareProfile ( _) => Some ( true ) ,
16671746 Self :: UpdateProfileSharing ( _) => Some ( true ) ,
16681747 Self :: NotifyAnyways => Some ( true ) ,
1748+ Self :: SetTranscriptBackground ( _) => Some ( true ) ,
16691749 _ => None
16701750 }
16711751 }
@@ -1751,6 +1831,9 @@ impl fmt::Display for Message {
17511831 } ,
17521832 Message :: NotifyAnyways => {
17531833 write ! ( f, "Notify anyways" )
1834+ } ,
1835+ Message :: SetTranscriptBackground ( _) => {
1836+ write ! ( f, "Changed the transcript background" )
17541837 }
17551838 }
17561839 }
@@ -1976,6 +2059,9 @@ impl MessageInst {
19762059 } ;
19772060 plist_to_bin ( & raw ) . unwrap ( )
19782061 } ,
2062+ Message :: SetTranscriptBackground ( back) => {
2063+ plist_to_bin ( & back) . unwrap ( )
2064+ }
19792065 Message :: UpdateExtension ( ext) => {
19802066 let raw = RawUpdateExtensionMessage {
19812067 version : "1" . to_string ( ) ,
@@ -2478,6 +2564,9 @@ impl MessageInst {
24782564 }
24792565 }
24802566 }
2567+ if let Ok ( loaded) = plist:: from_value :: < SetTranscriptBackgroundMessage > ( & value) {
2568+ return wrapper. to_message ( None , Message :: SetTranscriptBackground ( loaded) )
2569+ }
24812570 if let Ok ( loaded) = plist:: from_value :: < RecoverChatMetadataArray > ( & value) {
24822571 return wrapper. to_message ( None , Message :: RecoverChat ( loaded. recover_chat_metadata_array . into_iter ( ) . next ( ) . unwrap ( ) ) )
24832572 }
@@ -2720,7 +2809,8 @@ impl MessageInst {
27202809 None
27212810 }
27222811 } ;
2723- } else if let Some ( balloon) = & balloon_part {
2812+ }
2813+ if let ( Some ( balloon) , None ) = ( & balloon_part, & app) {
27242814 app = match Balloon :: decode_raw ( & balloon) {
27252815 Ok ( i) => Some ( ExtensionApp {
27262816 app_id : None ,
@@ -2733,7 +2823,7 @@ impl MessageInst {
27332823 None
27342824 }
27352825 } ;
2736- }
2826+ }
27372827 let mut link_meta = None ;
27382828 if let ( Some ( "com.apple.messages.URLBalloonProvider" ) , Some ( balloon_part) ) = ( loaded. balloon_id . as_deref ( ) , balloon_part) {
27392829 match ( || {
0 commit comments