Revision c6c7b30a

View differences:

ChatSecure/Classes/Controllers/FileTransferManager.swift
523 523
                    downloads = message.existingDownloads(with: transaction)
524 524
                    if let thread = message.threadOwner(with: transaction), let account = OTRAccount.fetchObject(withUniqueID: thread.threadAccountIdentifier, transaction: transaction) {
525 525
                        disableAutomaticURLFetching = account.disableAutomaticURLFetching
526
                        if !disableAutomaticURLFetching, let room = thread as? OTRXMPPRoom, let message = message as? OTRXMPPRoomMessage {
527
                            // For room messages, default to safe mode
528
                            disableAutomaticURLFetching = true
529
                            if let senderJidString = message.senderJID, let senderJID = XMPPJID(string: senderJidString), let roomJID = room.roomJID, let occupant = OTRXMPPRoomOccupant.occupant(jid: senderJID, realJID: senderJID, roomJID: roomJID, accountId: thread.threadAccountIdentifier, createIfNeeded: false, transaction: transaction), occupant.buddy(with: transaction) != nil {
530
                                // We have a buddy, i.e. we are friends with the sender.
531
                                disableAutomaticURLFetching = false
532
                            }
533
                        }
526 534
                    }
527 535
                }
528 536
            }
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
ChatSecure/Classes/Views/Cells/OTRMessageUnknownSenderCell.xib
6 6
    <dependencies>
7 7
        <deployment identifier="iOS"/>
8 8
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
9
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
10 9
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
11 10
    </dependencies>
12 11
    <objects>
13 12
        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
14 13
        <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
15
        <collectionReusableView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="22J-kO-64R" customClass="OTRMessagesUnknownSenderCell" customModule="ChatSecureCore">
14
        <collectionReusableView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" insetsLayoutMarginsFromSafeArea="NO" id="22J-kO-64R" customClass="OTRMessagesUnknownSenderCell" customModule="ChatSecureCore">
16 15
            <rect key="frame" x="0.0" y="0.0" width="375" height="50"/>
17
            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
16
            <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18 17
            <subviews>
19 18
                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="1000" verticalHuggingPriority="1000" horizontalCompressionResistancePriority="1000" verticalCompressionResistancePriority="1000" text="No data" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tP4-Uw-Q8q">
20 19
                    <rect key="frame" x="10" y="10" width="355" height="30"/>
21
                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
22
                    <nil key="textColor"/>
20
                    <fontDescription key="fontDescription" type="system" pointSize="12"/>
21
                    <color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
23 22
                    <nil key="highlightedColor"/>
24 23
                </label>
25 24
            </subviews>
25
            <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
26 26
            <constraints>
27
                <constraint firstItem="2Di-RS-Jjo" firstAttribute="bottom" secondItem="tP4-Uw-Q8q" secondAttribute="bottom" constant="10" id="PTO-Cn-PH4"/>
28
                <constraint firstItem="2Di-RS-Jjo" firstAttribute="trailing" secondItem="tP4-Uw-Q8q" secondAttribute="trailing" constant="10" id="ZqZ-wZ-92N"/>
29
                <constraint firstItem="tP4-Uw-Q8q" firstAttribute="leading" secondItem="2Di-RS-Jjo" secondAttribute="leading" constant="10" id="lTY-I5-fsW"/>
30
                <constraint firstItem="tP4-Uw-Q8q" firstAttribute="top" secondItem="2Di-RS-Jjo" secondAttribute="top" constant="10" id="vjV-ke-Pc2"/>
27
                <constraint firstAttribute="bottom" secondItem="tP4-Uw-Q8q" secondAttribute="bottom" constant="10" id="PTO-Cn-PH4"/>
28
                <constraint firstAttribute="trailing" secondItem="tP4-Uw-Q8q" secondAttribute="trailing" constant="10" id="ZqZ-wZ-92N"/>
29
                <constraint firstItem="tP4-Uw-Q8q" firstAttribute="leading" secondItem="22J-kO-64R" secondAttribute="leading" constant="10" id="lTY-I5-fsW"/>
30
                <constraint firstItem="tP4-Uw-Q8q" firstAttribute="top" secondItem="22J-kO-64R" secondAttribute="top" constant="10" id="vjV-ke-Pc2"/>
31 31
            </constraints>
32
            <viewLayoutGuide key="safeArea" id="2Di-RS-Jjo"/>
33 32
            <connections>
34 33
                <outlet property="titleLabel" destination="tP4-Uw-Q8q" id="b4e-Ao-C3K"/>
35 34
            </connections>
OTRAssets/Strings/OTRStrings.h
18 18
FOUNDATION_EXPORT NSString* ADD_BUDDY_STRING();
19 19
/** "Add Existing Account", Label for button to create account by logging into an existing account */
20 20
FOUNDATION_EXPORT NSString* ADD_EXISTING_STRING();
21
/** "Is %@ your friend? Add him/her to auto-download pictures in the future.", Shown in chat view to prompt user to add friend for auto-download of group media messages. */
22
FOUNDATION_EXPORT NSString* ADD_FRIEND_TO_AUTO_DOWNLOAD();
21 23
/** "Add", Button title to add someone as a buddy */
22 24
FOUNDATION_EXPORT NSString* ADD_STRING();
23 25
/** "Advanced", String to describe advanced set of settings */
OTRAssets/Strings/OTRStrings.m
18 18
NSString* ADD_BUDDY_STRING() { return [OTRLanguageManager translatedString:@"Add Buddy"]; }
19 19
/** "Add Existing Account", Label for button to create account by logging into an existing account */
20 20
NSString* ADD_EXISTING_STRING() { return [OTRLanguageManager translatedString:@"Add Existing Account"]; }
21
/** "Is %@ your friend? Add him/her to auto-download pictures in the future.", Shown in chat view to prompt user to add friend for auto-download of group media messages. */
22
NSString* ADD_FRIEND_TO_AUTO_DOWNLOAD() { return [OTRLanguageManager translatedString:@"Is %@ your friend? Add him/her to auto-download pictures in the future."]; }
21 23
/** "Add", Button title to add someone as a buddy */
22 24
NSString* ADD_STRING() { return [OTRLanguageManager translatedString:@"Add"]; }
23 25
/** "Advanced", String to describe advanced set of settings */
OTRAssets/Strings/strings.json
1182 1182
    }, "GROUP_INFO_YOU": {
1183 1183
        "comment": "This will be shown after your own JID in the group profile view",
1184 1184
        "string": "you"
1185
    }, "ADD_FRIEND_TO_AUTO_DOWNLOAD": {
1186
        "comment": "Shown in chat view to prompt user to add friend for auto-download of group media messages.",
1187
        "string": "Is %@ your friend? Add him/her to auto-download pictures in the future."
1185 1188
    }
1186 1189
}

Also available in: Unified diff