From f8cccd8967b2897d7aa8b4d74fb8a029f642d537 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 6 May 2019 16:01:37 +1000 Subject: [PATCH 1/2] Show spinning cog if we are calculating the proof of work. --- .../message_status_pow.imageset/Contents.json | 23 ++++++++++++++++++ .../message_status_pow.imageset/pow.png | Bin 0 -> 277 bytes .../message_status_pow.imageset/pow@2x.png | Bin 0 -> 417 bytes .../message_status_pow.imageset/pow@3x.png | Bin 0 -> 609 bytes .../Cells/OWSMessageFooterView.m | 4 +++ .../ViewControllers/HomeView/HomeViewCell.m | 4 +++ .../MessageDetailViewController.swift | 3 +++ .../Utils/MessageRecipientStatusUtils.swift | 8 ++++++ .../translations/en.lproj/Localizable.strings | 1 + .../Messages/Interactions/TSOutgoingMessage.h | 6 +++++ .../Messages/Interactions/TSOutgoingMessage.m | 21 ++++++++++++++++ .../src/Messages/OWSMessageSender.m | 15 ++++++++++-- 12 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 Signal/Images.xcassets/message_status_pow.imageset/Contents.json create mode 100644 Signal/Images.xcassets/message_status_pow.imageset/pow.png create mode 100644 Signal/Images.xcassets/message_status_pow.imageset/pow@2x.png create mode 100644 Signal/Images.xcassets/message_status_pow.imageset/pow@3x.png diff --git a/Signal/Images.xcassets/message_status_pow.imageset/Contents.json b/Signal/Images.xcassets/message_status_pow.imageset/Contents.json new file mode 100644 index 000000000..0ef0df12d --- /dev/null +++ b/Signal/Images.xcassets/message_status_pow.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/Signal/Images.xcassets/message_status_pow.imageset/pow.png b/Signal/Images.xcassets/message_status_pow.imageset/pow.png new file mode 100644 index 0000000000000000000000000000000000000000..b519414623718145f5c3e064e6dd87d31d157acc GIT binary patch literal 277 zcmeAS@N?(olHy`uVBq!ia0vp^JRr=$1|-8uW1a&kwj^(N7l!{JxM1({$v_d#0*}aI zppNSx%;=;sy8u7sn8d^K&O2Yj?aT(r84U-QO0#8d-g711M_=*VYZ;3+!}SL|cd)-rSQ30l_=dG}k$LIAi(xZA zY`$gi-1nrXa^>2)jNTkO7}7r~Wt@(`FC~86x>#O3eHr_PuKqlh$E$7jFz)Ol0WL{I zK~zY`#g6amtnzf+;IhDLV!c4hnP74E7zzY{A{Yt zr0Jg;!0?jFWYYa!)x7?xfjBOJ1+cYZA!A45)*)`96(iRa3EBsa?IpMZdh#seKEUr- z?>-Fx2J+coKngqn9|3zze9GKZxLeWM^Z8pLrj1|QzWE8oP0WmVS4mg{xx`w@>DGW} z#ZGzyn!ugJ4Uj2#J%CGK7^q_8At#c=#~X_FA6|f!!`h;TqkdaGJMmaqRXi3fgfF0M@I`z9^)1+=Bv_-}h+r>G z)hleymFDU^J8AhRXEkU3^PjnM&Y5$;4+}sQ_)=IEnD-%0c?y~Z(wgzK_%uz>P#~XR zf(8Tm1VI}3(A=NcJ`JDM`h=E%9FVCq76HpZn@LSY*cFjMuu;&9hG4`|R4UFb3RF!5HkW$JLC}ovrFIGX zf+|GoaGv>uy-#Ay8$@-;yT>ar<~-AULGnzLxHB`rxo_zRQCy!A#kIfD;)<01RzE+s zlMl4(zw|%@$hJ^W_Fp{mO>NM)XB%`OEtFRqgfwruMseLi%$lK5T>6)-v5vWo00000NkvXXu0mjfH!cVO literal 0 HcmV?d00001 diff --git a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m index 82a50af56..2060d052b 100644 --- a/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m +++ b/Signal/src/ViewControllers/ConversationView/Cells/OWSMessageFooterView.m @@ -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"]; diff --git a/Signal/src/ViewControllers/HomeView/HomeViewCell.m b/Signal/src/ViewControllers/HomeView/HomeViewCell.m index d95af9bb1..89dd0d735 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewCell.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewCell.m @@ -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"]; diff --git a/Signal/src/ViewControllers/MessageDetailViewController.swift b/Signal/src/ViewControllers/MessageDetailViewController.swift index 822214764..d802b8ed5 100644 --- a/Signal/src/ViewControllers/MessageDetailViewController.swift +++ b/Signal/src/ViewControllers/MessageDetailViewController.swift @@ -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.") diff --git a/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift b/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift index d720cbfce..def4de28f 100644 --- a/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift +++ b/Signal/src/ViewControllers/Utils/MessageRecipientStatusUtils.swift @@ -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" } } } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index d64cbf1bf..253071590 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -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"; diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h index bc06b8f98..1610e14d0 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.h @@ -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 diff --git a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m index 2fa564da7..4def76fa9 100644 --- a/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m +++ b/SignalServiceKit/src/Messages/Interactions/TSOutgoingMessage.m @@ -91,6 +91,8 @@ NSString *NSStringForOutgoingMessageRecipientState(OWSOutgoingMessageRecipientSt @property (atomic, nullable) NSDictionary *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]; diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index fb7c3237b..b67259ee0 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -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 *)deviceMessages wasSentByUD:(BOOL)wasSentByUD From bee85caa148ca92b333e2100a329c570dfd03a28 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Mon, 6 May 2019 16:14:51 +1000 Subject: [PATCH 2/2] Improved naming. --- SignalServiceKit/src/Messages/OWSMessageSender.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SignalServiceKit/src/Messages/OWSMessageSender.m b/SignalServiceKit/src/Messages/OWSMessageSender.m index b67259ee0..f3e4d14ad 100644 --- a/SignalServiceKit/src/Messages/OWSMessageSender.m +++ b/SignalServiceKit/src/Messages/OWSMessageSender.m @@ -1127,7 +1127,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; } // Update the state to show that proof of work is being calculated - [self calculatingProofOfWorkFor:messageSend]; + [self calculatingProofOfWorkForMessage:messageSend]; // Loki: Calculate the proof of work for each device message NSNumber *ttl = [NSNumber numberWithInteger:@(4 * 24 * 60 * 60)]; @@ -1206,7 +1206,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException"; }) retainUntilComplete]; } -- (void)calculatingProofOfWorkFor:(OWSMessageSend *)messageSend +- (void)calculatingProofOfWorkForMessage:(OWSMessageSend *)messageSend { OWSAssertDebug(messageSend); dispatch_async([OWSDispatch sendingQueue], ^{