From 5c2075cdb62e60bbf37e7cd9d1a0b6616b671ca7 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Wed, 17 Jan 2018 17:45:47 -0500 Subject: [PATCH] Show disappearing messages timer in share extension // FREEBIE --- SignalMessaging/Views/ContactTableViewCell.m | 13 +++- .../contacts/SelectThreadViewController.m | 65 +++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/SignalMessaging/Views/ContactTableViewCell.m b/SignalMessaging/Views/ContactTableViewCell.m index 255b4fbb8..9cf535f6c 100644 --- a/SignalMessaging/Views/ContactTableViewCell.m +++ b/SignalMessaging/Views/ContactTableViewCell.m @@ -1,5 +1,5 @@ // -// Copyright (c) 2017 Open Whisper Systems. All rights reserved. +// Copyright (c) 2018 Open Whisper Systems. All rights reserved. // #import "ContactTableViewCell.h" @@ -182,6 +182,17 @@ const CGFloat kContactTableViewCellAvatarTextMargin = 12; diameter:kContactTableViewCellAvatarSize contactsManager:contactsManager]; + if (self.accessoryMessage) { + UILabel *blockedLabel = [[UILabel alloc] init]; + blockedLabel.textAlignment = NSTextAlignmentRight; + blockedLabel.text = self.accessoryMessage; + blockedLabel.font = [UIFont ows_mediumFontWithSize:13.f]; + blockedLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; + [blockedLabel sizeToFit]; + + self.accessoryView = blockedLabel; + } + // Force layout, since imageView isn't being initally rendered on App Store optimized build. [self layoutSubviews]; } diff --git a/SignalMessaging/contacts/SelectThreadViewController.m b/SignalMessaging/contacts/SelectThreadViewController.m index f8accb49b..22790a509 100644 --- a/SignalMessaging/contacts/SelectThreadViewController.m +++ b/SignalMessaging/contacts/SelectThreadViewController.m @@ -21,6 +21,7 @@ #import #import #import +#import NS_ASSUME_NONNULL_BEGIN @@ -33,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper; @property (nonatomic, readonly) ConversationSearcher *conversationSearcher; @property (nonatomic, readonly) ThreadViewHelper *threadViewHelper; +@property (nonatomic, readonly) YapDatabaseConnection *uiDatabaseConnection; @property (nonatomic, readonly) OWSTableViewController *tableViewController; @@ -60,6 +62,18 @@ NS_ASSUME_NONNULL_BEGIN _threadViewHelper = [ThreadViewHelper new]; _threadViewHelper.delegate = self; + _uiDatabaseConnection = [[TSStorageManager sharedManager] newDatabaseConnection]; + _uiDatabaseConnection.permittedTransactions = YDB_AnyReadTransaction; + [_uiDatabaseConnection beginLongLivedReadTransaction]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(yapDatabaseModified:) + name:YapDatabaseModifiedNotification + object:TSStorageManager.sharedManager.dbNotificationObject]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(yapDatabaseModifiedExternally:) + name:YapDatabaseModifiedExternallyNotification + object:nil]; + [self createViews]; [self updateTableContents]; @@ -104,6 +118,24 @@ NS_ASSUME_NONNULL_BEGIN [self autoPinViewToBottomGuideOrKeyboard:self.tableViewController.view]; } +- (void)yapDatabaseModifiedExternally:(NSNotification *)notification +{ + OWSAssertIsOnMainThread(); + + DDLogVerbose(@"%@ %s", self.logTag, __PRETTY_FUNCTION__); + + [self.uiDatabaseConnection beginLongLivedReadTransaction]; + [self updateTableContents]; +} + +- (void)yapDatabaseModified:(NSNotification *)notification +{ + OWSAssertIsOnMainThread(); + + [self.uiDatabaseConnection beginLongLivedReadTransaction]; + [self updateTableContents]; +} + #pragma mark - UISearchBarDelegate - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText @@ -165,7 +197,40 @@ NS_ASSUME_NONNULL_BEGIN // To be consistent with the threads (above), we use ContactTableViewCell // instead of InboxTableViewCell to present contacts and threads. ContactTableViewCell *cell = [ContactTableViewCell new]; + + if ([thread isKindOfClass:[TSContactThread class]]) { + BOOL isBlocked = [helper isRecipientIdBlocked:thread.contactIdentifier]; + if (isBlocked) { + cell.accessoryMessage = NSLocalizedString(@"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked."); + } + } + [cell configureWithThread:thread contactsManager:helper.contactsManager]; + + if (cell.accessoryView == nil) { + // Don't add a disappearing messages indicator if we've already added a "blocked" label. + __block OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + disappearingMessagesConfiguration = + [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:thread.uniqueId + transaction:transaction]; + }]; + + if (disappearingMessagesConfiguration && disappearingMessagesConfiguration.isEnabled) { + UIImage *icon = [UIImage imageNamed:@"table_ic_hourglass"]; + OWSAssert(icon); + UIImageView *iconView = [UIImageView new]; + iconView.image = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; + iconView.tintColor = [UIColor colorWithWhite:0.5f alpha:1.f]; + iconView.contentMode = UIViewContentModeScaleAspectFit; + // Default size of this icon is a too large for the thread picker context + // so we specify a bit smaller. + iconView.frame = CGRectMake(0, 0, 20, 20); + + cell.accessoryView = iconView; + } + } + return cell; } customRowHeight:[ContactTableViewCell rowHeight]