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,
};
typedef void (^ActionSucceesBlock)(void);
typedef void (^ActionFailureBlock)(void);
typedef void (^ActionBlock)(ActionSucceesBlock success, ActionFailureBlock failure);
@interface TSOutgoingMessage (PostDatingDebug)
- (void)setReceivedAtTimestamp:(uint64_t)value;
@ -445,66 +449,28 @@ typedef NS_ENUM(NSUInteger, DebugMediaType) {
break;
}
[alert addAction:[UIAlertAction actionWithTitle:label
style:UIAlertActionStyleDefault
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
[alert addAction:[UIAlertAction
actionWithTitle:label
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[self sendRandomMedia:mediaType
count:countValue.unsignedIntegerValue
[self performActionNTimes:[self sendRandomMediaAction:mediaType thread:thread]
thread:thread];
}]];
}
[alert addAction:[OWSAlerts cancelAction]];
UIViewController *fromViewController = [[UIApplication sharedApplication] frontmostViewController];
[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(count > 0);
void (^completion)(void) = ^{
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];
});
};
return ^(ActionSucceesBlock success, ActionFailureBlock failure) {
void (^sendMessage)(NSString *) = ^(NSString *filePath) {
[self sendAttachment:filePath
thread:thread
success:completion
failure:^{
}];
[self sendAttachment:filePath thread:thread success:success failure:failure];
};
DebugMediaType mediaTypeToSend = mediaType;
while (mediaTypeToSend == DebugMediaType_Random) {
@ -534,6 +500,52 @@ typedef NS_ENUM(NSUInteger, DebugMediaType) {
OWSFail(@"%@ Invalid value.", self.logTag);
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

Loading…
Cancel
Save