CR: rename ThreadModel -> ThreadViewModel

// FREEBIE
This commit is contained in:
Michael Kirk 2018-04-23 12:15:21 -04:00
parent d1230abdc5
commit f5e810e82b
4 changed files with 21 additions and 21 deletions

View File

@ -5,7 +5,7 @@
import Foundation
@objc
public class ThreadModel: NSObject {
public class ThreadViewModel: NSObject {
let hasUnreadMessages: Bool
let lastMessageDate: Date
let isGroupThread: Bool

View File

@ -5,7 +5,7 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSContactsManager;
@class ThreadModel;
@class ThreadViewModel;
@class YapDatabaseReadTransaction;
@interface HomeViewCell : UITableViewCell
@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (NSString *)cellReuseIdentifier;
- (void)configureWithThread:(ThreadModel *)thread
- (void)configureWithThread:(ThreadViewModel *)thread
contactsManager:(OWSContactsManager *)contactsManager
blockedPhoneNumberSet:(NSSet<NSString *> *)blockedPhoneNumberSet;

View File

@ -26,7 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UIView *unreadBadge;
@property (nonatomic) UILabel *unreadLabel;
@property (nonatomic, nullable) ThreadModel *thread;
@property (nonatomic, nullable) ThreadViewModel *thread;
@property (nonatomic, nullable) OWSContactsManager *contactsManager;
@property (nonatomic, readonly) NSMutableArray<NSLayoutConstraint *> *viewConstraints;
@ -142,7 +142,7 @@ NS_ASSUME_NONNULL_BEGIN
return NSStringFromClass(self.class);
}
- (void)configureWithThread:(ThreadModel *)thread
- (void)configureWithThread:(ThreadViewModel *)thread
contactsManager:(OWSContactsManager *)contactsManager
blockedPhoneNumberSet:(NSSet<NSString *> *)blockedPhoneNumberSet
{
@ -239,7 +239,7 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
ThreadModel *thread = self.thread;
ThreadViewModel *thread = self.thread;
if (thread == nil) {
OWSFail(@"%@ thread should not be nil", self.logTag);
self.avatarView.image = nil;
@ -251,7 +251,7 @@ NS_ASSUME_NONNULL_BEGIN
contactsManager:contactsManager];
}
- (NSAttributedString *)attributedSnippetForThread:(ThreadModel *)thread
- (NSAttributedString *)attributedSnippetForThread:(ThreadViewModel *)thread
blockedPhoneNumberSet:(NSSet<NSString *> *)blockedPhoneNumberSet
{
OWSAssert(thread);
@ -447,7 +447,7 @@ NS_ASSUME_NONNULL_BEGIN
self.nameLabel.font = self.nameFont;
ThreadModel *thread = self.thread;
ThreadViewModel *thread = self.thread;
if (thread == nil) {
OWSFail(@"%@ thread should not be nil", self.logTag);
self.nameLabel.attributedText = nil;

View File

@ -47,7 +47,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
@property (nonatomic) UISegmentedControl *segmentedControl;
@property (nonatomic) id previewingContext;
@property (nonatomic) NSSet<NSString *> *blockedPhoneNumberSet;
@property (nonatomic, readonly) NSCache<NSString *, ThreadModel *> *threadModelCache;
@property (nonatomic, readonly) NSCache<NSString *, ThreadViewModel *> *threadViewModelCache;
@property (nonatomic) BOOL isViewVisible;
@property (nonatomic) BOOL isAppInBackground;
@property (nonatomic) BOOL shouldObserveDBModifications;
@ -108,7 +108,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
_messageSender = [Environment current].messageSender;
_blockingManager = [OWSBlockingManager sharedManager];
_blockedPhoneNumberSet = [NSSet setWithArray:[_blockingManager blockedPhoneNumbers]];
_threadModelCache = [NSCache new];
_threadViewModelCache = [NSCache new];
// Ensure ExperienceUpgradeFinder has been initialized.
[ExperienceUpgradeFinder sharedManager];
@ -476,7 +476,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
- (void)reloadTableViewData
{
// PERF: come up with a more nuanced cache clearing scheme
[self.threadModelCache removeAllObjects];
[self.threadViewModelCache removeAllObjects];
[self.tableView reloadData];
}
@ -604,21 +604,21 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
return (NSInteger)[self.threadMappings numberOfItemsInSection:(NSUInteger)section];
}
- (ThreadModel *)threadModelForIndexPath:(NSIndexPath *)indexPath
- (ThreadViewModel *)threadViewModelForIndexPath:(NSIndexPath *)indexPath
{
TSThread *threadRecord = [self threadForIndexPath:indexPath];
ThreadModel *_Nullable cachedThreadModel = [self.threadModelCache objectForKey:threadRecord.uniqueId];
if (cachedThreadModel) {
return cachedThreadModel;
ThreadViewModel *_Nullable cachedThreadViewModel = [self.threadViewModelCache objectForKey:threadRecord.uniqueId];
if (cachedThreadViewModel) {
return cachedThreadViewModel;
}
__block ThreadModel *_Nullable newThreadModel;
__block ThreadViewModel *_Nullable newThreadViewModel;
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
newThreadModel = [[ThreadModel alloc] initWithThread:threadRecord transaction:transaction];
newThreadViewModel = [[ThreadViewModel alloc] initWithThread:threadRecord transaction:transaction];
}];
[self.threadModelCache setObject:newThreadModel forKey:threadRecord.uniqueId];
return newThreadModel;
[self.threadViewModelCache setObject:newThreadViewModel forKey:threadRecord.uniqueId];
return newThreadViewModel;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@ -626,7 +626,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
HomeViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:HomeViewCell.cellReuseIdentifier];
OWSAssert(cell);
ThreadModel *thread = [self threadModelForIndexPath:indexPath];
ThreadViewModel *thread = [self threadViewModelForIndexPath:indexPath];
[cell configureWithThread:thread
contactsManager:self.contactsManager
blockedPhoneNumberSet:self.blockedPhoneNumberSet];
@ -1041,7 +1041,7 @@ typedef NS_ENUM(NSInteger, CellState) { kArchiveState, kInboxState };
for (YapDatabaseViewRowChange *rowChange in rowChanges) {
NSString *key = rowChange.collectionKey.key;
OWSAssert(key);
[self.threadModelCache removeObjectForKey:key];
[self.threadViewModelCache removeObjectForKey:key];
switch (rowChange.type) {
case YapDatabaseViewChangeDelete: {