Skip to content

Commit

Permalink
Fix "Long Comment" issue when the user is in the board with comment-t…
Browse files Browse the repository at this point in the history
…ime limit.
  • Loading branch information
clyang committed Oct 1, 2017
1 parent adb35d1 commit 304dc3e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/WLPostPushDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ - (IBAction)sendPostPushText:(id)sender {
[_sendButton setEnabled:NO];
[_cancelButton setEnabled:NO];
[_progressCircle setHidden:NO];
[_pushText setEditable:NO];
[_progressCircle setIndeterminate:YES];
[_progressCircle setUsesThreadedAnimation:YES];
[_progressCircle startAnimation:nil];
Expand All @@ -121,6 +122,7 @@ - (void)endThread {
[_progressCircle setIndeterminate:YES];
[_progressCircle setUsesThreadedAnimation:YES];
[_progressCircle stopAnimation:nil];
[_pushText setEditable:YES];

if([finalPushResult isEqualToString:@"DONE"]){
//[self showNotificationWindow:@"Auto Comment Result" withSheetMsg:@"Successfully leave the comment!"];
Expand Down Expand Up @@ -155,7 +157,7 @@ + (NSString *)getTerminalBottomLine {
}

+ (NSString *)performPostPushToTerminal:(NSString *)pushText{
const int sleepTime = 100000, maxAttempt = 300;
const int sleepTime = 100000, maxAttempt = 500;
BOOL isPushError = NO, isFinished = NO, tooFrequent = NO;
WLConnection *connection = [term connection];
int i=0, maxPushLen;
Expand Down Expand Up @@ -279,6 +281,19 @@ + (NSString *)performPostPushToTerminal:(NSString *)pushText{
i = 0;
isPushError = NO;
break;
} else if([bottomLine containsString:@"本板禁止快速連續推文"]) {
// get the pause seconds
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"請再等 ?(\\d+) ?秒" options:0 error:nil];
NSTextCheckingResult *match = [regex firstMatchInString:bottomLine options:NSAnchoredSearch range:NSMakeRange(0, bottomLine.length)];
NSRange needleRange = [match rangeAtIndex: 1];
NSString *needle = [bottomLine substringWithRange:needleRange];

// the board bans fast comment, just sleep for 1 second
// and give it another try.
[connection sendBytes:" " length:1];
sleep([needle intValue]);
[connection sendBytes:"%" length:1];
usleep(sleepTime);
}
isPushError = YES;
}
Expand Down

0 comments on commit 304dc3e

Please sign in to comment.