Elaborate debug UI for messages.

pull/1/head
Matthew Chen 7 years ago
parent 0dfa9cac7b
commit 68f3334e77

@ -35,6 +35,10 @@ typedef NS_ENUM(NSUInteger, DebugMediaType) {
DebugMediaType_Random, DebugMediaType_Random,
}; };
typedef void (^ActionSucceesBlock)(void);
typedef void (^ActionFailureBlock)(void);
typedef void (^ActionBlock)(ActionSucceesBlock success, ActionFailureBlock failure);
@interface TSOutgoingMessage (PostDatingDebug) @interface TSOutgoingMessage (PostDatingDebug)
- (void)setReceivedAtTimestamp:(uint64_t)value; - (void)setReceivedAtTimestamp:(uint64_t)value;
@ -445,66 +449,28 @@ typedef NS_ENUM(NSUInteger, DebugMediaType) {
break; break;
} }
[alert addAction:[UIAlertAction actionWithTitle:label [alert addAction:[UIAlertAction
style:UIAlertActionStyleDefault actionWithTitle:label
handler:^(UIAlertAction *action) {
[self sendRandomMedia:mediaType thread:thread];
}]];
}
[alert addAction:[OWSAlerts cancelAction]];
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
[fromViewController presentViewController:alert animated:YES completion:nil];
}
+ (void)sendRandomMedia:(DebugMediaType)mediaType thread:(TSThread *)thread
{
OWSAssertIsOnMainThread() OWSAssert(thread);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"How many to send?"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
for (NSNumber *countValue in @[
@(1),
@(10),
@(100),
@(1 * 1000),
@(10 * 1000),
]) {
[alert addAction:[UIAlertAction actionWithTitle:countValue.stringValue
style:UIAlertActionStyleDefault style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self sendRandomMedia:mediaType [self performActionNTimes:[self sendRandomMediaAction:mediaType thread:thread]
count:countValue.unsignedIntegerValue
thread:thread]; thread:thread];
}]]; }]];
} }
[alert addAction:[OWSAlerts cancelAction]]; [alert addAction:[OWSAlerts cancelAction]];
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController]; UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
[fromViewController presentViewController:alert animated:YES completion:nil]; [fromViewController presentViewController:alert animated:YES completion:nil];
} }
+ (void)sendRandomMedia:(DebugMediaType)mediaType count:(NSUInteger)count thread:(TSThread *)thread + (ActionBlock)sendRandomMediaAction:(DebugMediaType)mediaType thread:(TSThread *)thread
{ {
OWSAssert(thread); OWSAssert(thread);
OWSAssert(count > 0);
void (^completion)(void) = ^{ return ^(ActionSucceesBlock success, ActionFailureBlock failure) {
if (count <= 1) {
return;
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self sendRandomMedia:mediaType count:count - 1 thread:thread];
});
};
void (^sendMessage)(NSString *) = ^(NSString *filePath) { void (^sendMessage)(NSString *) = ^(NSString *filePath) {
[self sendAttachment:filePath [self sendAttachment:filePath thread:thread success:success failure:failure];
thread:thread
success:completion
failure:^{
}];
}; };
DebugMediaType mediaTypeToSend = mediaType; DebugMediaType mediaTypeToSend = mediaType;
while (mediaTypeToSend == DebugMediaType_Random) { while (mediaTypeToSend == DebugMediaType_Random) {
@ -534,6 +500,52 @@ typedef NS_ENUM(NSUInteger, DebugMediaType) {
OWSFail(@"%@ Invalid value.", self.logTag); OWSFail(@"%@ Invalid value.", self.logTag);
break; break;
} }
};
}
+ (void)performActionNTimes:(ActionBlock)action thread:(TSThread *)thread
{
OWSAssertIsOnMainThread() OWSAssert(thread);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"How many?"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
for (NSNumber *countValue in @[
@(0),
@(1),
@(10),
@(100),
@(1 * 1000),
@(10 * 1000),
]) {
[alert addAction:[UIAlertAction actionWithTitle:countValue.stringValue
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *ignore) {
[self performAction:action count:countValue.unsignedIntegerValue];
}]];
}
[alert addAction:[OWSAlerts cancelAction]];
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
[fromViewController presentViewController:alert animated:YES completion:nil];
}
+ (void)performAction:(ActionBlock)action count:(NSUInteger)count
{
OWSAssert(action);
OWSAssert(count > 0);
action(
^{
if (count <= 1) {
return;
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)1.f * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self performAction:action count:count - 1];
});
},
^{
});
} }
+ (void)ensureRandomJpegWithSuccess:(nullable void (^)(NSString *filePath))success + (void)ensureRandomJpegWithSuccess:(nullable void (^)(NSString *filePath))success

Loading…
Cancel
Save