2014-10-29 21:58:58 +01:00
|
|
|
//
|
|
|
|
// SignalsViewController.m
|
|
|
|
// Signal
|
|
|
|
//
|
|
|
|
// Created by Dylan Bourgeois on 27/10/14.
|
|
|
|
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2014-11-24 21:51:43 +01:00
|
|
|
#import "UIUtil.h"
|
2014-11-21 00:51:23 +01:00
|
|
|
#import "InboxTableViewCell.h"
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
#import "ContactsManager.h"
|
2014-11-26 20:29:45 +01:00
|
|
|
#import "Environment.h"
|
2014-10-29 21:58:58 +01:00
|
|
|
#import "MessagesViewController.h"
|
|
|
|
#import "SignalsViewController.h"
|
2015-01-14 22:30:01 +01:00
|
|
|
#import "InCallViewController.h"
|
2014-11-21 14:38:37 +01:00
|
|
|
#import "TSStorageManager.h"
|
2015-01-14 22:30:01 +01:00
|
|
|
#import "TSAccountManager.h"
|
2014-11-21 14:38:37 +01:00
|
|
|
#import "TSDatabaseView.h"
|
2014-11-21 12:18:40 +01:00
|
|
|
#import "TSSocketManager.h"
|
2014-11-25 16:38:33 +01:00
|
|
|
#import "TSContactThread.h"
|
2014-12-24 02:25:10 +01:00
|
|
|
#import "TSMessagesManager+sendMessages.h"
|
2015-01-27 21:17:49 +01:00
|
|
|
#import "UIImage+normalizeImage.h"
|
2015-02-21 03:47:52 +01:00
|
|
|
#import "VersionMigrations.h"
|
2015-01-31 03:50:48 +01:00
|
|
|
#import "PreferencesUtil.h"
|
2014-12-24 02:25:10 +01:00
|
|
|
#import "NSDate+millisecondTimeStamp.h"
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
#import <YapDatabase/YapDatabaseViewChange.h>
|
|
|
|
#import "YapDatabaseViewTransaction.h"
|
|
|
|
#import "YapDatabaseViewMappings.h"
|
|
|
|
#import "YapDatabaseViewConnection.h"
|
|
|
|
#import "YapDatabaseFullTextSearch.h"
|
|
|
|
#import "YapDatabase.h"
|
|
|
|
|
2015-01-06 07:06:19 +01:00
|
|
|
#define CELL_HEIGHT 72.0f
|
2014-10-29 21:58:58 +01:00
|
|
|
#define HEADER_HEIGHT 44.0f
|
|
|
|
|
|
|
|
|
2015-01-29 03:57:53 +01:00
|
|
|
static NSString *const inboxTableViewCell = @"inBoxTableViewCell";
|
|
|
|
static NSString *const kSegueIndentifier = @"showSegue";
|
|
|
|
static NSString* const kCallSegue = @"2.0_6.0_Call_Segue";
|
2015-01-14 22:30:01 +01:00
|
|
|
static NSString* const kShowSignupFlowSegue = @"showSignupFlow";
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2014-12-05 23:38:13 +01:00
|
|
|
@interface SignalsViewController ()
|
2015-01-29 03:57:53 +01:00
|
|
|
|
2014-12-05 23:38:13 +01:00
|
|
|
@property (nonatomic, strong) YapDatabaseConnection *editingDbConnection;
|
2014-11-21 14:38:37 +01:00
|
|
|
@property (nonatomic, strong) YapDatabaseConnection *uiDatabaseConnection;
|
|
|
|
@property (nonatomic, strong) YapDatabaseViewMappings *threadMappings;
|
2015-01-14 22:30:01 +01:00
|
|
|
@property (nonatomic) CellState viewingThreadsIn;
|
|
|
|
@property (nonatomic) long inboxCount;
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation SignalsViewController
|
|
|
|
|
2014-11-26 20:29:45 +01:00
|
|
|
- (void)awakeFromNib{
|
|
|
|
[[Environment getCurrent] setSignalsViewController:self];
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
2015-01-14 22:30:01 +01:00
|
|
|
[self.navigationController.navigationBar setTranslucent:NO];
|
2015-02-17 00:14:50 +01:00
|
|
|
|
2014-12-05 23:38:13 +01:00
|
|
|
[self tableViewSetUp];
|
|
|
|
|
|
|
|
self.editingDbConnection = TSStorageManager.sharedManager.newDatabaseConnection;
|
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.uiDatabaseConnection beginLongLivedReadTransaction];
|
2015-02-17 00:14:50 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(yapDatabaseModified:)
|
|
|
|
name:TSUIDatabaseConnectionDidUpdateNotification
|
|
|
|
object:nil];
|
2015-01-14 22:30:01 +01:00
|
|
|
[self selectedInbox:self];
|
|
|
|
|
|
|
|
[[[Environment getCurrent] contactsManager].getObservableContacts watchLatestValue:^(id latestValue) {
|
|
|
|
[self.tableView reloadData];
|
|
|
|
} onThread:[NSThread mainThread] untilCancelled:nil];
|
2015-02-18 23:21:03 +01:00
|
|
|
self.title = NSLocalizedString(@"CONVERSATIONS_VIEW_TITLE", @"");
|
|
|
|
|
2014-11-24 21:51:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
2015-01-27 02:20:11 +01:00
|
|
|
[self checkIfEmptyView];
|
2015-01-14 22:30:01 +01:00
|
|
|
|
2015-02-21 03:47:52 +01:00
|
|
|
if (![TSAccountManager isRegistered] && ![VersionMigrations isMigratingTo2Dot0]){
|
2015-01-14 22:30:01 +01:00
|
|
|
[self performSegueWithIdentifier:kShowSignupFlowSegue sender:self];
|
2015-02-17 00:14:50 +01:00
|
|
|
return;
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
2015-02-17 00:14:50 +01:00
|
|
|
|
|
|
|
[[self tableView] reloadData];
|
|
|
|
[self updateInboxCountLabel];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated{
|
|
|
|
[super viewDidAppear:animated];
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void)tableViewSetUp
|
|
|
|
{
|
2014-11-21 14:38:37 +01:00
|
|
|
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-24 04:26:04 +01:00
|
|
|
#pragma mark - Table View Data Source
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
2014-11-21 14:38:37 +01:00
|
|
|
return (NSInteger)[self.threadMappings numberOfSections];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2014-11-21 14:38:37 +01:00
|
|
|
return (NSInteger)[self.threadMappings numberOfItemsInSection:(NSUInteger)section];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
- (InboxTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
InboxTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:inboxTableViewCell];
|
2014-11-25 19:06:09 +01:00
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
2014-10-29 21:58:58 +01:00
|
|
|
|
|
|
|
if (!cell) {
|
2014-11-21 00:51:23 +01:00
|
|
|
cell = [[InboxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
2014-11-21 14:38:37 +01:00
|
|
|
reuseIdentifier:inboxTableViewCell];
|
2014-10-29 21:58:58 +01:00
|
|
|
cell.delegate = self;
|
|
|
|
}
|
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[cell configureWithThread:thread];
|
2015-01-14 22:30:01 +01:00
|
|
|
[cell configureForState:self.viewingThreadsIn == kInboxState ? kInboxState : kArchiveState];
|
2014-11-21 14:38:37 +01:00
|
|
|
|
2015-03-20 14:32:57 +01:00
|
|
|
if ((unsigned long)indexPath.row == [self.threadMappings numberOfItemsInSection:0]-1) {
|
|
|
|
cell.separatorInset = UIEdgeInsetsMake(0.f, cell.bounds.size.width, 0.f, 0.f);
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
return cell;
|
2014-11-21 14:38:37 +01:00
|
|
|
}
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
- (TSThread*)threadForIndexPath:(NSIndexPath*)indexPath {
|
|
|
|
|
|
|
|
__block TSThread *thread = nil;
|
|
|
|
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
thread = [[transaction extension:TSThreadDatabaseViewExtensionName] objectAtIndexPath:indexPath withMappings:self.threadMappings];
|
|
|
|
}];
|
|
|
|
|
|
|
|
return thread;
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return CELL_HEIGHT;
|
|
|
|
}
|
2014-10-29 21:58:58 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
#pragma mark Table Swipe to Delete
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-27 21:17:49 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
// add the ability to delete the cell
|
2015-01-27 21:17:49 +01:00
|
|
|
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@" " handler:^(UITableViewRowAction *action, NSIndexPath *swipedIndexPath){
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
[self tableViewCellTappedDelete:swipedIndexPath];
|
|
|
|
}];
|
2015-01-27 21:17:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
UIImage* buttonImage = [[UIImage imageNamed:@"cellBtnDelete"] resizedImageToSize:CGSizeMake(82.0f, 72.0f)];
|
|
|
|
|
|
|
|
deleteAction.backgroundColor = [[UIColor alloc] initWithPatternImage:buttonImage];
|
2015-01-14 22:30:01 +01:00
|
|
|
|
|
|
|
return @[deleteAction];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
#pragma mark - HomeFeedTableViewCellDelegate
|
|
|
|
|
2015-01-24 04:26:04 +01:00
|
|
|
- (void)tableViewCellTappedDelete:(NSIndexPath*)indexPath {
|
2014-11-25 17:28:42 +01:00
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
2014-12-24 02:25:10 +01:00
|
|
|
if([thread isKindOfClass:[TSGroupThread class]]) {
|
|
|
|
DDLogDebug(@"leaving the group");
|
|
|
|
TSOutgoingMessage *message = [[TSOutgoingMessage alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread messageBody:@"" attachments:[[NSMutableArray alloc] init]];
|
|
|
|
message.groupMetaMessage = TSGroupMessageQuit;
|
|
|
|
[[TSMessagesManager sharedManager] sendMessage:message inThread:thread];
|
|
|
|
}
|
2014-12-05 23:38:13 +01:00
|
|
|
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
|
|
|
[thread removeWithTransaction:transaction];
|
|
|
|
}];
|
2015-01-14 22:30:01 +01:00
|
|
|
_inboxCount -= (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
|
2015-01-27 02:20:11 +01:00
|
|
|
[self checkIfEmptyView];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-21 00:51:23 +01:00
|
|
|
- (void)tableViewCellTappedArchive:(InboxTableViewCell*)cell {
|
2014-12-05 23:38:13 +01:00
|
|
|
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
|
|
|
|
TSThread *thread = [self threadForIndexPath:indexPath];
|
|
|
|
|
|
|
|
[self.editingDbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
2015-02-17 00:14:50 +01:00
|
|
|
self.viewingThreadsIn == kInboxState ? [thread archiveThreadWithTransaction:transaction] : [thread unarchiveThreadWithTransaction:transaction];
|
|
|
|
|
2014-12-05 23:38:13 +01:00
|
|
|
}];
|
2015-01-27 02:20:11 +01:00
|
|
|
[self checkIfEmptyView];
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-(void) updateInboxCountLabel {
|
2015-02-10 12:02:58 +01:00
|
|
|
|
|
|
|
__block NSUInteger numberOfItems;
|
|
|
|
[_editingDbConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
|
|
|
|
numberOfItems = [[transaction ext:TSUnreadDatabaseViewExtensionName] numberOfItemsInAllGroups];
|
|
|
|
}];
|
|
|
|
|
|
|
|
NSNumber *badgeNumber = [NSNumber numberWithUnsignedInteger:numberOfItems];
|
|
|
|
NSString *badgeValue = nil;
|
|
|
|
|
|
|
|
if (![badgeNumber isEqualToNumber:@0]) {
|
|
|
|
badgeValue = [badgeNumber stringValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
self.inboxCountLabel.text = badgeValue;
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-25 17:28:42 +01:00
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
|
2014-10-29 21:58:58 +01:00
|
|
|
[self performSegueWithIdentifier:kSegueIndentifier sender:self];
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Navigation
|
|
|
|
|
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
|
|
2014-11-25 17:28:42 +01:00
|
|
|
if ([segue.identifier isEqualToString:kSegueIndentifier]){
|
2014-11-25 16:38:33 +01:00
|
|
|
MessagesViewController * vc = [segue destinationViewController];
|
2014-11-21 14:38:37 +01:00
|
|
|
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
|
2014-11-26 16:00:10 +01:00
|
|
|
TSThread *thread = [self threadForIndexPath:selectedIndexPath];
|
2014-12-17 06:44:36 +01:00
|
|
|
if (self.contactIdentifierFromCompose){
|
2014-11-26 16:00:10 +01:00
|
|
|
[vc setupWithTSIdentifier:self.contactIdentifierFromCompose];
|
|
|
|
self.contactIdentifierFromCompose = nil;
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
2014-12-17 06:44:36 +01:00
|
|
|
else if (self.groupFromCompose) {
|
|
|
|
[vc setupWithTSGroup:self.groupFromCompose];
|
|
|
|
self.groupFromCompose = nil;
|
|
|
|
}
|
|
|
|
else if (thread) {
|
|
|
|
[vc setupWithThread:thread];
|
|
|
|
}
|
2015-01-29 01:34:54 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
}
|
|
|
|
else if ([segue.identifier isEqualToString:kCallSegue]) {
|
|
|
|
InCallViewController* vc = [segue destinationViewController];
|
|
|
|
[vc configureWithLatestCall:_latestCall];
|
|
|
|
_latestCall = nil;
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - IBAction
|
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
-(IBAction)selectedInbox:(id)sender {
|
|
|
|
self.viewingThreadsIn = kInboxState;
|
|
|
|
[self.inboxButton setSelected:YES];
|
|
|
|
[self.archiveButton setSelected:NO];
|
|
|
|
[self changeToGrouping:TSInboxGroup];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(IBAction)selectedArchive:(id)sender {
|
|
|
|
self.viewingThreadsIn = kArchiveState;
|
|
|
|
[self.inboxButton setSelected:NO];
|
|
|
|
[self.archiveButton setSelected:YES];
|
|
|
|
[self changeToGrouping:TSArchiveGroup];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) changeToGrouping:(NSString*)grouping {
|
|
|
|
self.threadMappings = [[YapDatabaseViewMappings alloc] initWithGroups:@[grouping]
|
|
|
|
view:TSThreadDatabaseViewExtensionName];
|
2015-02-16 10:27:08 +01:00
|
|
|
[self.threadMappings setIsReversed:YES forGroup:grouping];
|
2015-02-17 00:14:50 +01:00
|
|
|
|
2015-03-21 19:15:43 +01:00
|
|
|
[self.uiDatabaseConnection asyncReadWithBlock:^(YapDatabaseReadTransaction *transaction){
|
2014-12-05 23:38:13 +01:00
|
|
|
[self.threadMappings updateWithTransaction:transaction];
|
2015-03-21 19:15:43 +01:00
|
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
[self.tableView reloadData];
|
|
|
|
[self checkIfEmptyView];
|
|
|
|
});
|
2014-12-05 23:38:13 +01:00
|
|
|
}];
|
2014-10-29 21:58:58 +01:00
|
|
|
}
|
2014-11-21 14:38:37 +01:00
|
|
|
|
|
|
|
#pragma mark Database delegates
|
|
|
|
|
|
|
|
- (YapDatabaseConnection *)uiDatabaseConnection {
|
|
|
|
NSAssert([NSThread isMainThread], @"Must access uiDatabaseConnection on main thread!");
|
|
|
|
if (!_uiDatabaseConnection) {
|
|
|
|
YapDatabase *database = TSStorageManager.sharedManager.database;
|
|
|
|
_uiDatabaseConnection = [database newConnection];
|
|
|
|
[_uiDatabaseConnection beginLongLivedReadTransaction];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(yapDatabaseModified:)
|
|
|
|
name:YapDatabaseModifiedNotification
|
|
|
|
object:database];
|
|
|
|
}
|
|
|
|
return _uiDatabaseConnection;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)yapDatabaseModified:(NSNotification *)notification {
|
2014-11-25 17:28:42 +01:00
|
|
|
NSArray *notifications = [self.uiDatabaseConnection beginLongLivedReadTransaction];
|
2014-11-21 14:38:37 +01:00
|
|
|
NSArray *sectionChanges = nil;
|
2014-11-25 17:28:42 +01:00
|
|
|
NSArray *rowChanges = nil;
|
2015-02-17 00:14:50 +01:00
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[[self.uiDatabaseConnection ext:TSThreadDatabaseViewExtensionName] getSectionChanges:§ionChanges
|
|
|
|
rowChanges:&rowChanges
|
|
|
|
forNotifications:notifications
|
|
|
|
withMappings:self.threadMappings];
|
|
|
|
|
|
|
|
if ([sectionChanges count] == 0 && [rowChanges count] == 0){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-10 12:02:58 +01:00
|
|
|
[self updateInboxCountLabel];
|
|
|
|
|
2014-11-21 14:38:37 +01:00
|
|
|
[self.tableView beginUpdates];
|
|
|
|
|
|
|
|
for (YapDatabaseViewSectionChange *sectionChange in sectionChanges)
|
|
|
|
{
|
|
|
|
switch (sectionChange.type)
|
|
|
|
{
|
|
|
|
case YapDatabaseViewChangeDelete :
|
|
|
|
{
|
|
|
|
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionChange.index]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case YapDatabaseViewChangeInsert :
|
|
|
|
{
|
|
|
|
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionChange.index]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case YapDatabaseViewChangeUpdate:
|
|
|
|
case YapDatabaseViewChangeMove:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (YapDatabaseViewRowChange *rowChange in rowChanges)
|
|
|
|
{
|
|
|
|
switch (rowChange.type)
|
|
|
|
{
|
|
|
|
case YapDatabaseViewChangeDelete :
|
|
|
|
{
|
|
|
|
[self.tableView deleteRowsAtIndexPaths:@[ rowChange.indexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
2015-01-14 22:30:01 +01:00
|
|
|
_inboxCount += (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
|
2014-11-21 14:38:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case YapDatabaseViewChangeInsert :
|
|
|
|
{
|
|
|
|
[self.tableView insertRowsAtIndexPaths:@[ rowChange.newIndexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
2015-01-14 22:30:01 +01:00
|
|
|
_inboxCount -= (self.viewingThreadsIn == kArchiveState) ? 1 : 0;
|
2014-11-21 14:38:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case YapDatabaseViewChangeMove :
|
|
|
|
{
|
|
|
|
[self.tableView deleteRowsAtIndexPaths:@[ rowChange.indexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
[self.tableView insertRowsAtIndexPaths:@[ rowChange.newIndexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationAutomatic];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case YapDatabaseViewChangeUpdate :
|
|
|
|
{
|
|
|
|
[self.tableView reloadRowsAtIndexPaths:@[ rowChange.indexPath ]
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.tableView endUpdates];
|
2015-01-14 22:30:01 +01:00
|
|
|
[self updateInboxCountLabel];
|
2015-01-27 02:20:11 +01:00
|
|
|
[self checkIfEmptyView];
|
2014-11-21 14:38:37 +01:00
|
|
|
}
|
2014-11-25 19:06:09 +01:00
|
|
|
|
2015-01-14 22:30:01 +01:00
|
|
|
|
|
|
|
- (IBAction)unwindSettingsDone:(UIStoryboardSegue *)segue {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)unwindMessagesView:(UIStoryboardSegue *)segue {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-27 02:20:11 +01:00
|
|
|
- (void)checkIfEmptyView{
|
|
|
|
[_tableView setHidden:NO];
|
|
|
|
if (self.viewingThreadsIn == kInboxState && [self.threadMappings numberOfItemsInGroup:TSInboxGroup]==0) {
|
2015-01-27 21:17:49 +01:00
|
|
|
[self setEmptyBoxText];
|
2015-01-27 02:20:11 +01:00
|
|
|
[_tableView setHidden:YES];
|
|
|
|
}
|
2015-02-17 00:14:50 +01:00
|
|
|
else if (self.viewingThreadsIn == kArchiveState && [self.threadMappings numberOfItemsInGroup:TSArchiveGroup]==0) {
|
2015-01-27 21:17:49 +01:00
|
|
|
[self setEmptyBoxText];
|
2015-01-27 02:20:11 +01:00
|
|
|
[_tableView setHidden:YES];
|
2014-11-25 19:06:09 +01:00
|
|
|
}
|
2015-01-27 21:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void) setEmptyBoxText {
|
|
|
|
_emptyBoxLabel.textColor = [UIColor grayColor];
|
|
|
|
_emptyBoxLabel.font = [UIFont ows_regularFontWithSize:18.f];
|
|
|
|
_emptyBoxLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
|
_emptyBoxLabel.numberOfLines = 4;
|
2015-02-17 00:14:50 +01:00
|
|
|
|
2015-01-27 21:17:49 +01:00
|
|
|
NSString* firstLine = @"";
|
|
|
|
NSString* secondLine = @"";
|
|
|
|
|
|
|
|
if(self.viewingThreadsIn == kInboxState) {
|
2015-02-09 17:31:22 +01:00
|
|
|
if([Environment.preferences getHasSentAMessage]) {
|
2015-02-18 23:21:03 +01:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_INBOX_FIRST_TITLE", @"");
|
|
|
|
secondLine = NSLocalizedString(@"EMPTY_INBOX_FIRST_TEXT", @"");
|
2015-02-09 17:31:22 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-02-18 23:21:03 +01:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_ARCHIVE_FIRST_TITLE", @"");
|
|
|
|
secondLine = NSLocalizedString(@"EMPTY_ARCHIVE_FIRST_TEXT", @"");
|
2015-02-09 17:31:22 +01:00
|
|
|
}
|
2015-01-27 21:17:49 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-02-09 17:31:22 +01:00
|
|
|
if([Environment.preferences getHasArchivedAMessage]) {
|
2015-02-18 23:21:03 +01:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_INBOX_TITLE", @"");
|
|
|
|
secondLine = NSLocalizedString(@"EMPTY_INBOX_TEXT", @"");
|
2015-02-09 17:31:22 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-02-18 23:21:03 +01:00
|
|
|
firstLine = NSLocalizedString(@"EMPTY_ARCHIVE_TITLE", @"");
|
|
|
|
secondLine = NSLocalizedString(@"EMPTY_ARCHIVE_TEXT", @"");
|
2015-02-09 17:31:22 +01:00
|
|
|
}
|
2015-01-27 21:17:49 +01:00
|
|
|
}
|
|
|
|
NSMutableAttributedString *fullLabelString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",firstLine,secondLine]];
|
|
|
|
|
|
|
|
[fullLabelString addAttribute:NSFontAttributeName value:[UIFont ows_boldFontWithSize:15.f] range:NSMakeRange(0,firstLine.length)];
|
|
|
|
[fullLabelString addAttribute:NSFontAttributeName value:[UIFont ows_regularFontWithSize:14.f] range:NSMakeRange(firstLine.length + 1, secondLine.length)];
|
|
|
|
[fullLabelString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0,firstLine.length)];
|
|
|
|
[fullLabelString addAttribute:NSForegroundColorAttributeName value:[UIColor ows_darkGrayColor] range:NSMakeRange(firstLine.length + 1, secondLine.length)];
|
|
|
|
_emptyBoxLabel.attributedText = fullLabelString;
|
2014-11-25 19:06:09 +01:00
|
|
|
}
|
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
@end
|