Merge branch 'dev' into feature/session-id-blinding-part-2

# Conflicts:
#	Session.xcodeproj/project.pbxproj
#	Session/Utilities/ContactUtilities.swift
#	SessionUtilitiesKit/General/Array+Utilities.swift
pull/592/head
Morgan Pretty 2 years ago
commit d298bcdb4e

@ -6,10 +6,8 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
private var threads: YapDatabaseViewMappings! private var threads: YapDatabaseViewMappings!
private var threadViewModelCache: [String:ThreadViewModel] = [:] // Thread ID to ThreadViewModel private var threadViewModelCache: [String:ThreadViewModel] = [:] // Thread ID to ThreadViewModel
private var tableViewTopConstraint: NSLayoutConstraint! private var tableViewTopConstraint: NSLayoutConstraint!
private var unreadMessageRequestCount: UInt = 0 private var unreadMessageRequestCount: UInt {
OWSMessageUtils.sharedManager().unreadMessageRequestCount()
private var messageRequestCount: UInt {
threads.numberOfItems(inGroup: TSMessageRequestGroup)
} }
private var threadCount: UInt { private var threadCount: UInt {
@ -182,7 +180,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch section { switch section {
case 0: case 0:
if messageRequestCount > 0 && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] { if unreadMessageRequestCount > 0 && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
return 1 return 1
} }
@ -264,9 +262,6 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
} }
} }
// Update the number of unread message requests
unreadMessageRequestCount = OWSMessageUtils.sharedManager().unreadMessageRequestCount()
// If there are no unread message requests then hide the message request banner // If there are no unread message requests then hide the message request banner
if unreadMessageRequestCount == 0 { if unreadMessageRequestCount == 0 {
CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] = true CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] = true
@ -295,8 +290,6 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
// If we need to unhide the message request row and then re-insert it // If we need to unhide the message request row and then re-insert it
if !messageRequestChanges.isEmpty { if !messageRequestChanges.isEmpty {
// Update the number of unread message requests
unreadMessageRequestCount = OWSMessageUtils.sharedManager().unreadMessageRequestCount()
// If there are no unread message requests then hide the message request banner // If there are no unread message requests then hide the message request banner
if unreadMessageRequestCount == 0 && tableView.numberOfRows(inSection: 0) == 1 { if unreadMessageRequestCount == 0 && tableView.numberOfRows(inSection: 0) == 1 {
@ -304,10 +297,10 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
tableView.deleteRows(at: [IndexPath(row: 0, section: 0)], with: .automatic) tableView.deleteRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
} }
else { else {
if tableView.numberOfRows(inSection: 0) == 1 && Int(messageRequestCount) <= 0 { if tableView.numberOfRows(inSection: 0) == 1 && Int(unreadMessageRequestCount) <= 0 {
tableView.deleteRows(at: [IndexPath(row: 0, section: 0)], with: .automatic) tableView.deleteRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
} }
else if tableView.numberOfRows(inSection: 0) == 0 && Int(messageRequestCount) > 0 && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] { else if tableView.numberOfRows(inSection: 0) == 0 && Int(unreadMessageRequestCount) > 0 && !CurrentAppContext().appUserDefaults()[.hasHiddenMessageRequests] {
tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic) tableView.insertRows(at: [IndexPath(row: 0, section: 0)], with: .automatic)
} }
} }

