@@ -2001,8 +2001,17 @@ - (void)collectionView:(JSQMessagesCollectionView *)collectionView didTapMessage
20012001 [alert addAction: obj];
20022002 }];
20032003 [alert addAction: [self cancleAction ]];
2004+
2005+ // Get the anchor
20042006 alert.popoverPresentationController .sourceView = self.view ;
20052007 alert.popoverPresentationController .sourceRect = self.view .bounds ;
2008+ UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath: indexPath];
2009+ if ([cell isKindOfClass: [JSQMessagesCollectionViewCell class ]]) {
2010+ UIView *cellContainterView = ((JSQMessagesCollectionViewCell *)cell).messageBubbleContainerView ;
2011+ alert.popoverPresentationController .sourceRect = cellContainterView.bounds ;
2012+ alert.popoverPresentationController .sourceView = cellContainterView;
2013+ }
2014+
20062015 [self presentViewController: alert animated: YES completion: nil ];
20072016 }
20082017}
@@ -2027,9 +2036,49 @@ - (void)didReceiveChanges:(OTRYapViewHandler *)handler sectionChanges:(NSArray<Y
20272036 if (!rowChanges.count ) {
20282037 return ;
20292038 }
2039+
2040+ // Important to clear our "one message cache" here, since things may have changed.
2041+ self.currentIndexPath = nil ;
2042+
20302043 NSUInteger collectionViewNumberOfItems = [self .collectionView numberOfItemsInSection: 0 ];
20312044 NSUInteger numberMappingsItems = [self .viewHandler.mappings numberOfItemsInSection: 0 ];
20322045
2046+ [self .collectionView performBatchUpdates: ^{
2047+
2048+ for (YapDatabaseViewRowChange *rowChange in rowChanges)
2049+ {
2050+ switch (rowChange.type )
2051+ {
2052+ case YapDatabaseViewChangeDelete :
2053+ {
2054+ [self .collectionView deleteItemsAtIndexPaths: @[rowChange.indexPath]];
2055+ break ;
2056+ }
2057+ case YapDatabaseViewChangeInsert :
2058+ {
2059+ [self .collectionView insertItemsAtIndexPaths: @[ rowChange.newIndexPath ]];
2060+ break ;
2061+ }
2062+ case YapDatabaseViewChangeMove :
2063+ {
2064+ [self .collectionView moveItemAtIndexPath: rowChange.indexPath toIndexPath: rowChange.newIndexPath];
2065+ break ;
2066+ }
2067+ case YapDatabaseViewChangeUpdate :
2068+ {
2069+ // Update could be e.g. when we are done auto-loading a link. We
2070+ // need to reset the stored size of this item, so the image/message
2071+ // will get the correct bubble height.
2072+ id <JSQMessageData> message = [self messageAtIndexPath: rowChange.indexPath];
2073+ [self .collectionView.collectionViewLayout.bubbleSizeCalculator resetBubbleSizeCacheForMessageData: message];
2074+ [self .messageSizeCache removeObjectForKey: @(message.messageHash)];
2075+ [self .collectionView reloadItemsAtIndexPaths: @[ rowChange.indexPath]];
2076+ break ;
2077+ }
2078+ }
2079+ }
2080+ } completion: nil ];
2081+
20332082 if (numberMappingsItems > collectionViewNumberOfItems && numberMappingsItems > 0 ) {
20342083 // Inserted new item, probably at the end
20352084 // Get last message and test if isIncoming
@@ -2040,41 +2089,8 @@ - (void)didReceiveChanges:(OTRYapViewHandler *)handler sectionChanges:(NSArray<Y
20402089 } else {
20412090 // We can't use finishSendingMessage here because it might
20422091 // accidentally clear out unsent message text
2043- [self .collectionView.collectionViewLayout invalidateLayoutWithContext: [JSQMessagesCollectionViewFlowLayoutInvalidationContext context ]];
2044- [self .collectionView reloadData ];
20452092 [self scrollToBottomAnimated: YES ];
20462093 }
2047- } else {
2048- // deleted a message or message updated
2049- [self .collectionView performBatchUpdates: ^{
2050-
2051- for (YapDatabaseViewRowChange *rowChange in rowChanges)
2052- {
2053- switch (rowChange.type )
2054- {
2055- case YapDatabaseViewChangeDelete :
2056- {
2057- [self .collectionView deleteItemsAtIndexPaths: @[rowChange.indexPath]];
2058- break ;
2059- }
2060- case YapDatabaseViewChangeInsert :
2061- {
2062- [self .collectionView insertItemsAtIndexPaths: @[ rowChange.newIndexPath ]];
2063- break ;
2064- }
2065- case YapDatabaseViewChangeMove :
2066- {
2067- [self .collectionView moveItemAtIndexPath: rowChange.indexPath toIndexPath: rowChange.newIndexPath];
2068- break ;
2069- }
2070- case YapDatabaseViewChangeUpdate :
2071- {
2072- [self .collectionView reloadItemsAtIndexPaths: @[ rowChange.indexPath]];
2073- break ;
2074- }
2075- }
2076- }
2077- } completion: nil ];
20782094 }
20792095}
20802096
0 commit comments