Show spinning cog if we are calculating the proof of work.

This commit is contained in:
Mikunj 2019-05-06 16:01:37 +10:00
parent 598226d58e
commit f8cccd8967
12 changed files with 83 additions and 2 deletions

View File

@ -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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -141,6 +141,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
@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.
*/
@ -183,6 +186,9 @@ typedef NS_ENUM(NSInteger, TSGroupMetaMessage) {
#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.
- (void)updateWithSentRecipient:(NSString *)recipientId
wasSentByUD:(BOOL)wasSentByUD

View File

@ -91,6 +91,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
@property (atomic, nullable) NSDictionary<NSString *, TSOutgoingMessageRecipientState *> *recipientStateMap;
@property (atomic) BOOL isCalculatingPoW;
@end
#pragma mark -
@ -323,6 +325,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}
_hasSyncedTranscript = NO;
_isCalculatingPoW = NO;
if ([thread isKindOfClass:TSGroupThread.class]) {
// Unless specified, we assume group messages are "Delivery" i.e. normal messages.
@ -607,6 +610,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}
}
[message setMostRecentFailureText:error.localizedDescription];
[message setIsCalculatingPoW:false];
}];
}
@ -623,6 +627,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
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
wasSentByUD:(BOOL)wasSentByUD
transaction:(YapDatabaseReadWriteTransaction *)transaction {
@ -685,6 +700,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}
recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.wasSentByUD = wasSentByUD;
[message setIsCalculatingPoW:false];
}];
}
@ -702,6 +718,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
return;
}
recipientState.state = OWSOutgoingMessageRecipientStateSkipped;
[message setIsCalculatingPoW:false];
}];
}
@ -730,6 +747,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}
recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.deliveryTimestamp = deliveryTimestamp;
[message setIsCalculatingPoW:false];
}];
}
@ -753,6 +771,7 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}
recipientState.state = OWSOutgoingMessageRecipientStateSent;
recipientState.readTimestamp = @(readTimestamp);
[message setIsCalculatingPoW:false];
}];
}
@ -821,6 +840,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt
}
}
}
[message setIsCalculatingPoW:false];
if (!isSentUpdate) {
[message setIsFromLinkedDevice:YES];

View File

@ -929,7 +929,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
NSString *destination = message[@"destination"];
NSString *data = message[@"content"];
NSString *_Nullable nonce = [ProofOfWork calculateForData:data pubKey:destination timestamp:timestamp.unsignedIntegerValue ttl:ttl.integerValue];
NSString *_Nullable nonce = [ProofOfWork calculateWithData:data pubKey:destination timestamp:timestamp.unsignedIntegerValue ttl:ttl.integerValue];
// Return our timestamp along with the nonce
// These will help us identify which nonce belongs to which message
@ -1126,7 +1126,8 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
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 calculatingProofOfWorkFor:messageSend];
// Loki: Calculate the proof of work for each device message
NSNumber *ttl = [NSNumber numberWithInteger:@(4 * 24 * 60 * 60)];
@ -1205,6 +1206,16 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
}) retainUntilComplete];
}
- (void)calculatingProofOfWorkFor:(OWSMessageSend *)messageSend
{
OWSAssertDebug(messageSend);
dispatch_async([OWSDispatch sendingQueue], ^{
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[messageSend.message updateIsCalculatingProofOfWorkWithTransaction:transaction];
}];
});
}
- (void)messageSendDidSucceed:(OWSMessageSend *)messageSend
deviceMessages:(NSArray<NSDictionary *> *)deviceMessages
wasSentByUD:(BOOL)wasSentByUD