@ -1,3 +1,4 @@
import SessionUtilitiesKit
extension ConfigurationMessage { extension ConfigurationMessage {
@ -10,8 +11,7 @@ extension ConfigurationMessage {
let profileKey = user.profileEncryptionKey?.keyData let profileKey = user.profileEncryptionKey?.keyData
var closedGroups: Set<ClosedGroup> = [] var closedGroups: Set<ClosedGroup> = []
var openGroups: Set<String> = [] var openGroups: Set<String> = []
var contacts: Set<Contact> = [] var contacts: Set<ConfigurationMessage.Contact> = []
var contactCount = 0
let populateDataClosure: (YapDatabaseReadTransaction) -> () = { transaction in let populateDataClosure: (YapDatabaseReadTransaction) -> () = { transaction in
TSGroupThread.enumerateCollectionObjects(with: transaction) { object, _ in TSGroupThread.enumerateCollectionObjects(with: transaction) { object, _ in
@ -48,47 +48,48 @@ extension ConfigurationMessage {
} }
let currentUserPublicKey: String = getUserHexEncodedPublicKey() let currentUserPublicKey: String = getUserHexEncodedPublicKey()
var truncatedContacts = storage.getAllContacts(with: transaction)
if truncatedContacts.count > 200 { contacts = storage.getAllContacts(with: transaction)
truncatedContacts = Set(Array(truncatedContacts)[0..<200]) .filter { contact -> Bool in
} let threadID = TSContactThread.threadID(fromContactSessionID: contact.sessionID)
truncatedContacts.forEach { contact in return (
let publicKey = contact.sessionID // Skip the current user
let threadID = TSContactThread.threadID(fromContactSessionID: publicKey) contact.sessionID != currentUserPublicKey && (
// Want to sync contacts for visible threads and blocked contacts between devices // Include already approved contacts
guard contact.isApproved ||
publicKey != currentUserPublicKey && ( contact.didApproveMe ||
TSContactThread.fetch(uniqueId: threadID, transaction: transaction)?.shouldBeVisible == true ||
SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(publicKey) // Sync blocked contacts
SSKEnvironment.shared.blockingManager.isRecipientIdBlocked(contact.sessionID) ||
// Contacts which have visible threads (sanity check - should be included as already approved)
TSContactThread.fetch(uniqueId: threadID, transaction: transaction)?.shouldBeVisible == true
)
) )
else {
return
} }
.map { contact -> ConfigurationMessage.Contact in
// Can just default the 'hasX' values to true as they will be set to this // Can just default the 'hasX' values to true as they will be set to this
// when converting to proto anyway // when converting to proto anyway
let profilePictureURL = contact.profilePictureURL let profilePictureURL = contact.profilePictureURL
let profileKey = contact.profileEncryptionKey?.keyData let profileKey = contact.profileEncryptionKey?.keyData
let contact = ConfigurationMessage.Contact(
publicKey: publicKey, return ConfigurationMessage.Contact(
displayName: (contact.name ?? publicKey), publicKey: contact.sessionID,
profilePictureURL: profilePictureURL, displayName: (contact.name ?? contact.sessionID),
profileKey: profileKey, profilePictureURL: profilePictureURL,
hasIsApproved: true, profileKey: profileKey,
isApproved: contact.isApproved, hasIsApproved: true,
hasIsBlocked: true, isApproved: contact.isApproved,
isBlocked: contact.isBlocked, hasIsBlocked: true,
hasDidApproveMe: true, isBlocked: contact.isBlocked,
didApproveMe: contact.didApproveMe hasDidApproveMe: true,
) didApproveMe: contact.didApproveMe
)
contacts.insert(contact) }
contactCount += 1 .asSet()
} }
}
// If we are provided with a transaction then read the data based on the state of the database // If we are provided with a transaction then read the data based on the state of the database
// from within the transaction rather than the state in disk // from within the transaction rather than the state in disk

@ -16,6 +16,7 @@ public enum ContactUtilities {
// Collect all contacts // Collect all contacts
var result: [Contact] = [] var result: [Contact] = []
Storage.read { transaction in Storage.read { transaction in
// FIXME: If a user deletes a contact thread they will no longer appear in this list (ie. won't be an option for closed group conversations)
TSContactThread.enumerateCollectionObjects(with: transaction) { object, _ in TSContactThread.enumerateCollectionObjects(with: transaction) { object, _ in
guard let contact: Contact = approvedContact(in: object, using: transaction) else { return } guard let contact: Contact = approvedContact(in: object, using: transaction) else { return }

@ -6,18 +6,8 @@ public extension Array where Element : CustomStringConvertible {
} }
} }
public extension Array { public extension Array where Element: Hashable {
func appending(_ other: Element) -> [Element] { func asSet() -> Set<Element> {
var updatedArray: [Element] = self return Set(self)
updatedArray.append(other)
return updatedArray
}
func appending(_ other: [Element]) -> [Element] {
var updatedArray: [Element] = self
updatedArray.append(contentsOf: other)
return updatedArray
} }
} }

Loading…
Cancel
Save