Merge branch 'ipad-support-1' into voice-calls-2

This commit is contained in:
Ryan Zhao 2022-03-08 17:10:40 +11:00
commit 5762445128
8 changed files with 62 additions and 51 deletions

View file

@ -718,7 +718,7 @@
C3A7219A2558C1660043A11F /* AnyPromise+Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A721992558C1660043A11F /* AnyPromise+Conversion.swift */; };
C3A7225E2558C38D0043A11F /* Promise+Retaining.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A7225D2558C38D0043A11F /* Promise+Retaining.swift */; };
C3A76A8D25DB83F90074CB90 /* PermissionMissingModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A76A8C25DB83F90074CB90 /* PermissionMissingModal.swift */; };
C3AABDDF2553ECF00042FF4C /* Array+Description.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D12553860800C340D1 /* Array+Description.swift */; };
C3AABDDF2553ECF00042FF4C /* Array+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C2A5D12553860800C340D1 /* Array+Utilities.swift */; };
C3AAFFF225AE99710089E6DD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3AAFFF125AE99710089E6DD /* AppDelegate.swift */; };
C3ADC66126426688005F1414 /* ShareVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3ADC66026426688005F1414 /* ShareVC.swift */; };
C3BBE0762554CDA60050F1E3 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3BBE0752554CDA60050F1E3 /* Configuration.swift */; };
@ -1791,7 +1791,7 @@
C3C2A5CE2553860700C340D1 /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
C3C2A5CF2553860700C340D1 /* Promise+Hashing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Hashing.swift"; sourceTree = "<group>"; };
C3C2A5D02553860800C340D1 /* Promise+Threading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Threading.swift"; sourceTree = "<group>"; };
C3C2A5D12553860800C340D1 /* Array+Description.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Description.swift"; sourceTree = "<group>"; };
C3C2A5D12553860800C340D1 /* Array+Utilities.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+Utilities.swift"; sourceTree = "<group>"; };
C3C2A5D22553860900C340D1 /* String+Trimming.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Trimming.swift"; sourceTree = "<group>"; };
C3C2A5D32553860900C340D1 /* Promise+Delaying.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Delaying.swift"; sourceTree = "<group>"; };
C3C2A5D42553860A00C340D1 /* Threading.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Threading.swift; sourceTree = "<group>"; };
@ -2428,7 +2428,7 @@
7BAF54D727ACD0E3003D12F8 /* UITableView+ReusableView.swift */,
C33FDB8A255A581200E217F9 /* AppContext.h */,
C33FDB85255A581100E217F9 /* AppContext.m */,
C3C2A5D12553860800C340D1 /* Array+Description.swift */,
C3C2A5D12553860800C340D1 /* Array+Utilities.swift */,
C33FDAA8255A57FF00E217F9 /* BuildConfiguration.swift */,
B8F5F58225EC94A6003BF8D4 /* Collection+Subscripting.swift */,
B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */,
@ -4745,7 +4745,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C3AABDDF2553ECF00042FF4C /* Array+Description.swift in Sources */,
C3AABDDF2553ECF00042FF4C /* Array+Utilities.swift in Sources */,
C32C5A47256DB8F0003C73A2 /* ECKeyPair+Hexadecimal.swift in Sources */,
C3D9E41525676C320040E4F3 /* Storage.swift in Sources */,
C32C5D83256DD5B6003C73A2 /* SSKKeychainStorage.swift in Sources */,

View file

@ -12,6 +12,8 @@ enum Onboarding {
TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = x25519PublicKey
Storage.writeSync { transaction in
let user = Contact(sessionID: x25519PublicKey)
user.isApproved = true
user.didApproveMe = true
Storage.shared.setContact(user, using: transaction)
}
switch self {

View file

@ -5,6 +5,7 @@ enum ContactUtilities {
// Collect all contacts
var result: [String] = []
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
guard
let thread: TSContactThread = object as? TSContactThread,

View file

@ -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)
// Want to sync contacts for visible threads and blocked contacts between devices
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 (
// Skip the current user
contact.sessionID != currentUserPublicKey && (
// Include already approved contacts
contact.isApproved ||
contact.didApproveMe ||
// 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
}
// Can just default the 'hasX' values to true as they will be set to this
// when converting to proto anyway
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
// Can just default the 'hasX' values to true as they will be set to this
// when converting to proto anyway
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()
}
}
// 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

View file

@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) NSString *authorId;
// convenience method for expiring a message which was just read
- (void)markAsReadNowWithSendReadReceipt:(BOOL)sendReadReceipt
- (void)markAsReadNowWithTrySendReadReceipt:(BOOL)trySendReadReceipt
transaction:(YapDatabaseReadWriteTransaction *)transaction;
- (void)setNotificationIdentifier:(NSString * _Nullable)notificationIdentifier

View file

@ -240,12 +240,6 @@ extension MessageReceiver {
thread.remove(with: transaction)
}
}
else {
// Otherwise create and save the thread
let thread = TSContactThread.getOrCreateThread(withContactSessionID: sessionID, transaction: transaction)
thread.shouldBeVisible = true
thread.save(with: transaction)
}
}
// FIXME: 'OWSBlockingManager' manages it's own dbConnection and transactions so we have to dispatch this to prevent deadlocks
@ -298,7 +292,7 @@ extension MessageReceiver {
}
if let messageToDelete = localMessage {
if let incomingMessage = messageToDelete as? TSIncomingMessage {
incomingMessage.markAsReadNow(withSendReadReceipt: false, transaction: transaction)
incomingMessage.markAsReadNow(withTrySendReadReceipt: false, transaction: transaction)
if let notificationIdentifier = incomingMessage.notificationIdentifier, !notificationIdentifier.isEmpty {
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [notificationIdentifier])
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [notificationIdentifier])

View file

@ -5,3 +5,9 @@ public extension Array where Element : CustomStringConvertible {
return "[ " + map { $0.description }.joined(separator: ", ") + " ]"
}
}
public extension Array where Element: Hashable {
func asSet() -> Set<Element> {
return Set(self)
}
}

View file

@ -41,6 +41,13 @@ public class MessageRequestsMigration : OWSDatabaseMigration {
threads.append(thread)
}
if let user = Storage.shared.getUser() {
user.isApproved = true
user.didApproveMe = true
contacts.insert(user)
}
Storage.write(with: { transaction in
contacts.forEach { contact in
Storage.shared.setContact(contact, using: transaction)