Show disappearing messages timer in share extension

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent e0ea3921fc
commit 5c2075cdb6

@ -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" #import "ContactTableViewCell.h"
@ -182,6 +182,17 @@ const CGFloat kContactTableViewCellAvatarTextMargin = 12;
diameter:kContactTableViewCellAvatarSize diameter:kContactTableViewCellAvatarSize
contactsManager:contactsManager]; 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. // Force layout, since imageView isn't being initally rendered on App Store optimized build.
[self layoutSubviews]; [self layoutSubviews];
} }

@ -21,6 +21,7 @@
#import <SignalServiceKit/TSAccountManager.h> #import <SignalServiceKit/TSAccountManager.h>
#import <SignalServiceKit/TSContactThread.h> #import <SignalServiceKit/TSContactThread.h>
#import <SignalServiceKit/TSThread.h> #import <SignalServiceKit/TSThread.h>
#import <YapDatabase/YapDatabase.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -33,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper; @property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
@property (nonatomic, readonly) ConversationSearcher *conversationSearcher; @property (nonatomic, readonly) ConversationSearcher *conversationSearcher;
@property (nonatomic, readonly) ThreadViewHelper *threadViewHelper; @property (nonatomic, readonly) ThreadViewHelper *threadViewHelper;
@property (nonatomic, readonly) YapDatabaseConnection *uiDatabaseConnection;
@property (nonatomic, readonly) OWSTableViewController *tableViewController; @property (nonatomic, readonly) OWSTableViewController *tableViewController;
@ -60,6 +62,18 @@ NS_ASSUME_NONNULL_BEGIN
_threadViewHelper = [ThreadViewHelper new]; _threadViewHelper = [ThreadViewHelper new];
_threadViewHelper.delegate = self; _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 createViews];
[self updateTableContents]; [self updateTableContents];
@ -104,6 +118,24 @@ NS_ASSUME_NONNULL_BEGIN
[self autoPinViewToBottomGuideOrKeyboard:self.tableViewController.view]; [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 #pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText - (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 // To be consistent with the threads (above), we use ContactTableViewCell
// instead of InboxTableViewCell to present contacts and threads. // instead of InboxTableViewCell to present contacts and threads.
ContactTableViewCell *cell = [ContactTableViewCell new]; 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]; [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; return cell;
} }
customRowHeight:[ContactTableViewCell rowHeight] customRowHeight:[ContactTableViewCell rowHeight]

Loading…
Cancel
Save