Merge pull request #7 from loki-project/proof-of-work-ui

Proof of work UI
pull/8/head
Niels Andriesse 6 years ago committed by GitHub
commit 18d1225faa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "pow.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "pow@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "pow@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

@ -122,6 +122,10 @@ NS_ASSUME_NONNULL_BEGIN
MessageReceiptStatus messageStatus = MessageReceiptStatus messageStatus =
[MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage]; [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage];
switch (messageStatus) { switch (messageStatus) {
case MessageReceiptStatusCalculatingPoW:
statusIndicatorImage = [UIImage imageNamed:@"message_status_pow"];
[self animateSpinningIcon];
break;
case MessageReceiptStatusUploading: case MessageReceiptStatusUploading:
case MessageReceiptStatusSending: case MessageReceiptStatusSending:
statusIndicatorImage = [UIImage imageNamed:@"message_status_sending"]; statusIndicatorImage = [UIImage imageNamed:@"message_status_sending"];

@ -308,6 +308,10 @@ NS_ASSUME_NONNULL_BEGIN
MessageReceiptStatus messageStatus = MessageReceiptStatus messageStatus =
[MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage]; [MessageRecipientStatusUtils recipientStatusWithOutgoingMessage:outgoingMessage];
switch (messageStatus) { switch (messageStatus) {
case MessageReceiptStatusCalculatingPoW:
statusIndicatorImage = [UIImage imageNamed:@"message_status_pow"];
shouldAnimateStatusIcon = YES;
break;
case MessageReceiptStatusUploading: case MessageReceiptStatusUploading:
case MessageReceiptStatusSending: case MessageReceiptStatusSending:
statusIndicatorImage = [UIImage imageNamed:@"message_status_sending"]; statusIndicatorImage = [UIImage imageNamed:@"message_status_sending"];

@ -603,6 +603,9 @@ class MessageDetailViewController: OWSViewController, MediaGalleryDataSourceDele
private func string(for messageReceiptStatus: MessageReceiptStatus) -> String { private func string(for messageReceiptStatus: MessageReceiptStatus) -> String {
switch messageReceiptStatus { switch messageReceiptStatus {
case .calculatingPoW:
return NSLocalizedString("Calculating proof of work",
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.")

@ -14,6 +14,7 @@ import SignalMessaging
case read case read
case failed case failed
case skipped case skipped
case calculatingPoW
} }
@objc @objc
@ -109,6 +110,11 @@ public class MessageRecipientStatusUtils: NSObject {
// Use the "long" version of this message here. // Use the "long" version of this message here.
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 {
return (.calculatingPoW, NSLocalizedString("Calculating proof of work",
comment: "message status while calculating proof of work."))
}
if outgoingMessage.hasAttachments() { if outgoingMessage.hasAttachments() {
return (.uploading, NSLocalizedString("MESSAGE_STATUS_UPLOADING", return (.uploading, NSLocalizedString("MESSAGE_STATUS_UPLOADING",
comment: "status message while attachment is uploading")) comment: "status message while attachment is uploading"))
@ -164,6 +170,8 @@ public class MessageRecipientStatusUtils: NSObject {
return "failed" return "failed"
case .skipped: case .skipped:
return "skipped" return "skipped"
case .calculatingPoW:
return "calculatingPoW"
} }
} }
} }

@ -2568,3 +2568,4 @@
"Start a Conversation" = "Start a Conversation"; "Start a Conversation" = "Start a Conversation";
"Invalid public key" = "Invalid public key"; "Invalid public key" = "Invalid public key";
"No search results" = "No search results"; "No search results" = "No search results";
"Calculating proof of work" = "Calculating proof of work";

@ -141,6 +141,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@property (nonatomic, readonly) BOOL isOnline; @property (nonatomic, readonly) BOOL isOnline;
// Loki: Bool to indicate if proof of work is being calculated for this message
@property (atomic, readonly) BOOL isCalculatingPoW;
/** /**
* The data representation of this message, to be encrypted, before being sent. * The data representation of this message, to be encrypted, before being sent.
*/ */
@ -183,6 +186,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
#pragma mark - Update With... Methods #pragma mark - Update With... Methods
// When sending a message, when proof of work calculation is started, we should mark it as such
- (void)updateIsCalculatingProofOfWorkWithTransaction:(YapDatabaseReadWriteTransaction *)transaction;
// This method is used to record a successful send to one recipient. // This method is used to record a successful send to one recipient.
- (void)updateWithSentRecipient:(NSString *)recipientId - (void)updateWithSentRecipient:(NSString *)recipientId
wasSentByUD:(BOOL)wasSentByUD wasSentByUD:(BOOL)wasSentByUD

@ -91,6 +91,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
@property (atomic, nullable) NSDictionary<NSString *, TSOutgoingMessageRecipientState *> *recipientStateMap; @property (atomic, nullable) NSDictionary<NSString *, TSOutgoingMessageRecipientState *> *recipientStateMap;
@property (atomic) BOOL isCalculatingPoW;
@end @end
#pragma mark - #pragma mark -
@ -323,6 +325,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
} }
_hasSyncedTranscript = NO; _hasSyncedTranscript = NO;
_isCalculatingPoW = NO;
if ([thread isKindOfClass:TSGroupThread.class]) { if ([thread isKindOfClass:TSGroupThread.class]) {
// Unless specified, we assume group messages are "Delivery" i.e. normal messages. // Unless specified, we assume group messages are "Delivery" i.e. normal messages.
@ -607,6 +610,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
} }
} }
[message setMostRecentFailureText:error.localizedDescription]; [message setMostRecentFailureText:error.localizedDescription];
[message setIsCalculatingPoW:false];
}]; }];
} }
@ -623,6 +627,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
recipientState.state = OWSOutgoingMessageRecipientStateFailed; recipientState.state = OWSOutgoingMessageRecipientStateFailed;
} }
} }
[message setIsCalculatingPoW:false];
}]; }];
} }
@ -669,6 +674,16 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}]; }];
} }
- (void)updateIsCalculatingProofOfWorkWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
OWSAssertDebug(transaction);
[self applyChangeToSelfAndLatestCopy:transaction
changeBlock:^(TSOutgoingMessage *message) {
[message setIsCalculatingPoW:true];
}];
}
- (void)updateWithSentRecipient:(NSString *)recipientId - (void)updateWithSentRecipient:(NSString *)recipientId
wasSentByUD:(BOOL)wasSentByUD wasSentByUD:(BOOL)wasSentByUD
transaction:(YapDatabaseReadWriteTransaction *)transaction { transaction:(YapDatabaseReadWriteTransaction *)transaction {
@ -685,6 +700,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
} }
recipientState.state = OWSOutgoingMessageRecipientStateSent; recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.wasSentByUD = wasSentByUD; recipientState.wasSentByUD = wasSentByUD;
[message setIsCalculatingPoW:false];
}]; }];
} }
@ -702,6 +718,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
return; return;
} }
recipientState.state = OWSOutgoingMessageRecipientStateSkipped; recipientState.state = OWSOutgoingMessageRecipientStateSkipped;
[message setIsCalculatingPoW:false];
}]; }];
} }
@ -730,6 +747,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
} }
recipientState.state = OWSOutgoingMessageRecipientStateSent; recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.deliveryTimestamp = deliveryTimestamp; recipientState.deliveryTimestamp = deliveryTimestamp;
[message setIsCalculatingPoW:false];
}]; }];
} }
@ -753,6 +771,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
} }
recipientState.state = OWSOutgoingMessageRecipientStateSent; recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.readTimestamp = @(readTimestamp); recipientState.readTimestamp = @(readTimestamp);
[message setIsCalculatingPoW:false];
}]; }];
} }
@ -822,6 +841,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
} }
} }
[message setIsCalculatingPoW:false];
if (!isSentUpdate) { if (!isSentUpdate) {
[message setIsFromLinkedDevice:YES]; [message setIsFromLinkedDevice:YES];
} }

