This commit is contained in:
Frederic Jacobs 2015-01-31 01:00:58 -10:00
parent 4833487e94
commit 585079de21
1 changed files with 41 additions and 14 deletions

View File

@ -103,6 +103,8 @@ typedef enum : NSUInteger {
@property NSUInteger page;
@property BOOL isVisible;
@end
@implementation MessagesViewController
@ -143,11 +145,12 @@ typedef enum : NSUInteger {
else if(![self isTextSecureReachable] ){
[self inputToolbar].hidden= YES; // only RedPhone
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"btnPhone--white"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(callAction)];;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
_isVisible = NO;
[self.navigationController.navigationBar setTranslucent:NO];
_showFingerprintDisplay = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showFingerprint)];
@ -185,6 +188,7 @@ typedef enum : NSUInteger {
[self updateRangeOptionsForPage:self.page];
[self.uiDatabaseConnection beginLongLivedReadTransaction];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.messageMappings updateWithTransaction:transaction];
}];
@ -216,7 +220,8 @@ typedef enum : NSUInteger {
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.collectionView reloadData];
NSInteger numberOfMessages = (NSInteger)[self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
if (numberOfMessages > 0) {
@ -237,6 +242,7 @@ typedef enum : NSUInteger {
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self startReadTimer];
_isVisible = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
@ -274,6 +280,10 @@ typedef enum : NSUInteger {
}
- (void)viewDidDisappear:(BOOL)animated{
_isVisible = NO;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@ -449,9 +459,6 @@ typedef enum : NSUInteger {
return [PhoneNumber tryParsePhoneNumberFromUserSpecifiedText:contactId];
}
-(void)callAction
{
if ([self isRedPhoneReachable]) {
@ -1251,24 +1258,44 @@ typedef enum : NSUInteger {
[self initializeToolbars];
}];
}
// Process the notification(s),
// and get the change-set(s) as applies to my view and mappings configuration.
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
NSArray *messageRowChanges = nil;
[[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] getSectionChanges:nil
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
if ( ![[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] hasChangesForNotifications:notifications])
{
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction){
[self.messageMappings updateWithTransaction:transaction];
}];
return;
}
if (!_isVisible)
{
// Since we moved our databaseConnection to a new commit,
// we need to update the mappings too.
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction){
[self.messageMappings updateWithTransaction:transaction];
}];
return;
}
NSArray *messageRowChanges = nil;
NSArray *sectionChanges = nil;
[[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] getSectionChanges:&sectionChanges
rowChanges:&messageRowChanges
forNotifications:notifications
withMappings:self.messageMappings];
__block BOOL scrollToBottom = NO;
if (!messageRowChanges) {
if ([sectionChanges count] == 0 & [messageRowChanges count] == 0)
{
return;
}
[self.collectionView performBatchUpdates:^{
for (YapDatabaseViewRowChange *rowChange in messageRowChanges)
{
switch (rowChange.type)