Revision c6c7b30a ChatSecure/Classes/View Controllers/OTRMessagesViewController.m
ChatSecure/Classes/View Controllers/OTRMessagesViewController.m | ||
---|---|---|
69 | 69 |
OTRDropDownTypePush = 2 |
70 | 70 |
}; |
71 | 71 |
|
72 |
@interface OTRMessagesViewController () <UITextViewDelegate, OTRAttachmentPickerDelegate, OTRYapViewHandlerDelegateProtocol, OTRMessagesCollectionViewFlowLayoutSizeProtocol, OTRRoomOccupantsViewControllerDelegate> { |
|
72 |
@interface OTRMessagesViewController () <UITextViewDelegate, OTRAttachmentPickerDelegate, OTRYapViewHandlerDelegateProtocol, OTRMessagesCollectionViewFlowLayoutSizeProtocol, OTRMessagesCollectionViewFlowLayoutSupplementaryViewProtocol, OTRRoomOccupantsViewControllerDelegate> {
|
|
73 | 73 |
JSQMessagesAvatarImage *_warningAvatarImage; |
74 | 74 |
JSQMessagesAvatarImage *_accountAvatarImage; |
75 | 75 |
JSQMessagesAvatarImage *_buddyAvatarImage; |
... | ... | |
102 | 102 |
@property (nonatomic, strong) id currentMessage; |
103 | 103 |
@property (nonatomic, strong) NSCache *messageSizeCache; |
104 | 104 |
|
105 |
@property (nonatomic) BOOL automaticURLFetchingDisabled; |
|
106 |
@property (nonatomic, strong) OTRMessagesUnknownSenderCell *prototypeCellUnknownSender; |
|
107 |
|
|
105 | 108 |
@end |
106 | 109 |
|
107 | 110 |
@implementation OTRMessagesViewController |
... | ... | |
175 | 178 |
///Custom Layout to account for no bubble cells |
176 | 179 |
OTRMessagesCollectionViewFlowLayout *layout = [[OTRMessagesCollectionViewFlowLayout alloc] init]; |
177 | 180 |
layout.sizeDelegate = self; |
181 |
layout.supplementaryViewDelegate = self; |
|
178 | 182 |
self.collectionView.collectionViewLayout = layout; |
179 |
|
|
183 |
UINib *nib = [UINib nibWithNibName:@"OTRMessageUnknownSenderCell" bundle:OTRAssets.resourcesBundle]; |
|
184 |
[self.collectionView registerNib:nib forSupplementaryViewOfKind:[OTRMessagesUnknownSenderCell reuseIdentifier] withReuseIdentifier:[OTRMessagesUnknownSenderCell reuseIdentifier]]; |
|
185 |
|
|
180 | 186 |
///"Loading Earlier" header view |
181 | 187 |
[self.collectionView registerNib:[UINib nibWithNibName:@"OTRMessagesLoadingView" bundle:OTRAssets.resourcesBundle] |
182 | 188 |
forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
... | ... | |
381 | 387 |
self.threadCollection = collection; |
382 | 388 |
[self.readOnlyDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction * _Nonnull transaction) { |
383 | 389 |
self.senderId = [[self threadObjectWithTransaction:transaction] threadAccountIdentifier]; |
390 |
self.automaticURLFetchingDisabled = [[self accountWithTransaction:transaction] disableAutomaticURLFetching]; |
|
384 | 391 |
}]; |
385 | 392 |
|
386 | 393 |
// Clear out old state (don't just alloc a new object, we have KVOs attached to this!) |
... | ... | |
2287 | 2294 |
[self.navigationController.navigationController popViewControllerAnimated:YES]; |
2288 | 2295 |
} |
2289 | 2296 |
} |
2297 |
|
|
2298 |
#pragma - mark OTRMessagesCollectionViewFlowLayoutSupplementaryViewProtocol |
|
2299 |
|
|
2300 |
- (nullable NSArray *)supplementaryViewsForCellAtIndexPath:(NSIndexPath *)indexPath { |
|
2301 |
id<OTRMessageProtocol,JSQMessageData> message = [self messageAtIndexPath:indexPath]; |
|
2302 |
if ([self isGroupChat] && [message isKindOfClass:[OTRGroupDownloadMessage class]]) { |
|
2303 |
OTRGroupDownloadMessage *roomMessage = (OTRGroupDownloadMessage *)message; |
|
2304 |
// A message that is not automatically downloaded, even though auto download not disabled, means that this is group download message from someone who is not our friend. |
|
2305 |
if ([roomMessage.messageError isAutomaticDownloadError] && !self.automaticURLFetchingDisabled && [roomMessage.media isKindOfClass:[OTRImageItem class]]) { |
|
2306 |
if (!_prototypeCellUnknownSender) { |
|
2307 |
UINib *nib = [UINib nibWithNibName:@"OTRMessageUnknownSenderCell" bundle:OTRAssets.resourcesBundle]; |
|
2308 |
_prototypeCellUnknownSender = (OTRMessagesUnknownSenderCell *)[nib instantiateWithOwner:self options:nil][0]; |
|
2309 |
} |
|
2310 |
[self populateUnknownSenderCell:_prototypeCellUnknownSender withMessage:message]; |
|
2311 |
[_prototypeCellUnknownSender setNeedsLayout]; |
|
2312 |
[_prototypeCellUnknownSender layoutIfNeeded]; |
|
2313 |
_prototypeCellUnknownSender.frame = CGRectMake(0, 0, self.collectionView.bounds.size.width, _prototypeCellUnknownSender.frame.size.height); |
|
2314 |
int height = [_prototypeCellUnknownSender systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1; |
|
2315 |
|
|
2316 |
OTRMessagesCollectionSupplementaryViewInfo *info = [[OTRMessagesCollectionSupplementaryViewInfo alloc] initWithKind:[OTRMessagesUnknownSenderCell reuseIdentifier] height:height]; |
|
2317 |
return [NSArray arrayWithObject:info]; |
|
2318 |
} |
|
2319 |
} |
|
2320 |
return nil; |
|
2321 |
} |
|
2322 |
|
|
2323 |
- (void)populateUnknownSenderCell:(OTRMessagesUnknownSenderCell *)cell withMessage:(id<OTRMessageProtocol,JSQMessageData>)message { |
|
2324 |
cell.titleLabel.text = [NSString stringWithFormat:ADD_FRIEND_TO_AUTO_DOWNLOAD(), message.senderDisplayName]; |
|
2325 |
} |
|
2326 |
|
|
2327 |
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { |
|
2328 |
if ([OTRMessagesUnknownSenderCell.reuseIdentifier isEqualToString:kind]) { |
|
2329 |
id<OTRMessageProtocol,JSQMessageData> message = [self messageAtIndexPath:indexPath]; |
|
2330 |
OTRMessagesUnknownSenderCell *cell = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kind forIndexPath:indexPath]; |
|
2331 |
[self populateUnknownSenderCell:cell withMessage:message]; |
|
2332 |
return cell; |
|
2333 |
} |
|
2334 |
// We should never get there, but if we do, don't return nil |
|
2335 |
return [[UICollectionReusableView alloc] initWithFrame:CGRectZero]; |
|
2336 |
} |
|
2337 |
|
|
2290 | 2338 |
@end |
Also available in: Unified diff