@ -529,18 +529,24 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations
self . isViewVisible = YES ;
self . isViewVisible = YES ;
/ / When returning to home view , try to ensure that the "last " thread is still
BOOL isShowingSearchResults = !self . searchResultsController . view . hidden ;
/ / visible . The threads often change ordering while in conversation view due
if ( isShowingSearchResults ) {
/ / to incoming & outgoing messages .
OWSAssert ( self . searchBar . text . ows_stripped . length > 0 ) ;
if ( self . lastThread ) {
self . tableView . contentOffset = CGPointZero ;
} else if ( self . lastThread ) {
OWSAssert ( self . searchBar . text . ows_stripped . length == 0 ) ;
/ / When returning to home view , try to ensure that the "last " thread is still
/ / visible . The threads often change ordering while in conversation view due
/ / to incoming & outgoing messages .
__block NSIndexPath * indexPathOfLastThread = nil ;
__block NSIndexPath * indexPathOfLastThread = nil ;
[ self . uiDatabaseConnection readWithBlock : ^( YapDatabaseReadTransaction * transaction ) {
[ self . uiDatabaseConnection readWithBlock : ^( YapDatabaseReadTransaction * transaction ) {
indexPathOfLastThread =
indexPathOfLastThread =
[ [ transaction extension : TSThreadDatabaseViewExtensionName ] indexPathForKey : self . lastThread . uniqueId
[ [ transaction extension : TSThreadDatabaseViewExtensionName ] indexPathForKey : self . lastThread . uniqueId
inCollection : [ TSThread collection ]
inCollection : [ TSThread collection ]
withMappings : self . threadMappings ] ;
withMappings : self . threadMappings ] ;
} ] ;
} ] ;
if ( indexPathOfLastThread ) {
if ( indexPathOfLastThread ) {
[ self . tableView scrollToRowAtIndexPath : indexPathOfLastThread
[ self . tableView scrollToRowAtIndexPath : indexPathOfLastThread
atScrollPosition : UITableViewScrollPositionNone
atScrollPosition : UITableViewScrollPositionNone