зеркало из https://github.com/nextcloud/talk-ios.git
Show shared files previews.
Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Родитель
4f12508dff
Коммит
10e4f57d5d
|
@ -35,6 +35,7 @@
|
|||
2C3F6AB71FBB47C400E2705C /* UICKeyChainStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA1CC991F0161EA002FE6A2 /* UICKeyChainStore.m */; };
|
||||
2C3F6AB81FBB4C9500E2705C /* NCRoom.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA1CCC21F166CC5002FE6A2 /* NCRoom.m */; };
|
||||
2C3F6AB91FBB4C9D00E2705C /* NCUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 2CA1CCCC1F181741002FE6A2 /* NCUser.m */; };
|
||||
2C415F9B2136BDD6005F7F37 /* FileMessageTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C415F9A2136BDD6005F7F37 /* FileMessageTableViewCell.m */; };
|
||||
2C42ADB420B58E6300296DEA /* NCRoomController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C42ADB320B58E6300296DEA /* NCRoomController.m */; };
|
||||
2C43BA7621309A1000B3068A /* NCMessageParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C43BA7521309A1000B3068A /* NCMessageParameter.m */; };
|
||||
2C43BA7A2130BB2A00B3068A /* NCMessageParameter.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C43BA7521309A1000B3068A /* NCMessageParameter.m */; };
|
||||
|
@ -63,6 +64,8 @@
|
|||
2C7A12422017872600864818 /* AddParticipantsTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C7A12402017872600864818 /* AddParticipantsTableViewController.m */; };
|
||||
2C7A12432017872600864818 /* AddParticipantsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C7A12412017872600864818 /* AddParticipantsTableViewController.xib */; };
|
||||
2C7F47AA20289B9600081CC7 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2C7F47AC20289B9600081CC7 /* Localizable.strings */; };
|
||||
2C86DB8B2135B910008770C3 /* NCFilePreviewSessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C86DB8A2135B910008770C3 /* NCFilePreviewSessionManager.m */; };
|
||||
2C86DB8C2135BBE6008770C3 /* NCFilePreviewSessionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C86DB8A2135B910008770C3 /* NCFilePreviewSessionManager.m */; };
|
||||
2C90E5641EDDE0FB0093D85A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C90E5631EDDE0FB0093D85A /* Foundation.framework */; };
|
||||
2C90E5671EDDE1340093D85A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C90E5661EDDE1340093D85A /* CoreGraphics.framework */; };
|
||||
2C90E5691EDDE13A0093D85A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2C90E5681EDDE13A0093D85A /* UIKit.framework */; };
|
||||
|
@ -182,6 +185,8 @@
|
|||
2C3F6AA61FBB1ACD00E2705C /* NotificationService.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NotificationService.h; sourceTree = "<group>"; };
|
||||
2C3F6AA71FBB1ACD00E2705C /* NotificationService.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NotificationService.m; sourceTree = "<group>"; };
|
||||
2C3F6AA91FBB1ACD00E2705C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
2C415F992136BDD6005F7F37 /* FileMessageTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FileMessageTableViewCell.h; sourceTree = "<group>"; };
|
||||
2C415F9A2136BDD6005F7F37 /* FileMessageTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FileMessageTableViewCell.m; sourceTree = "<group>"; };
|
||||
2C42ADB220B58E6300296DEA /* NCRoomController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCRoomController.h; sourceTree = "<group>"; };
|
||||
2C42ADB320B58E6300296DEA /* NCRoomController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCRoomController.m; sourceTree = "<group>"; };
|
||||
2C43BA7421309A1000B3068A /* NCMessageParameter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCMessageParameter.h; sourceTree = "<group>"; };
|
||||
|
@ -230,6 +235,8 @@
|
|||
2C7A12402017872600864818 /* AddParticipantsTableViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AddParticipantsTableViewController.m; sourceTree = "<group>"; };
|
||||
2C7A12412017872600864818 /* AddParticipantsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = AddParticipantsTableViewController.xib; sourceTree = "<group>"; };
|
||||
2C7F47AB20289B9600081CC7 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
2C86DB892135B910008770C3 /* NCFilePreviewSessionManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NCFilePreviewSessionManager.h; sourceTree = "<group>"; };
|
||||
2C86DB8A2135B910008770C3 /* NCFilePreviewSessionManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NCFilePreviewSessionManager.m; sourceTree = "<group>"; };
|
||||
2C8B5FF11FB4A9DA006E87EF /* aes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = aes.h; sourceTree = "<group>"; };
|
||||
2C8B5FF21FB4A9DA006E87EF /* asn1.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asn1.h; sourceTree = "<group>"; };
|
||||
2C8B5FF31FB4A9DA006E87EF /* asn1_mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = asn1_mac.h; sourceTree = "<group>"; };
|
||||
|
@ -659,6 +666,8 @@
|
|||
2CBF82BC1FD5AE0A00636459 /* NCImageSessionManager.m */,
|
||||
2CBF82BF1FD5AE3F00636459 /* NCPushProxySessionManager.h */,
|
||||
2CBF82C01FD5AE3F00636459 /* NCPushProxySessionManager.m */,
|
||||
2C86DB892135B910008770C3 /* NCFilePreviewSessionManager.h */,
|
||||
2C86DB8A2135B910008770C3 /* NCFilePreviewSessionManager.m */,
|
||||
);
|
||||
name = Network;
|
||||
sourceTree = "<group>";
|
||||
|
@ -813,6 +822,8 @@
|
|||
2CA15547208EA1EA00CE8EF0 /* ChatMessageTableViewCell.m */,
|
||||
2CA155542099E07700CE8EF0 /* GroupedChatMessageTableViewCell.h */,
|
||||
2CA155552099E07700CE8EF0 /* GroupedChatMessageTableViewCell.m */,
|
||||
2C415F992136BDD6005F7F37 /* FileMessageTableViewCell.h */,
|
||||
2C415F9A2136BDD6005F7F37 /* FileMessageTableViewCell.m */,
|
||||
2C604BD7211988A700D34DCD /* SystemMessageTableViewCell.h */,
|
||||
2C604BD8211988A700D34DCD /* SystemMessageTableViewCell.m */,
|
||||
2C06BF6520AC647A0031EB46 /* DateHeaderView.h */,
|
||||
|
@ -1112,9 +1123,11 @@
|
|||
2CA1CCC31F166CC5002FE6A2 /* NCRoom.m in Sources */,
|
||||
2C06BF5D20A89F510031EB46 /* NCRoomsManager.m in Sources */,
|
||||
2CA1CCA71F026222002FE6A2 /* ContactsTableViewController.m in Sources */,
|
||||
2C415F9B2136BDD6005F7F37 /* FileMessageTableViewCell.m in Sources */,
|
||||
2C78EF9C1F826B22008AFA74 /* NCCallController.m in Sources */,
|
||||
2C4D7D761F30F7B600FF4A0D /* ARDUtilities.m in Sources */,
|
||||
2CBF82AE1FC888FC00636459 /* NCPushNotification.m in Sources */,
|
||||
2C86DB8B2135B910008770C3 /* NCFilePreviewSessionManager.m in Sources */,
|
||||
2CC7159420C54D080045C789 /* ChatTableViewCell.m in Sources */,
|
||||
2CA1CCAA1F02D1A4002FE6A2 /* NCAPIController.m in Sources */,
|
||||
2C3780C3210F49DC003F9AE8 /* HeaderWithButton.m in Sources */,
|
||||
|
@ -1180,6 +1193,7 @@
|
|||
2C063314205AB8B90043481A /* ARDSettingsModel.m in Sources */,
|
||||
2CBF82BA1FD5A1E500636459 /* CCCertificate.m in Sources */,
|
||||
2CA15542208E3B7B00CE8EF0 /* NCChatMessage.m in Sources */,
|
||||
2C86DB8C2135BBE6008770C3 /* NCFilePreviewSessionManager.m in Sources */,
|
||||
2CBF82B71FD0939600636459 /* NCAPISessionManager.m in Sources */,
|
||||
2C43BA7A2130BB2A00B3068A /* NCMessageParameter.m in Sources */,
|
||||
2CBF82C21FD5AE3F00636459 /* NCPushProxySessionManager.m in Sources */,
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// FileMessageTableViewCell.h
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 29.08.18.
|
||||
// Copyright © 2018 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "ChatTableViewCell.h"
|
||||
#import "MessageBodyTextView.h"
|
||||
|
||||
static CGFloat kFileMessageCellMinimumHeight = 50.0;
|
||||
static CGFloat kFileMessageCellAvatarHeight = 30.0;
|
||||
static CGFloat kFileMessageCellFilePreviewHeight = 120.0;
|
||||
|
||||
static NSString *FileMessageCellIdentifier = @"FileMessageCellIdentifier";
|
||||
|
||||
@interface FilePreviewImageView : UIImageView
|
||||
@end
|
||||
|
||||
@interface FileMessageTableViewCell : ChatTableViewCell
|
||||
|
||||
@property (nonatomic, strong) UILabel *titleLabel;
|
||||
@property (nonatomic, strong) UILabel *dateLabel;
|
||||
@property (nonatomic, strong) FilePreviewImageView *previewImageView;
|
||||
@property (nonatomic, strong) MessageBodyTextView *bodyTextView;
|
||||
@property (nonatomic, strong) UIImageView *avatarView;
|
||||
|
||||
+ (CGFloat)defaultFontSize;
|
||||
- (void)setGuestAvatar:(NSString *)displayName;
|
||||
|
||||
@end
|
|
@ -0,0 +1,153 @@
|
|||
//
|
||||
// FileMessageTableViewCell.m
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 29.08.18.
|
||||
// Copyright © 2018 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import "FileMessageTableViewCell.h"
|
||||
#import "SLKUIConstants.h"
|
||||
#import "NCFilePreviewSessionManager.h"
|
||||
#import "UIImageView+AFNetworking.h"
|
||||
#import "UIImageView+Letters.h"
|
||||
|
||||
@implementation FilePreviewImageView : UIImageView
|
||||
|
||||
@end
|
||||
|
||||
@implementation FileMessageTableViewCell
|
||||
|
||||
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
||||
{
|
||||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
||||
if (self) {
|
||||
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[self configureSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)configureSubviews
|
||||
{
|
||||
_avatarView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kFileMessageCellAvatarHeight, kFileMessageCellAvatarHeight)];
|
||||
_avatarView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_avatarView.userInteractionEnabled = NO;
|
||||
_avatarView.backgroundColor = [UIColor colorWithRed:0.84 green:0.84 blue:0.84 alpha:1.0]; /*#d5d5d5*/
|
||||
_avatarView.layer.cornerRadius = kFileMessageCellAvatarHeight/2.0;
|
||||
_avatarView.layer.masksToBounds = YES;
|
||||
[self.contentView addSubview:_avatarView];
|
||||
|
||||
_previewImageView = [[FilePreviewImageView alloc] initWithFrame:CGRectMake(0, 0, kFileMessageCellFilePreviewHeight, kFileMessageCellFilePreviewHeight)];
|
||||
_previewImageView.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_previewImageView.userInteractionEnabled = NO;
|
||||
_previewImageView.backgroundColor = [UIColor colorWithRed:0.84 green:0.84 blue:0.84 alpha:1.0]; /*#d5d5d5*/
|
||||
_previewImageView.layer.cornerRadius = 4.0;
|
||||
_previewImageView.layer.masksToBounds = YES;
|
||||
[self.contentView addSubview:_previewImageView];
|
||||
|
||||
[self.contentView addSubview:self.titleLabel];
|
||||
[self.contentView addSubview:self.dateLabel];
|
||||
[self.contentView addSubview:self.bodyTextView];
|
||||
|
||||
NSDictionary *views = @{@"avatarView": self.avatarView,
|
||||
@"titleLabel": self.titleLabel,
|
||||
@"dateLabel": self.dateLabel,
|
||||
@"previewImageView": self.previewImageView,
|
||||
@"bodyTextView": self.bodyTextView,
|
||||
};
|
||||
|
||||
NSDictionary *metrics = @{@"avatarSize": @(kFileMessageCellAvatarHeight),
|
||||
@"previewSize": @(kFileMessageCellFilePreviewHeight),
|
||||
@"padding": @15,
|
||||
@"right": @10,
|
||||
@"left": @5
|
||||
};
|
||||
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-right-[avatarView(avatarSize)]-right-[titleLabel]-[dateLabel(40)]-right-|" options:0 metrics:metrics views:views]];
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-right-[avatarView(avatarSize)]-right-[previewImageView(previewSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-right-[avatarView(avatarSize)]-right-[bodyTextView(>=0)]-right-|" options:0 metrics:metrics views:views]];
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[titleLabel(28)]-left-[previewImageView(previewSize)]-left-[bodyTextView(>=0@999)]-left-|" options:0 metrics:metrics views:views]];
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[dateLabel(28)]-left-[previewImageView(previewSize)]-left-[bodyTextView(>=0@999)]-left-|" options:0 metrics:metrics views:views]];
|
||||
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-right-[avatarView(avatarSize)]-(>=0)-|" options:0 metrics:metrics views:views]];
|
||||
}
|
||||
|
||||
- (void)prepareForReuse
|
||||
{
|
||||
[super prepareForReuse];
|
||||
|
||||
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
||||
|
||||
CGFloat pointSize = [FileMessageTableViewCell defaultFontSize];
|
||||
|
||||
self.titleLabel.font = [UIFont systemFontOfSize:pointSize];
|
||||
self.bodyTextView.font = [UIFont systemFontOfSize:pointSize];
|
||||
|
||||
self.titleLabel.text = @"";
|
||||
self.bodyTextView.text = @"";
|
||||
self.dateLabel.text = @"";
|
||||
|
||||
[self.avatarView cancelImageDownloadTask];
|
||||
self.avatarView.image = nil;
|
||||
}
|
||||
|
||||
#pragma mark - Getters
|
||||
|
||||
- (UILabel *)titleLabel
|
||||
{
|
||||
if (!_titleLabel) {
|
||||
_titleLabel = [UILabel new];
|
||||
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_titleLabel.backgroundColor = [UIColor clearColor];
|
||||
_titleLabel.userInteractionEnabled = NO;
|
||||
_titleLabel.numberOfLines = 0;
|
||||
_titleLabel.textColor = [UIColor lightGrayColor];
|
||||
_titleLabel.font = [UIFont systemFontOfSize:[FileMessageTableViewCell defaultFontSize]];
|
||||
}
|
||||
return _titleLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)dateLabel
|
||||
{
|
||||
if (!_dateLabel) {
|
||||
_dateLabel = [UILabel new];
|
||||
_dateLabel.textAlignment = NSTextAlignmentRight;
|
||||
_dateLabel.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
_dateLabel.backgroundColor = [UIColor clearColor];
|
||||
_dateLabel.userInteractionEnabled = NO;
|
||||
_dateLabel.numberOfLines = 0;
|
||||
_dateLabel.textColor = [UIColor lightGrayColor];
|
||||
_dateLabel.font = [UIFont systemFontOfSize:12.0];
|
||||
}
|
||||
return _dateLabel;
|
||||
}
|
||||
|
||||
- (MessageBodyTextView *)bodyTextView
|
||||
{
|
||||
if (!_bodyTextView) {
|
||||
_bodyTextView = [MessageBodyTextView new];
|
||||
_bodyTextView.font = [UIFont systemFontOfSize:[FileMessageTableViewCell defaultFontSize]];
|
||||
}
|
||||
return _bodyTextView;
|
||||
}
|
||||
|
||||
- (void)setGuestAvatar:(NSString *)displayName
|
||||
{
|
||||
UIColor *guestAvatarColor = [UIColor colorWithRed:0.84 green:0.84 blue:0.84 alpha:1.0]; /*#d5d5d5*/
|
||||
NSString *name = ([displayName isEqualToString:@""]) ? @"?" : displayName;
|
||||
[_avatarView setImageWithString:name color:guestAvatarColor circular:true];
|
||||
}
|
||||
|
||||
+ (CGFloat)defaultFontSize
|
||||
{
|
||||
CGFloat pointSize = 16.0;
|
||||
|
||||
// NSString *contentSizeCategory = [[UIApplication sharedApplication] preferredContentSizeCategory];
|
||||
// pointSize += SLKPointSizeDifferenceForCategory(contentSizeCategory);
|
||||
|
||||
return pointSize;
|
||||
}
|
||||
|
||||
@end
|
|
@ -9,6 +9,7 @@
|
|||
#import "NCAPIController.h"
|
||||
|
||||
#import "NCAPISessionManager.h"
|
||||
#import "NCFilePreviewSessionManager.h"
|
||||
#import "NCPushProxySessionManager.h"
|
||||
#import "NCSettingsController.h"
|
||||
|
||||
|
@ -39,6 +40,9 @@ NSString * const kNCSpreedAPIVersion = @"/apps/spreed/api/v1";
|
|||
- (void)setNCServer:(NSString *)serverUrl
|
||||
{
|
||||
_serverUrl = serverUrl;
|
||||
|
||||
//Set NC server in managers that requires it
|
||||
[[NCFilePreviewSessionManager sharedInstance] setNCServer:serverUrl];
|
||||
}
|
||||
|
||||
- (void)setAuthHeaderWithUser:(NSString *)user andToken:(NSString *)token
|
||||
|
@ -51,6 +55,9 @@ NSString * const kNCSpreedAPIVersion = @"/apps/spreed/api/v1";
|
|||
[[NCAPISessionManager sharedInstance].requestSerializer setValue:authHeader forHTTPHeaderField:@"Authorization"];
|
||||
|
||||
_authToken = token;
|
||||
|
||||
//Set auth header in managers that requires authentication
|
||||
[[NCFilePreviewSessionManager sharedInstance] setAuthHeaderWithUser:user andToken:token];
|
||||
}
|
||||
|
||||
- (NSString *)currentServerUrl
|
||||
|
|
|
@ -29,6 +29,7 @@ extern NSInteger const kChatMessageGroupTimeDifference;
|
|||
|
||||
+ (instancetype)messageWithDictionary:(NSDictionary *)messageDict;
|
||||
- (BOOL)isSystemMessage;
|
||||
- (NSString *)filePreview;
|
||||
- (NSMutableAttributedString *)parsedMessage;
|
||||
- (NSMutableAttributedString *)systemMessageFormat;
|
||||
|
||||
|
|
|
@ -58,6 +58,24 @@ NSInteger const kChatMessageGroupTimeDifference = 30;
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (NSString *)filePreview;
|
||||
{
|
||||
NSString *fileId = nil;
|
||||
for (NSDictionary *parameterDict in _messageParameters.allValues) {
|
||||
NCMessageParameter *parameter = [NCMessageParameter parameterWithDictionary:parameterDict] ;
|
||||
if ([parameter.type isEqualToString:@"file"]) {
|
||||
if (!fileId) {
|
||||
fileId = parameter.parameterId;
|
||||
} else {
|
||||
// If there is more than one file in the message,
|
||||
// we don't display any preview.
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileId;
|
||||
}
|
||||
|
||||
- (NSMutableAttributedString *)parsedMessage
|
||||
{
|
||||
NSString *originalMessage = _message;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#import "ChatMessageTableViewCell.h"
|
||||
#import "GroupedChatMessageTableViewCell.h"
|
||||
#import "FileMessageTableViewCell.h"
|
||||
#import "SystemMessageTableViewCell.h"
|
||||
#import "DateHeaderView.h"
|
||||
#import "ChatPlaceholderView.h"
|
||||
|
@ -18,6 +19,7 @@
|
|||
#import "NCMessageParameter.h"
|
||||
#import "NCChatTitleView.h"
|
||||
#import "NCMessageTextView.h"
|
||||
#import "NCFilePreviewSessionManager.h"
|
||||
#import "NCRoomsManager.h"
|
||||
#import "NCRoomController.h"
|
||||
#import "NCSettingsController.h"
|
||||
|
@ -113,6 +115,7 @@
|
|||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
[self.tableView registerClass:[ChatMessageTableViewCell class] forCellReuseIdentifier:ChatMessageCellIdentifier];
|
||||
[self.tableView registerClass:[GroupedChatMessageTableViewCell class] forCellReuseIdentifier:GroupedChatMessageCellIdentifier];
|
||||
[self.tableView registerClass:[FileMessageTableViewCell class] forCellReuseIdentifier:FileMessageCellIdentifier];
|
||||
[self.tableView registerClass:[SystemMessageTableViewCell class] forCellReuseIdentifier:SystemMessageCellIdentifier];
|
||||
[self.autoCompletionView registerClass:[ChatMessageTableViewCell class] forCellReuseIdentifier:AutoCompletionCellIdentifier];
|
||||
[self registerPrefixesForAutoCompletion:@[@"@"]];
|
||||
|
@ -709,6 +712,21 @@
|
|||
}
|
||||
return systemCell;
|
||||
}
|
||||
|
||||
if (message.filePreview) {
|
||||
FileMessageTableViewCell *fileCell = (FileMessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:FileMessageCellIdentifier];
|
||||
fileCell.titleLabel.text = message.actorDisplayName;
|
||||
fileCell.bodyTextView.attributedText = message.parsedMessage;
|
||||
fileCell.messageId = message.messageId;
|
||||
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:message.timestamp];
|
||||
fileCell.dateLabel.text = [self getTimeFromDate:date];
|
||||
[fileCell.avatarView setImageWithURLRequest:[[NCAPIController sharedInstance] createAvatarRequestForUser:message.actorId andSize:96]
|
||||
placeholderImage:nil success:nil failure:nil];
|
||||
[[NCFilePreviewSessionManager sharedInstance] getFilePreview:message.filePreview width:120 height:120 withCompletionBlock:^(UIImage *preview, NSError *error) {
|
||||
[fileCell.previewImageView setImage:preview];
|
||||
}];
|
||||
return fileCell;
|
||||
}
|
||||
if (message.groupMessage) {
|
||||
GroupedChatMessageTableViewCell *groupedCell = (GroupedChatMessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:GroupedChatMessageCellIdentifier];
|
||||
groupedCell.bodyTextView.attributedText = message.parsedMessage;
|
||||
|
@ -777,6 +795,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
if (message.filePreview) {
|
||||
height += kFileMessageCellFilePreviewHeight + 10;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// NCFilePreviewSessionManager.h
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 28.08.18.
|
||||
// Copyright © 2018 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "AFNetworking.h"
|
||||
|
||||
typedef void (^GetFilePreviewCompletionBlock)(UIImage *preview, NSError *error);
|
||||
|
||||
@interface NCFilePreviewSessionManager : AFHTTPSessionManager
|
||||
|
||||
@property (nonatomic, strong) NSString *userAgent;
|
||||
|
||||
+ (instancetype)sharedInstance;
|
||||
- (void)setNCServer:(NSString *)serverUrl;
|
||||
- (void)setAuthHeaderWithUser:(NSString *)user andToken:(NSString *)token;
|
||||
- (NSURLSessionDataTask *)getFilePreview:(NSString *)fileId width:(NSInteger)width height:(NSInteger)height withCompletionBlock:(GetFilePreviewCompletionBlock)block;
|
||||
- (NSURLRequest *)createPreviewRequestForFile:(NSString *)fileId width:(NSInteger)width height:(NSInteger)height;
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
//
|
||||
// NCFilePreviewSessionManager.m
|
||||
// VideoCalls
|
||||
//
|
||||
// Created by Ivan Sein on 28.08.18.
|
||||
// Copyright © 2018 struktur AG. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NCFilePreviewSessionManager.h"
|
||||
#import "CCCertificate.h"
|
||||
|
||||
@interface NCFilePreviewSessionManager () <NSURLSessionTaskDelegate, NSURLSessionDelegate>
|
||||
{
|
||||
NSString *_serverUrl;
|
||||
NSString *_authToken;
|
||||
NSString *_userAgent;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NCFilePreviewSessionManager
|
||||
|
||||
+ (NCFilePreviewSessionManager *)sharedInstance
|
||||
{
|
||||
static dispatch_once_t once;
|
||||
static NCFilePreviewSessionManager *sharedInstance;
|
||||
dispatch_once(&once, ^{
|
||||
sharedInstance = [[self alloc] init];
|
||||
});
|
||||
return sharedInstance;
|
||||
}
|
||||
|
||||
- (void)setNCServer:(NSString *)serverUrl
|
||||
{
|
||||
_serverUrl = serverUrl;
|
||||
}
|
||||
|
||||
- (void)setAuthHeaderWithUser:(NSString *)user andToken:(NSString *)token
|
||||
{
|
||||
NSString *userTokenString = [NSString stringWithFormat:@"%@:%@", user, token];
|
||||
NSData *data = [userTokenString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
NSString *base64Encoded = [data base64EncodedStringWithOptions:0];
|
||||
|
||||
NSString *authHeader = [[NSString alloc]initWithFormat:@"Basic %@",base64Encoded];
|
||||
[[NCFilePreviewSessionManager sharedInstance].requestSerializer setValue:authHeader forHTTPHeaderField:@"Authorization"];
|
||||
|
||||
_authToken = token;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
// Set ephemeralSessionConfiguration and just use AFAutoPurgingImageCache for caching images.
|
||||
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
||||
self = [super initWithSessionConfiguration:configuration];
|
||||
if (self) {
|
||||
_userAgent = [NSString stringWithFormat:@"Mozilla/5.0 (iOS) Nextcloud-Talk v%@",
|
||||
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
|
||||
|
||||
self.responseSerializer = [[AFImageResponseSerializer alloc] init];
|
||||
self.requestSerializer = [[AFHTTPRequestSerializer alloc] init];
|
||||
|
||||
AFSecurityPolicy* policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
|
||||
self.securityPolicy = policy;
|
||||
|
||||
self.responseSerializer.acceptableContentTypes = [self.responseSerializer.acceptableContentTypes setByAddingObject:@"image/jpg"];
|
||||
[self.requestSerializer setValue:_userAgent forHTTPHeaderField:@"User-Agent"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSURLSessionDataTask *)getFilePreview:(NSString *)fileId width:(NSInteger)width height:(NSInteger)height withCompletionBlock:(GetFilePreviewCompletionBlock)block
|
||||
{
|
||||
NSString *URLString = [NSString stringWithFormat:@"%@/index.php/core/preview", _serverUrl];
|
||||
NSDictionary *parameters = @{@"fileId" : fileId,
|
||||
@"x" : @(width),
|
||||
@"y" : @(height),
|
||||
@"forceIcon" : @(1)};
|
||||
|
||||
NSURLSessionDataTask *task = [[NCFilePreviewSessionManager sharedInstance] GET:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
||||
if (block) {
|
||||
block(responseObject, nil);
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
if (block) {
|
||||
block(nil, error);
|
||||
}
|
||||
}];
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
- (NSURLRequest *)createPreviewRequestForFile:(NSString *)fileId width:(NSInteger)width height:(NSInteger)height
|
||||
{
|
||||
NSString *urlString = [NSString stringWithFormat:@"%@/index.php/core/preview?fileId=%@&x=%ld&y=%ld&forceIcon=1", _serverUrl, fileId, (long)width, (long)height];
|
||||
return [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]
|
||||
cachePolicy:NSURLRequestReturnCacheDataElseLoad
|
||||
timeoutInterval:60];
|
||||
}
|
||||
|
||||
-(void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
|
||||
{
|
||||
if ([[CCCertificate sharedManager] checkTrustedChallenge:challenge]) {
|
||||
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
|
||||
} else {
|
||||
completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -25,6 +25,13 @@
|
|||
messageParameter.path = [parameterDict objectForKey:@"path"];
|
||||
messageParameter.link = [parameterDict objectForKey:@"link"];
|
||||
|
||||
id parameterId = [parameterDict objectForKey:@"id"];
|
||||
if ([parameterId isKindOfClass:[NSString class]]) {
|
||||
messageParameter.parameterId = parameterId;
|
||||
} else {
|
||||
messageParameter.parameterId = [parameterId stringValue];
|
||||
}
|
||||
|
||||
return messageParameter;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче