Browse Source

fix notification problem

When collapsing duplicate notification, the oldest one was kept
instead of the latest one.

Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Kuang Rufan 12 years ago
parent
commit
7cbe8d5656
1 changed files with 14 additions and 3 deletions
  1. 14 3
      Sources/VLCEventManager.m

+ 14 - 3
Sources/VLCEventManager.m

@@ -93,17 +93,28 @@ static void * EventDispatcherMainLoop(void * user_data)
         [[self messageQueue] removeLastObject];
         message = (message_t *)[dataMessage bytes];
 
-        /* Remove duplicate notifications. */
+        /* Remove duplicate notifications (keep the newest one). */
         if (message->type == VLCNotification) {
+            NSInteger last_match_msg = -1;
             for (NSInteger i = [[self messageQueue] count]-1; i >= 0; i-- ) {
                 message_newer = (message_t *)[(NSData *)[[self messageQueue] objectAtIndex:i] bytes];
                 if (message_newer->type == VLCNotification &&
                     message_newer->target == message->target &&
                     [message_newer->u.name isEqualToString:message->u.name]) {
-                    [message_newer->u.name release];
-                    [[self messageQueue] removeObjectAtIndex:i];
+                    if (last_match_msg >= 0) {
+                        message_t * msg = (message_t *)[(NSData *)[[self messageQueue] objectAtIndex:last_match_msg] bytes];
+                        [msg->u.name release];
+                        [[self messageQueue] removeObjectAtIndex:last_match_msg];
+                    }
+                    last_match_msg = i;
                 }
             }
+            if (last_match_msg >= 0) {
+                // newer notification detected, ignore current one
+                [message->u.name release];
+                pthread_mutex_unlock([self queueLock]);
+                continue;
+            }
         } else if (message->type == VLCObjectMethodWithArrayArg) {
             NSMutableArray * newArg = nil;