Rename LokiStorageAPI → LokiFileServerAPI

pull/92/head
Niels Andriesse 4 years ago
parent d502aeaa80
commit cc40862740

@ -777,7 +777,7 @@ static NSTimeInterval launchStartedAt;
[self startLongPollerIfNeeded];
// Loki: Get device links
[LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber];
[LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber];
if (![UIApplication sharedApplication].isRegisteredForRemoteNotifications) {
OWSLogInfo(@"Retrying to register for remote notifications since user hasn't registered yet.");
@ -1448,7 +1448,7 @@ static NSTimeInterval launchStartedAt;
[self startLongPollerIfNeeded];
// Loki: Get device links
[LKStorageAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber];
[LKFileServerAPI getDeviceLinksAssociatedWith:self.tsAccountManager.localNumber];
}
}

@ -175,7 +175,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
dismiss(animated: true, completion: nil)
let master = DeviceLink.Device(hexEncodedPublicKey: deviceLink.master.hexEncodedPublicKey, signature: linkingAuthorizationMessage.masterSignature)
let signedDeviceLink = DeviceLink(between: master, and: deviceLink.slave)
LokiStorageAPI.addDeviceLink(signedDeviceLink).done {
LokiFileServerAPI.addDeviceLink(signedDeviceLink).done {
self.delegate?.handleDeviceLinkAuthorized(signedDeviceLink) // Intentionally capture self strongly
}.catch { error in
print("[Loki] Failed to add device link due to error: \(error).")
@ -191,7 +191,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
subtitleLabel.text = NSLocalizedString("Your device has been linked successfully", comment: "")
mnemonicLabel.isHidden = true
buttonStackView.isHidden = true
LokiStorageAPI.addDeviceLink(deviceLink).catch { error in
LokiFileServerAPI.addDeviceLink(deviceLink).catch { error in
print("[Loki] Failed to add device link due to error: \(error).")
}
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in

@ -152,7 +152,7 @@ final class DeviceLinksVC : UIViewController, UITableViewDataSource, UITableView
}
private func removeDeviceLink(_ deviceLink: DeviceLink) {
LokiStorageAPI.removeDeviceLink(deviceLink).done { [weak self] in
LokiFileServerAPI.removeDeviceLink(deviceLink).done { [weak self] in
let linkedDeviceHexEncodedPublicKey = deviceLink.other.hexEncodedPublicKey
guard let thread = TSContactThread.fetch(uniqueId: TSContactThread.threadId(fromContactId: linkedDeviceHexEncodedPublicKey)) else { return }
let unlinkDeviceMessage = UnlinkDeviceMessage(thread: thread)!

@ -157,7 +157,7 @@ final class LandingVC : UIViewController, LinkDeviceVCDelegate, DeviceLinkingMod
TSAccountManager.sharedInstance().phoneNumberAwaitingVerification = keyPair.hexEncodedPublicKey
TSAccountManager.sharedInstance().didRegister()
setUserInteractionEnabled(false)
let _ = LokiStorageAPI.getDeviceLinks(associatedWith: hexEncodedPublicKey).done(on: DispatchQueue.main) { [weak self] deviceLinks in
let _ = LokiFileServerAPI.getDeviceLinks(associatedWith: hexEncodedPublicKey).done(on: DispatchQueue.main) { [weak self] deviceLinks in
guard let self = self else { return }
defer { self.setUserInteractionEnabled(true) }
guard deviceLinks.count < 2 else {

@ -411,7 +411,7 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
NSData *encryptedAvatarData = [self encryptProfileData:avatarData profileKey:newProfileKey];
OWSAssertDebug(encryptedAvatarData.length > 0);
[[LKStorageAPI setProfilePicture:encryptedAvatarData]
[[LKFileServerAPI setProfilePicture:encryptedAvatarData]
.thenOn(dispatch_get_main_queue(), ^(NSString *url) {
[self.localUserProfile updateWithProfileKey:newProfileKey dbConnection:self.dbConnection completion:^{
successBlock(url);

@ -132,7 +132,7 @@ public final class LokiAPI : NSObject {
if timeSinceLastUpdate > deviceLinkUpdateInterval {
storage.dbReadConnection.read { transaction in
let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey
LokiStorageAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done(on: DispatchQueue.global()) { _ in
LokiFileServerAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done(on: DispatchQueue.global()) { _ in
getDestinations()
lastDeviceLinkUpdate[hexEncodedPublicKey] = Date()
}.catch(on: DispatchQueue.global()) { error in

@ -1,6 +1,6 @@
import PromiseKit
/// Base class for `LokiStorageAPI` and `LokiPublicChatAPI`.
/// Base class for `LokiFileServerAPI` and `LokiPublicChatAPI`.
public class LokiDotNetAPI : NSObject {
// MARK: Convenience
@ -39,7 +39,7 @@ public class LokiDotNetAPI : NSObject {
// MARK: Attachments (Public API)
public static func uploadAttachment(_ attachment: TSAttachmentStream, with attachmentID: String, to server: String) -> Promise<Void> {
let isEncryptionRequired = (server == LokiStorageAPI.server)
let isEncryptionRequired = (server == LokiFileServerAPI.server)
return Promise<Void>() { seal in
func proceed(with token: String) {
// Get the attachment
@ -88,7 +88,7 @@ public class LokiDotNetAPI : NSObject {
attachment.save()
seal.fulfill(())
}
let isProxyingRequired = (server == LokiStorageAPI.server) // Don't proxy open group requests for now
let isProxyingRequired = (server == LokiFileServerAPI.server) // Don't proxy open group requests for now
if isProxyingRequired {
let _ = LokiFileServerProxy(for: server).performLokiFileServerNSURLRequest(request as NSURLRequest).done { responseObject in
parseResponse(responseObject)
@ -119,7 +119,7 @@ public class LokiDotNetAPI : NSObject {
task.resume()
}
}
if server == LokiStorageAPI.server {
if server == LokiFileServerAPI.server {
proceed(with: "loki") // Uploads to the Loki File Server shouldn't include any personally identifiable information so use a dummy auth token
} else {
getAuthToken(for: server).done(on: DispatchQueue.global()) { token in

@ -1,7 +1,7 @@
import PromiseKit
@objc(LKStorageAPI)
public final class LokiStorageAPI : LokiDotNetAPI {
@objc(LKFileServerAPI)
public final class LokiFileServerAPI : LokiDotNetAPI {
// MARK: Settings
#if DEBUG

@ -37,7 +37,7 @@ internal class LokiFileServerProxy : LokiHTTPClient {
// MARK: Proxying
override internal func perform(_ request: TSRequest, withCompletionQueue queue: DispatchQueue = DispatchQueue.main) -> LokiAPI.RawResponsePromise {
let isLokiFileServer = (server == LokiStorageAPI.server)
let isLokiFileServer = (server == LokiFileServerAPI.server)
guard isLokiFileServer else { return super.perform(request, withCompletionQueue: queue) } // Don't proxy open group requests for now
return performLokiFileServerNSURLRequest(request, withCompletionQueue: queue)
}

@ -13,7 +13,7 @@ public enum LokiRSSFeedProxy {
}
public static func fetchContent(for url: String) -> Promise<String> {
let server = LokiStorageAPI.server
let server = LokiFileServerAPI.server
let endpoints = [ "messenger-updates/feed" : "loki/v1/rss/messenger", "loki.network/feed" : "loki/v1/rss/loki" ]
let endpoint = endpoints.first { url.lowercased().contains($0.key) }!.value
let url = URL(string: server + "/" + endpoint)!

@ -192,7 +192,7 @@ public final class LokiPublicChatPoller : NSObject {
if !hexEncodedPublicKeysToUpdate.isEmpty {
let storage = OWSPrimaryStorage.shared()
storage.dbReadConnection.read { transaction in
LokiStorageAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in
LokiFileServerAPI.getDeviceLinks(associatedWith: hexEncodedPublicKeysToUpdate).done(on: DispatchQueue.global()) { _ in
proceed()
hexEncodedPublicKeysToUpdate.forEach {
LokiAPI.lastDeviceLinkUpdate[$0] = Date()

@ -1249,7 +1249,7 @@ NS_ASSUME_NONNULL_BEGIN
}]) {
return;
}
[LKStorageAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet<LKDeviceLink *> *deviceLinks) {
[LKFileServerAPI getDeviceLinksAssociatedWith:userHexEncodedPublicKey].thenOn(dispatch_get_main_queue(), ^(NSSet<LKDeviceLink *> *deviceLinks) {
if ([deviceLinks contains:^BOOL(LKDeviceLink *deviceLink) {
return [deviceLink.master.hexEncodedPublicKey isEqual:senderHexEncodedPublicKey] && [deviceLink.slave.hexEncodedPublicKey isEqual:userHexEncodedPublicKey];
}]) {

@ -484,9 +484,6 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
});
}
failure:^(NSError *error) {
OWSLogError(@"Could not obtain UD sender certificate: %@", error);
// Proceed using non-UD message sends.
dispatch_async([OWSDispatch sendingQueue], ^{
[self sendMessageToService:message senderCertificate:nil success:success failure:failure];
});

@ -65,14 +65,13 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f;
- (void)run
{
__block TSAttachmentStream *attachmentStream;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
attachmentStream = [TSAttachmentStream fetchObjectWithUniqueID:self.attachmentId transaction:transaction];
}];
if (!attachmentStream) {
OWSProdError([OWSAnalyticsEvents messageSenderErrorCouldNotLoadAttachment]);
NSError *error = OWSErrorMakeFailedToSendOutgoingMessageError();
// Not finding local attachment is a terminal failure.
// Not finding a local attachment is a terminal failure
error.isRetryable = NO;
[self reportError:error];
return;
@ -90,9 +89,9 @@ static const CGFloat kAttachmentUploadProgressTheta = 0.001f;
[self.dbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
publicChat = [LKDatabaseUtilities getPublicChatForThreadID:self.threadID transaction:transaction];
}];
NSString *server = (publicChat != nil) ? publicChat.server : LKStorageAPI.server;
NSString *server = (publicChat != nil) ? publicChat.server : LKFileServerAPI.server;
[[LKStorageAPI uploadAttachment:attachmentStream withID:self.attachmentId toServer:server]
[[LKFileServerAPI uploadAttachment:attachmentStream withID:self.attachmentId toServer:server]
.thenOn(dispatch_get_main_queue(), ^() {
[self reportSuccess];
})

Loading…
Cancel
Save