@ -1,3 +1,4 @@
import SessionUtilitiesKit
extension ConfigurationMessage {
@ -10,8 +11,7 @@ extension ConfigurationMessage {
let profileKey = user . profileEncryptionKey ? . keyData
var closedGroups : Set < ClosedGroup > = [ ]
var openGroups : Set < String > = [ ]
var contacts : Set < Contact > = [ ]
var contactCount = 0
var contacts : Set < ConfigurationMessage . Contact > = [ ]
let populateDataClosure : ( YapDatabaseReadTransaction ) -> ( ) = { transaction in
TSGroupThread . enumerateCollectionObjects ( with : transaction ) { object , _ in
@ -48,47 +48,48 @@ extension ConfigurationMessage {
}
let currentUserPublicKey : String = getUserHexEncodedPublicKey ( )
var truncatedContacts = storage . getAllContacts ( with : transaction )
if truncatedContacts . count > 200 {
truncatedContacts = Set ( Array ( truncatedContacts ) [ 0. . < 200 ] )
}
truncatedContacts . forEach { contact in
let publicKey = contact . sessionID
let threadID = TSContactThread . threadID ( fromContactSessionID : publicKey )
// W a n t t o s y n c c o n t a c t s f o r v i s i b l e t h r e a d s a n d b l o c k e d c o n t a c t s b e t w e e n d e v i c e s
guard
publicKey != currentUserPublicKey && (
TSContactThread . fetch ( uniqueId : threadID , transaction : transaction ) ? . shouldBeVisible = = true ||
SSKEnvironment . shared . blockingManager . isRecipientIdBlocked ( publicKey )
contacts = storage . getAllContacts ( with : transaction )
. filter { contact -> Bool in
let threadID = TSContactThread . threadID ( fromContactSessionID : contact . sessionID )
return (
// S k i p t h e c u r r e n t u s e r
contact . sessionID != currentUserPublicKey && (
// I n c l u d e a l r e a d y a p p r o v e d c o n t a c t s
contact . isApproved ||
contact . didApproveMe ||
// S y n c b l o c k e d c o n t a c t s
SSKEnvironment . shared . blockingManager . isRecipientIdBlocked ( contact . sessionID ) ||
// C o n t a c t s w h i c h h a v e v i s i b l e t h r e a d s ( s a n i t y c h e c k - s h o u l d b e i n c l u d e d a s a l r e a d y a p p r o v e d )
TSContactThread . fetch ( uniqueId : threadID , transaction : transaction ) ? . shouldBeVisible = = true
)
)
else {
return
}
// C a n j u s t d e f a u l t t h e ' h a s X ' v a l u e s t o t r u e a s t h e y w i l l b e s e t t o t h i s
// w h e n c o n v e r t i n g t o p r o t o a n y w a y
let profilePictureURL = contact . profilePictureURL
let profileKey = contact . profileEncryptionKey ? . keyData
let contact = ConfigurationMessage . Contact (
publicKey : publicKey ,
displayName : ( contact . name ? ? publicKey ) ,
profilePictureURL : profilePictureURL ,
profileKey : profileKey ,
hasIsApproved : true ,
isApproved : contact . isApproved ,
hasIsBlocked : true ,
isBlocked : contact . isBlocked ,
hasDidApproveMe : true ,
didApproveMe : contact . didApproveMe
)
contacts . insert ( contact )
contactCount += 1
. map { contact -> ConfigurationMessage . Contact in
// C a n j u s t d e f a u l t t h e ' h a s X ' v a l u e s t o t r u e a s t h e y w i l l b e s e t t o t h i s
// w h e n c o n v e r t i n g t o p r o t o a n y w a y
let profilePictureURL = contact . profilePictureURL
let profileKey = contact . profileEncryptionKey ? . keyData
return ConfigurationMessage . Contact (
publicKey : contact . sessionID ,
displayName : ( contact . name ? ? contact . sessionID ) ,
profilePictureURL : profilePictureURL ,
profileKey : profileKey ,
hasIsApproved : true ,
isApproved : contact . isApproved ,
hasIsBlocked : true ,
isBlocked : contact . isBlocked ,
hasDidApproveMe : true ,
didApproveMe : contact . didApproveMe
)
}
. asSet ( )
}
}
// I f w e a r e p r o v i d e d w i t h a t r a n s a c t i o n t h e n r e a d t h e d a t a b a s e d o n t h e s t a t e o f t h e d a t a b a s e
// f r o m w i t h i n t h e t r a n s a c t i o n r a t h e r t h a n t h e s t a t e i n d i s k