pull/220/head
nielsandriesse 5 years ago
parent e0da0fd64e
commit c0b4a548bf

@ -181,8 +181,8 @@ class MediaPageViewController: UIPageViewController, UIPageViewControllerDataSou
self.view.addSubview(bottomContainer) self.view.addSubview(bottomContainer)
bottomContainer.autoPinWidthToSuperview() bottomContainer.autoPinWidthToSuperview()
bottomContainer.autoPinEdge(toSuperviewEdge: .bottom) bottomContainer.autoPinEdge(toSuperviewSafeArea: .bottom)
footerBar.autoPinEdge(.bottom, to: .bottom, of: view) footerBar.autoPinEdge(toSuperviewSafeArea: .bottom)
footerBar.autoSetDimension(.height, toSize: 44) footerBar.autoSetDimension(.height, toSize: 44)
updateTitle() updateTitle()

@ -1027,10 +1027,26 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
- (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID - (nullable NSString *)profileNameForRecipientWithID:(NSString *)recipientID
{ {
if ([self.tsAccountManager.localNumber isEqualToString:recipientID]) {
return self.localUserProfile.profileName;
}
__block OWSUserProfile *userProfile;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
userProfile = [OWSUserProfile fetchObjectWithUniqueID:recipientID transaction:transaction];
}];
if (userProfile != nil) {
return userProfile.profileName;
}
__block NSString *result; __block NSString *result;
[LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [LKStorage writeSyncWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
result = [self profileNameForRecipientWithID:recipientID transaction:transaction]; result = [self profileNameForRecipientWithID:recipientID transaction:transaction];
} error:nil]; } error:nil];
return result; return result;
} }

@ -9,7 +9,6 @@ public final class LokiAPI : NSObject {
// MARK: Settings // MARK: Settings
private static let maxRetryCount: UInt = 4 private static let maxRetryCount: UInt = 4
private static let defaultTimeout: TimeInterval = 20 private static let defaultTimeout: TimeInterval = 20
private static let longPollingTimeout: TimeInterval = 40
internal static var powDifficulty: UInt = 1 internal static var powDifficulty: UInt = 1
/// - Note: Changing this on the fly is not recommended. /// - Note: Changing this on the fly is not recommended.
@ -51,19 +50,17 @@ public final class LokiAPI : NSObject {
} }
} }
internal static func getRawMessages(from target: LokiAPITarget, usingLongPolling useLongPolling: Bool) -> RawResponsePromise { internal static func getRawMessages(from target: LokiAPITarget) -> RawResponsePromise {
let lastHashValue = getLastMessageHashValue(for: target) ?? "" let lastHashValue = getLastMessageHashValue(for: target) ?? ""
let parameters = [ "pubKey" : getUserHexEncodedPublicKey(), "lastHash" : lastHashValue ] let parameters = [ "pubKey" : getUserHexEncodedPublicKey(), "lastHash" : lastHashValue ]
let headers: [String:String]? = useLongPolling ? [ "X-Loki-Long-Poll" : "true" ] : nil return invoke(.getMessages, on: target, associatedWith: getUserHexEncodedPublicKey(), parameters: parameters)
let timeout: TimeInterval? = useLongPolling ? longPollingTimeout : nil
return invoke(.getMessages, on: target, associatedWith: getUserHexEncodedPublicKey(), parameters: parameters, headers: headers, timeout: timeout)
} }
// MARK: Public API // MARK: Public API
public static func getMessages() -> Promise<Set<MessageListPromise>> { public static func getMessages() -> Promise<Set<MessageListPromise>> {
return attempt(maxRetryCount: maxRetryCount, recoveringOn: LokiAPI.workQueue) { return attempt(maxRetryCount: maxRetryCount, recoveringOn: LokiAPI.workQueue) {
getTargetSnodes(for: getUserHexEncodedPublicKey()).mapValues2 { targetSnode in getTargetSnodes(for: getUserHexEncodedPublicKey()).mapValues2 { targetSnode in
getRawMessages(from: targetSnode, usingLongPolling: false).map2 { parseRawMessagesResponse($0, from: targetSnode) } getRawMessages(from: targetSnode).map2 { parseRawMessagesResponse($0, from: targetSnode) }
}.map2 { Set($0) } }.map2 { Set($0) }
} }
} }

@ -96,7 +96,7 @@ public final class LokiPoller : NSObject {
private func poll(_ target: LokiAPITarget, seal longTermSeal: Resolver<Void>) -> Promise<Void> { private func poll(_ target: LokiAPITarget, seal longTermSeal: Resolver<Void>) -> Promise<Void> {
guard !hasStopped else { return Promise { $0.fulfill(()) } } guard !hasStopped else { return Promise { $0.fulfill(()) } }
return LokiAPI.getRawMessages(from: target, usingLongPolling: false).then(on: DispatchQueue.main) { [weak self] rawResponse -> Promise<Void> in return LokiAPI.getRawMessages(from: target).then(on: DispatchQueue.main) { [weak self] rawResponse -> Promise<Void> in
guard let strongSelf = self, !strongSelf.hasStopped else { return Promise { $0.fulfill(()) } } guard let strongSelf = self, !strongSelf.hasStopped else { return Promise { $0.fulfill(()) } }
let messages = LokiAPI.parseRawMessagesResponse(rawResponse, from: target) let messages = LokiAPI.parseRawMessagesResponse(rawResponse, from: target)
strongSelf.onMessagesReceived(messages) strongSelf.onMessagesReceived(messages)

@ -85,6 +85,8 @@ public final class MentionsManager : NSObject {
populate(in: transaction) populate(in: transaction)
} }
} }
if !result.isEmpty {
userPublicKeyCache[threadID] = result userPublicKeyCache[threadID] = result
} }
} }
}

Loading…
Cancel
Save