Fix duplication

This commit is contained in:
Niels Andriesse 2019-10-15 09:43:58 +11:00
parent 48883bf1f1
commit 131c27d089
6 changed files with 21 additions and 38 deletions

View file

@ -4,12 +4,12 @@ final class DisplayNameVC : OnboardingBaseViewController {
private lazy var userNameTextField: UITextField = {
let result = UITextField()
result.textColor = Theme.primaryColor
result.font = UIFont.ows_dynamicTypeBodyClamped
result.font = .ows_dynamicTypeBodyClamped
result.textAlignment = .center
let placeholder = NSMutableAttributedString(string: NSLocalizedString("Display Name", comment: ""))
placeholder.addAttribute(.foregroundColor, value: Theme.placeholderColor, range: NSRange(location: 0, length: placeholder.length))
result.attributedPlaceholder = placeholder
result.tintColor = UIColor.lokiGreen()
result.tintColor = .lokiGreen()
result.accessibilityIdentifier = "onboarding.accountDetailsStep.userNameTextField"
result.keyboardAppearance = .dark
return result

View file

@ -85,7 +85,7 @@ public final class LokiPublicChatManager: NSObject {
}
// Save the group chat
self.storage.setGroupChat(chat, for: thread.uniqueId!, in: transaction)
LokiDatabaseUtilities.setGroupChat(chat, for: thread.uniqueId!, in: transaction)
}
// Update chats and pollers
@ -101,7 +101,7 @@ public final class LokiPublicChatManager: NSObject {
private func refreshChatsAndPollers() {
storage.dbReadConnection.read { transaction in
let newChats = self.storage.getAllGroupChats(in: transaction)
let newChats = LokiDatabaseUtilities.getAllGroupChats(in: transaction)
// Remove any chats that don't exist in the database
let removedChatThreadIds = self.chats.keys.filter { !newChats.keys.contains($0) }
@ -129,7 +129,7 @@ public final class LokiPublicChatManager: NSObject {
// Remove the chat from the db
storage.dbReadWriteConnection.readWrite { transaction in
self.storage.removeGroupChat(for: threadId, in: transaction)
LokiDatabaseUtilities.removeGroupChat(for: threadId, in: transaction)
}
refreshChatsAndPollers()

View file

@ -310,7 +310,7 @@ public final class LokiAPI : NSObject {
var candidates: [Mention] = []
// Gather candidates
var groupChat: LokiGroupChat?
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
storage.dbReadConnection.read { transaction in
groupChat = LokiDatabaseUtilities.getGroupChat(for: threadID, in: transaction)
}
storage.dbReadConnection.read { transaction in

View file

@ -4,6 +4,7 @@ public final class LokiDatabaseUtilities : NSObject {
private override init() { }
// MARK: Quotes
@objc(getServerIDForQuoteWithID:quoteeHexEncodedPublicKey:threadID:transaction:)
public static func getServerID(quoteID: UInt64, quoteeHexEncodedPublicKey: String, threadID: String, transaction: YapDatabaseReadTransaction) -> UInt64 {
guard let message = TSInteraction.interactions(withTimestamp: quoteID, filter: { interaction in
@ -20,28 +21,37 @@ public final class LokiDatabaseUtilities : NSObject {
return message.groupChatServerID
}
// MARK: Device Links
@objc(getMasterHexEncodedPublicKeyFor:in:)
public static func objc_getMasterHexEncodedPublicKey(for slaveHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> String? {
return OWSPrimaryStorage.shared().getMasterHexEncodedPublicKey(for: slaveHexEncodedPublicKey, in: transaction)
}
// MARK: Group Chats
private static let groupChatCollection = "LokiGroupChatCollection"
@objc(getAllGroupChats:)
public static func getAllGroupChats(in transaction: YapDatabaseReadTransaction) -> [String:LokiGroupChat] {
return OWSPrimaryStorage.shared().getAllGroupChats(in: transaction)
var result = [String:LokiGroupChat]()
transaction.enumerateKeysAndObjects(inCollection: groupChatCollection) { threadID, object, _ in
guard let groupChat = object as? LokiGroupChat else { return }
result[threadID] = groupChat
}
return result
}
@objc(getGroupChatForThreadID:transaction:)
public static func getGroupChat(for threadID: String, in transaction: YapDatabaseReadTransaction) -> LokiGroupChat? {
return OWSPrimaryStorage.shared().getGroupChat(for: threadID, in: transaction)
return transaction.object(forKey: threadID, inCollection: groupChatCollection) as? LokiGroupChat
}
@objc(setGroupChat:threadID:transaction:)
public static func setGroupChat(_ groupChat: LokiGroupChat, for threadID: String, in transaction: YapDatabaseReadWriteTransaction) {
return OWSPrimaryStorage.shared().setGroupChat(groupChat, for: threadID, in: transaction)
transaction.setObject(groupChat, forKey: threadID, inCollection: groupChatCollection)
}
@objc(removeGroupChatForThreadID:transaction:)
public static func removeGroupChat(for threadID: String, in transaction: YapDatabaseReadWriteTransaction) {
return OWSPrimaryStorage.shared().removeGroupChat(for: threadID, in: transaction)
transaction.removeObject(forKey: threadID, inCollection: groupChatCollection)
}
}

View file

@ -1,7 +1,6 @@
public extension OWSPrimaryStorage {
// MARK: Device Links
private func getDeviceLinkCollection(for primaryDevice: String) -> String {
return "LokiDeviceLinkCollection-\(primaryDevice)"
}
@ -52,30 +51,4 @@ public extension OWSPrimaryStorage {
public func getMasterHexEncodedPublicKey(for slaveHexEncodedPublicKey: String, in transaction: YapDatabaseReadTransaction) -> String? {
return getDeviceLink(for: slaveHexEncodedPublicKey, in: transaction)?.master.hexEncodedPublicKey
}
// MARK: Group Chats
private var groupChatCollection: String {
return "LokiGroupChatCollection"
}
public func getAllGroupChats(in transaction: YapDatabaseReadTransaction) -> [String:LokiGroupChat] {
var result = [String:LokiGroupChat]()
transaction.enumerateKeysAndObjects(inCollection: groupChatCollection) { threadID, object, _ in
guard let groupChat = object as? LokiGroupChat else { return }
result[threadID] = groupChat
}
return result
}
public func getGroupChat(for threadID: String, in transaction: YapDatabaseReadTransaction) -> LokiGroupChat? {
return transaction.object(forKey: threadID, inCollection: groupChatCollection) as? LokiGroupChat
}
public func setGroupChat(_ groupChat: LokiGroupChat, for threadID: String, in transaction: YapDatabaseReadWriteTransaction) {
transaction.setObject(groupChat, forKey: threadID, inCollection: groupChatCollection)
}
public func removeGroupChat(for threadID: String, in transaction: YapDatabaseReadWriteTransaction) {
transaction.removeObject(forKey: threadID, inCollection: groupChatCollection)
}
}

View file

@ -503,7 +503,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
if ([message isKindOfClass:[OWSOutgoingSyncMessage class]]) {
[recipientIds addObject:self.tsAccountManager.localNumber];
} else if (thread.isGroupThread) {
[self.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) {
[self.primaryStorage.dbReadConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
LKGroupChat *groupChat = [LKDatabaseUtilities getGroupChatForThreadID:thread.uniqueId transaction:transaction];
[recipientIds addObject:groupChat.server];
}];