Hook up new messaging API

pull/8/head
Niels Andriesse 6 years ago
parent 1c4c47ab33
commit 72cc345734

@ -604,8 +604,7 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
private func string(for messageReceiptStatus: MessageReceiptStatus) -> String { private func string(for messageReceiptStatus: MessageReceiptStatus) -> String {
switch messageReceiptStatus { switch messageReceiptStatus {
case .calculatingPoW: case .calculatingPoW:
return NSLocalizedString("Calculating proof of work", return NSLocalizedString("Calculating proof of work", comment: "")
comment: "Status label for messages which are calculating proof of work.")
case .uploading: case .uploading:
return NSLocalizedString("MESSAGE_METADATA_VIEW_MESSAGE_STATUS_UPLOADING", return NSLocalizedString("MESSAGE_METADATA_VIEW_MESSAGE_STATUS_UPLOADING",
comment: "Status label for messages which are uploading.") comment: "Status label for messages which are uploading.")

@ -111,8 +111,7 @@ public class MessageRecipientStatusUtils: NSObject {
return (.failed, NSLocalizedString("MESSAGE_STATUS_FAILED", comment: "status message for failed messages")) return (.failed, NSLocalizedString("MESSAGE_STATUS_FAILED", comment: "status message for failed messages"))
case .sending: case .sending:
if outgoingMessage.isCalculatingPoW { if outgoingMessage.isCalculatingPoW {
return (.calculatingPoW, NSLocalizedString("Calculating proof of work", return (.calculatingPoW, NSLocalizedString("Calculating proof of work", comment: ""))
comment: "message status while calculating proof of work."))
} }
if outgoingMessage.hasAttachments() { if outgoingMessage.hasAttachments() {

@ -52,7 +52,7 @@ import PromiseKit
} }
// MARK: Obj-C API // MARK: Obj-C API
@objc public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, requiringPOW isPOWRequired: Bool, completionHandler: @escaping (Any?, NSError?) -> Void) { @objc public static func sendSignalMessage(_ signalMessage: SignalMessage, to destination: String, requiringPOW isPOWRequired: Bool, completionHandler: ((Any?, NSError?) -> Void)? = nil) {
sendSignalMessage(signalMessage, to: destination, requiringPOW: isPOWRequired).done { completionHandler($0.responseObject, nil) }.catch { completionHandler(nil, $0 as NSError) } sendSignalMessage(signalMessage, to: destination, requiringPOW: isPOWRequired).done { completionHandler?($0.responseObject, nil) }.catch { completionHandler?(nil, $0 as NSError) }
} }
} }

@ -43,7 +43,7 @@ private extension MutableCollection where Element == UInt8, Index == Int {
* This was copied from the desktop messenger. * This was copied from the desktop messenger.
* Ref: libloki/proof-of-work.js * Ref: libloki/proof-of-work.js
*/ */
@objc public class ProofOfWork : NSObject { @objc public final class ProofOfWork : NSObject {
// If this changes then we also have to use something other than UInt64 to support the new length // If this changes then we also have to use something other than UInt64 to support the new length
private static let nonceLength = 8 private static let nonceLength = 8

@ -1095,28 +1095,21 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} }
// Update the state to show that proof of work is being calculated // Update the state to show that proof of work is being calculated
[self calculatingProofOfWorkForMessage:messageSend]; [self setIsCalculatingProofOfWorkForMessage:messageSend];
// Loki: Calculate the proof of work for each device message // Convert the message to a Loki message and send it using the Loki messaging API
NSNumber *ttl = [NSNumber numberWithInteger:@(4 * 24 * 60 * 60)]; NSDictionary *signalMessage = deviceMessages.firstObject;
AnyPromise *powPromise = [self calculateProofOfWorkForDeviceMessages:deviceMessages ttl:ttl]; BOOL isPOWRequired = YES; // TODO: Base on message type
[powPromise [LokiMessagingAPI sendSignalMessage:signalMessage to:recipient.recipientId requiringPOW:isPOWRequired completionHandler:nil];
.thenOn([OWSDispatch sendingQueue], ^(NSArray *nonceArray) {
// Loki: Original code
/*
OWSRequestMaker *requestMaker = [[OWSRequestMaker alloc] initWithLabel:@"Message Send" OWSRequestMaker *requestMaker = [[OWSRequestMaker alloc] initWithLabel:@"Message Send"
requestFactoryBlock:^(SMKUDAccessKey *_Nullable udAccessKey) { requestFactoryBlock:^(SMKUDAccessKey *_Nullable udAccessKey) {
// Loki
// ========
return [OWSRequestFactory submitLokiMessageRequestWithRecipient:recipient.recipientId
messages:deviceMessages
nonceArray:nonceArray
ttl:ttl];
// ========
/* Original code:
return [OWSRequestFactory submitMessageRequestWithRecipient:recipient.recipientId return [OWSRequestFactory submitMessageRequestWithRecipient:recipient.recipientId
messages:deviceMessages messages:deviceMessages
timeStamp:message.timestamp timeStamp:message.timestamp
udAccessKey:udAccessKey]; udAccessKey:udAccessKey];
*/
} }
udAuthFailureBlock:^{ udAuthFailureBlock:^{
// Note the UD auth failure so subsequent retries // Note the UD auth failure so subsequent retries
@ -1131,11 +1124,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
recipientId:recipient.recipientId recipientId:recipient.recipientId
udAccess:messageSend.udAccess udAccess:messageSend.udAccess
canFailoverUDAuth:NO]; canFailoverUDAuth:NO];
return requestMaker; [[requestMaker makeRequestObjc]
}) .then(^(OWSRequestMakerResult *result) {
.thenOn([OWSDispatch sendingQueue], ^(OWSRequestMaker *requestMaker) {
return [requestMaker makeRequestObjc];
}).then(^(OWSRequestMakerResult *result) {
dispatch_async([OWSDispatch sendingQueue], ^{ dispatch_async([OWSDispatch sendingQueue], ^{
[self messageSendDidSucceed:messageSend [self messageSendDidSucceed:messageSend
deviceMessages:deviceMessages deviceMessages:deviceMessages
@ -1172,9 +1162,10 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
responseData:responseData]; responseData:responseData];
}); });
}) retainUntilComplete]; }) retainUntilComplete];
*/
} }
- (void)calculatingProofOfWorkForMessage:(OWSMessageSend *)messageSend - (void)setIsCalculatingProofOfWorkForMessage:(OWSMessageSend *)messageSend
{ {
OWSAssertDebug(messageSend); OWSAssertDebug(messageSend);
dispatch_async([OWSDispatch sendingQueue], ^{ dispatch_async([OWSDispatch sendingQueue], ^{

Loading…
Cancel
Save