@ -931,6 +931,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSString *nonce = [ProofOfWork calculateWithData:data pubKey:destination timestamp:timestamp.unsignedIntegerValue ttl:ttl.integerValue]; NSString *nonce = [ProofOfWork calculateWithData:data pubKey:destination timestamp:timestamp.unsignedIntegerValue ttl:ttl.integerValue];
// Return our timestamp along with the nonce // Return our timestamp along with the nonce
// These will help us identify which nonce belongs to which message // These will help us identify which nonce belongs to which message
return @{ return @{
@ -1126,7 +1127,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
return messageSend.failure(error); return messageSend.failure(error);
} }
// TODO: Update message here to show the POW cog icon // Update the state to show that proof of work is being calculated
[self calculatingProofOfWorkForMessage:messageSend];
// Loki: Calculate the proof of work for each device message // Loki: Calculate the proof of work for each device message
NSNumber *ttl = [NSNumber numberWithInteger:@(4 * 24 * 60 * 60)]; NSNumber *ttl = [NSNumber numberWithInteger:@(4 * 24 * 60 * 60)];
@ -1205,6 +1207,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}) retainUntilComplete]; }) retainUntilComplete];
} }
- (void)calculatingProofOfWorkForMessage:(OWSMessageSend *)messageSend
{
OWSAssertDebug(messageSend);
dispatch_async([OWSDispatch sendingQueue], ^{
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[messageSend.message updateIsCalculatingProofOfWorkWithTransaction:transaction];
}];
});
}
- (void)messageSendDidSucceed:(OWSMessageSend *)messageSend - (void)messageSendDidSucceed:(OWSMessageSend *)messageSend
deviceMessages:(NSArray<NSDictionary *> *)deviceMessages deviceMessages:(NSArray<NSDictionary *> *)deviceMessages
wasSentByUD:(BOOL)wasSentByUD wasSentByUD:(BOOL)wasSentByUD

Loading…
Cancel
Save