1. Atlassian
  2. Project: Atlassian
  3. jiraconnect-ios

Commits

Nick Pellow [Atlassian]  committed 53296f8

CONNECT-182: ensure custom attachment items have a non-nil file path set. use the JRLManager as the custom datasource delegate. Delete items which are marked in permanent error. Reset all items that are 'in-progress' when the app re-launches.

  • Participants
  • Parent commits 6a32ee3
  • Branches default

Comments (0)

Files changed (5)

File JIRAConnect/JMCClasses/Base/JMCViewController.m

View file
     if ([[JMC sharedInstance].customDataSource respondsToSelector:@selector(customAttachment)]) {
         JMCAttachmentItem *payloadData = [[JMC sharedInstance].customDataSource customAttachment];
         if (payloadData) {
-            [allAttachments addObject:payloadData];
+            if (payloadData.path)
+            {
+                [allAttachments addObject:payloadData];
+            }
+            else
+            {
+                JMCALog(@"Not adding attachment: %@ with no path.", payloadData);
+            }
         }
     }
     

File JIRAConnect/JMCClasses/Core/queue/JMCRequestQueue.h

View file
 
 -(void) flushQueue;
 
+-(void) resetAllInProgress;
+
 -(void) addItem:(JMCQueueItem *)item;
 -(void)updateItem:(NSString *)uuid sentStatus:(JMCSentStatus)sentStatus bumpNumAttemptsBy:(int)inc;
 -(NSDictionary *) metaDataFor:(NSString *)uuid;

File JIRAConnect/JMCClasses/Core/queue/JMCRequestQueue.m

View file
         _flushLock = [[NSRecursiveLock alloc] init];
         _maxNumRequestFailures = 50;
         JMCDLog(@"queue at  %@", [instance getQueueIndexPath]);
+        [instance resetAllInProgress];
 
     }
     return instance;
     [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(doFlushQueue:) userInfo:nil repeats:NO];
 }
 
+- (void)resetAllInProgress
+{
+    @synchronized (_flushLock) {
+        NSMutableDictionary *items = [self getQueueList];
+
+        for (NSString *itemId in [items allKeys]) {
+            JMCQueueItem *item = [self getItem:itemId];
+
+            // Get metadata and check if empty
+            NSDictionary *metadata = [self metaDataFor:itemId];
+            if (!metadata) {
+                continue;
+            }
+            JMCSentStatus sentStatus = [[metadata valueForKey:KEY_SENT_STATUS] intValue];
+            if (sentStatus == JMCSentStatusInProgress)
+            {
+                JMCDLog(@"Resetting request to retry from in-progress %@",itemId)
+                [self updateItem:itemId sentStatus:JMCSentStatusRetry bumpNumAttemptsBy:0];
+            }
+        }
+    }
+
+}
+
+
 -(void)doFlushQueue:(NSTimer*) timer
 {
     // Ensure a single thread at a time tries to flush the queue.
             // Check permanent error
             JMCSentStatus sentStatus = [[metadata valueForKey:KEY_SENT_STATUS] intValue];
             if (sentStatus == JMCSentStatusPermError) {
-                JMCALog(@"Ignored queued item as sent status shows permanent error: %@.", itemId);
+                JMCALog(@"Deleting queued item as sent status shows permanent error: %@.", itemId);
+                [self deleteItem:itemId];
                 continue;
             }
             

File JIRAConnect/JMCClasses/Core/transport/JMCTransport.m

View file
             }
         }
     }
-    
+
     for (NSString *key in unique) {
         JMCAttachmentItem *item = [unique valueForKey:key];
-        NSString *filename = [NSString stringWithFormat:item.filenameFormat, index];
+        NSString *filename = [NSString stringWithFormat:item.filenameFormat, attachmentIndex];
         
         [self addPart:item filename:filename key:item.name boundary:boundary toStream:stream];
         

File JIRAConnect/JMCClasses/Core/transport/JMCTransportOperation.m

View file
         // remove the request item from the queue
         JMCRequestQueue *queue = [JMCRequestQueue sharedInstance];
         [queue deleteItem:requestId];
-        JMCDLog(@"%@ Request succeeded & queued item is deleted. %@ ",self, requestId);
+        JMCDLog(@"%@ Request succeeded & queued item is deleted. %@ ", self, requestId);
     } else if (statusCode == 401) {
         NSLog(@"Issue not created in JIRA because the autocreated user 'jiraconnectuser' does not have the 'Create Issue' permission on your project.\n Server Response: '%@'", responseString);
         [self connection:connection didFailWithError:nil];
 
 - (void)connection:(NSURLConnection *)aConnection didFailWithError:(NSError *)error {
     NSString *requestId = [request valueForHTTPHeaderField:kJMCHeaderNameRequestId];
-    
-    // TODO: time-out items in the request queue after N Attempts ?
+
     [[JMCRequestQueue sharedInstance] updateItem:requestId sentStatus:JMCSentStatusRetry bumpNumAttemptsBy:1];
     
     if ([self.delegate respondsToSelector:@selector(transportDidFinishWithError:statusCode:requestId:)]) {