twilio / conversations-ios

SPM releases
https://www.twilio.com/docs/conversations/ios/changelog
10 stars 5 forks source link

Quick consecutive calls to getUnreadMessagesCountWithCompletion returning different values #27

Closed bmadaras closed 1 year ago

bmadaras commented 1 year ago

TwilioConversationsClient 2.2.5

2022-09-12 11:44:09.291775-0400 ARMS Coach[96791:2058527] Request Unread for Convo CH13340207d4684c57be2b6ba0e62aaad3
2022-09-12 11:44:09.352320-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 Count 1
2022-09-12 11:44:09.352443-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 is unread
2022-09-12 11:44:12.656520-0400 ARMS Coach[96791:2058527] Request Unread for Convo CH13340207d4684c57be2b6ba0e62aaad3
2022-09-12 11:44:12.691441-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 Count 0
2022-09-12 11:44:12.691559-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 is read
2022-09-12 11:44:16.571202-0400 ARMS Coach[96791:2058527] Request Unread for Convo CH13340207d4684c57be2b6ba0e62aaad3
2022-09-12 11:44:16.601171-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 Count 0
2022-09-12 11:44:16.601285-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 is read
2022-09-12 11:44:42.828179-0400 ARMS Coach[96791:2058527] Request Unread for Convo CH13340207d4684c57be2b6ba0e62aaad3
2022-09-12 11:44:42.856511-0400 ARMS Coach[96791:2058527] Request Unread for Convo CH13340207d4684c57be2b6ba0e62aaad3
2022-09-12 11:44:42.881628-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 Count 1
2022-09-12 11:44:42.881760-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 is unread
2022-09-12 11:44:42.899378-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 Count 0
2022-09-12 11:44:42.899481-0400 ARMS Coach[96791:2058527] Conversation CH13340207d4684c57be2b6ba0e62aaad3 is read

The correct value for Conversation CH13340207d4684c57be2b6ba0e62aaad3 is Count 1, and if I scroll my conversation list to then cause the call to need to reload it does correctly give me the Count 1.

The issue only seems to occur when making the call very close together. 2022-09-12 11:44:42.828179 2022-09-12 11:44:42.856511

Here is my example code an unneeded dispatch to the main thread because I thought that possibly could have been the reason for the indicator not displaying.

 NSLog(@"Request Unread for Convo %@", weakSelf.conversation.sid);
    [self.conversation getUnreadMessagesCountWithCompletion:^(TCHResult * _Nonnull result, NSNumber * count) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (![result isSuccessful]) {
                NSLog(@"Conversation %@ FAILED unreadCount", weakSelf.conversation.sid);
            }

            NSLog(@"Conversation %@ Count %@", weakSelf.conversation.sid, count);

            if ([result isSuccessful] && count != nil && [count intValue] > 0) {
    //            weakSelf.unreadMessageIndicator.hidden = NO;
                weakSelf.unreadMessageIndicator.backgroundColor = [UIColor orange];
                NSLog(@"Conversation %@ is unread", weakSelf.conversation.sid);
            } else {
    //            weakSelf.unreadMessageIndicator.hidden = YES;
                weakSelf.unreadMessageIndicator.backgroundColor = [UIColor clearColor];
                NSLog(@"Conversation %@ is read", weakSelf.conversation.sid);
            }

            [weakSelf setNeedsUpdateConstraints];
        });
    }];